Use syscall.Timespec.Unix
Use the syscall method instead of repeating the type conversions for the syscall.Stat_t Atim/Mtim members. This also allows to drop the //nolint: unconvert comments. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
This commit is contained in:
parent
10aecb0e65
commit
cfd26afabe
2 changed files with 7 additions and 7 deletions
|
@ -228,8 +228,8 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error {
|
|||
if f.IsDir() {
|
||||
dirsToSetMtimes.PushFront(&dirMtimeInfo{dstPath: &dstPath, stat: stat})
|
||||
} else if !isSymlink {
|
||||
aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
|
||||
mTime := time.Unix(int64(stat.Mtim.Sec), int64(stat.Mtim.Nsec))
|
||||
aTime := time.Unix(stat.Atim.Unix())
|
||||
mTime := time.Unix(stat.Mtim.Unix())
|
||||
if err := system.Chtimes(dstPath, aTime, mTime); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestChtimesLinux(t *testing.T) {
|
|||
}
|
||||
|
||||
stat := f.Sys().(*syscall.Stat_t)
|
||||
aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
|
||||
aTime := time.Unix(stat.Atim.Unix())
|
||||
if aTime != unixEpochTime {
|
||||
t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func TestChtimesLinux(t *testing.T) {
|
|||
}
|
||||
|
||||
stat = f.Sys().(*syscall.Stat_t)
|
||||
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
|
||||
aTime = time.Unix(stat.Atim.Unix())
|
||||
if aTime != unixEpochTime {
|
||||
t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func TestChtimesLinux(t *testing.T) {
|
|||
}
|
||||
|
||||
stat = f.Sys().(*syscall.Stat_t)
|
||||
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
|
||||
aTime = time.Unix(stat.Atim.Unix())
|
||||
if aTime != unixEpochTime {
|
||||
t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func TestChtimesLinux(t *testing.T) {
|
|||
}
|
||||
|
||||
stat = f.Sys().(*syscall.Stat_t)
|
||||
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
|
||||
aTime = time.Unix(stat.Atim.Unix())
|
||||
if aTime != afterUnixEpochTime {
|
||||
t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime)
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func TestChtimesLinux(t *testing.T) {
|
|||
}
|
||||
|
||||
stat = f.Sys().(*syscall.Stat_t)
|
||||
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
|
||||
aTime = time.Unix(stat.Atim.Unix())
|
||||
if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) {
|
||||
t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue