This fixes Chtimes on systems with 32 bit Timespec

Signed-off-by: Darren Stahl <darst@microsoft.com>
This commit is contained in:
Darren Stahl 2015-11-03 14:49:50 -08:00
parent c02491b8c3
commit 17d202b021
4 changed files with 27 additions and 95 deletions

View file

@ -30,9 +30,7 @@ func TestChtimes(t *testing.T) {
beforeUnixEpochTime := time.Unix(0, 0).Add(-100 * time.Second)
unixEpochTime := time.Unix(0, 0)
afterUnixEpochTime := time.Unix(100, 0)
// The max Unix time is 33 bits set
unixMaxTime := unixEpochTime.Add((1<<33 - 1) * time.Second)
afterUnixMaxTime := unixMaxTime.Add(100 * time.Second)
unixMaxTime := maxTime
// Test both aTime and mTime set to Unix Epoch
Chtimes(file, unixEpochTime, unixEpochTime)
@ -90,31 +88,7 @@ func TestChtimes(t *testing.T) {
t.Fatal(err)
}
if f.ModTime() != unixMaxTime {
t.Fatalf("Expected: %s, got: %s", unixMaxTime, f.ModTime())
}
// Test aTime after Unix max time and mTime set to Unix max time
Chtimes(file, afterUnixMaxTime, unixMaxTime)
f, err = os.Stat(file)
if err != nil {
t.Fatal(err)
}
if f.ModTime() != unixMaxTime {
t.Fatalf("Expected: %s, got: %s", unixMaxTime, f.ModTime())
}
// Test aTime set to Unix Epoch and mTime before Unix Epoch
Chtimes(file, unixMaxTime, afterUnixMaxTime)
f, err = os.Stat(file)
if err != nil {
t.Fatal(err)
}
if f.ModTime() != unixEpochTime {
t.Fatalf("Expected: %s, got: %s", unixEpochTime, f.ModTime())
if f.ModTime().Truncate(time.Second) != unixMaxTime.Truncate(time.Second) {
t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), f.ModTime().Truncate(time.Second))
}
}