Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
1afa2a1b
Commit
1afa2a1b
authored
May 20, 2010
by
Brad Fitzpatrick
Committed by
Russ Cox
May 20, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
os: add Chtimes function
R=rsc, r CC=golang-dev
https://golang.org/cl/1103041
parent
cbc01a3e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
file.go
src/pkg/os/file.go
+16
-0
os_test.go
src/pkg/os/os_test.go
+42
-0
No files found.
src/pkg/os/file.go
View file @
1afa2a1b
...
@@ -407,3 +407,19 @@ func (f *File) Truncate(size int64) Error {
...
@@ -407,3 +407,19 @@ func (f *File) Truncate(size int64) Error {
}
}
return
nil
return
nil
}
}
// Chtimes changes the access and modification times of the named
// file, similar to the Unix utime() or utimes() functions.
//
// The argument times are in nanoseconds, although the underlying
// filesystem may truncate or round the values to a more
// coarse time unit.
func
Chtimes
(
name
string
,
atime_ns
int64
,
mtime_ns
int64
)
Error
{
var
utimes
[
2
]
syscall
.
Timeval
utimes
[
0
]
=
syscall
.
NsecToTimeval
(
atime_ns
)
utimes
[
1
]
=
syscall
.
NsecToTimeval
(
mtime_ns
)
if
e
:=
syscall
.
Utimes
(
name
,
&
utimes
);
e
!=
0
{
return
&
PathError
{
"chtimes"
,
name
,
Errno
(
e
)}
}
return
nil
}
src/pkg/os/os_test.go
View file @
1afa2a1b
...
@@ -483,6 +483,48 @@ func TestTruncate(t *testing.T) {
...
@@ -483,6 +483,48 @@ func TestTruncate(t *testing.T) {
Remove
(
Path
)
Remove
(
Path
)
}
}
func
TestChtimes
(
t
*
testing
.
T
)
{
MkdirAll
(
"_obj"
,
0777
)
const
Path
=
"_obj/_TestChtimes_"
fd
,
err
:=
Open
(
Path
,
O_WRONLY
|
O_CREAT
,
0666
)
if
err
!=
nil
{
t
.
Fatalf
(
"create %s: %s"
,
Path
,
err
)
}
fd
.
Write
([]
byte
(
"hello, world
\n
"
))
fd
.
Close
()
preStat
,
err
:=
Stat
(
Path
)
if
err
!=
nil
{
t
.
Fatalf
(
"Stat %s: %s"
,
Path
,
err
)
}
// Move access and modification time back a second
const
OneSecond
=
1e9
// in nanoseconds
err
=
Chtimes
(
Path
,
preStat
.
Atime_ns
-
OneSecond
,
preStat
.
Mtime_ns
-
OneSecond
)
if
err
!=
nil
{
t
.
Fatalf
(
"Chtimes %s: %s"
,
Path
,
err
)
}
postStat
,
err
:=
Stat
(
Path
)
if
err
!=
nil
{
t
.
Fatalf
(
"second Stat %s: %s"
,
Path
,
err
)
}
if
postStat
.
Atime_ns
>=
preStat
.
Atime_ns
{
t
.
Errorf
(
"Atime_ns didn't go backwards; was=%d, after=%d"
,
preStat
.
Atime_ns
,
postStat
.
Atime_ns
)
}
if
postStat
.
Mtime_ns
>=
preStat
.
Mtime_ns
{
t
.
Errorf
(
"Mtime_ns didn't go backwards; was=%d, after=%d"
,
preStat
.
Mtime_ns
,
postStat
.
Mtime_ns
)
}
Remove
(
Path
)
}
func
TestChdirAndGetwd
(
t
*
testing
.
T
)
{
func
TestChdirAndGetwd
(
t
*
testing
.
T
)
{
fd
,
err
:=
Open
(
"."
,
O_RDONLY
,
0
)
fd
,
err
:=
Open
(
"."
,
O_RDONLY
,
0
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment