LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package os_test | 5 package os_test |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | 9 "fmt" |
10 "io" | 10 "io" |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 fd.Truncate(1024) | 476 fd.Truncate(1024) |
477 checkSize(t, Path, 1024) | 477 checkSize(t, Path, 1024) |
478 fd.Truncate(0) | 478 fd.Truncate(0) |
479 checkSize(t, Path, 0) | 479 checkSize(t, Path, 0) |
480 fd.Write([]byte("surprise!")) | 480 fd.Write([]byte("surprise!")) |
481 checkSize(t, Path, 13+9) // wrote at offset past where hello, world was. | 481 checkSize(t, Path, 13+9) // wrote at offset past where hello, world was. |
482 fd.Close() | 482 fd.Close() |
483 Remove(Path) | 483 Remove(Path) |
484 } | 484 } |
485 | 485 |
486 func TestUtime(t *testing.T) { | 486 func TestChtimes(t *testing.T) { |
487 MkdirAll("_obj", 0777) | 487 MkdirAll("_obj", 0777) |
488 » const Path = "_obj/_TestUtime_" | 488 » const Path = "_obj/_TestChtimes_" |
489 fd, err := Open(Path, O_WRONLY|O_CREAT, 0666) | 489 fd, err := Open(Path, O_WRONLY|O_CREAT, 0666) |
490 if err != nil { | 490 if err != nil { |
491 t.Fatalf("create %s: %s", Path, err) | 491 t.Fatalf("create %s: %s", Path, err) |
492 } | 492 } |
493 fd.Write([]byte("hello, world\n")) | 493 fd.Write([]byte("hello, world\n")) |
494 fd.Close() | 494 fd.Close() |
495 | 495 |
496 preStat, err := Stat(Path) | 496 preStat, err := Stat(Path) |
497 if err != nil { | 497 if err != nil { |
498 » » t.Fatalf("stat %s: %s", Path, err) | 498 » » t.Fatalf("Stat %s: %s", Path, err) |
499 } | 499 } |
500 | 500 |
501 // Move access and modification time back a second | 501 // Move access and modification time back a second |
502 » const SecondNanos = 1000000000 | 502 » const OneSecond = 1e9 // in nanoseconds |
503 » err = Utime(Path, preStat.Atime_ns-SecondNanos, preStat.Mtime_ns-SecondN
anos) | 503 » err = Chtimes(Path, preStat.Atime_ns-OneSecond, preStat.Mtime_ns-OneSeco
nd) |
504 » if err != nil { | 504 » if err != nil { |
505 » » t.Fatalf("utime %s: %s", Path, err) | 505 » » t.Fatalf("Chtimes %s: %s", Path, err) |
506 } | 506 } |
507 | 507 |
508 postStat, err := Stat(Path) | 508 postStat, err := Stat(Path) |
509 if err != nil { | 509 if err != nil { |
510 » » t.Fatalf("second stat %s: %s", Path, err) | 510 » » t.Fatalf("second Stat %s: %s", Path, err) |
511 } | 511 } |
512 | 512 |
513 if postStat.Atime_ns >= preStat.Atime_ns { | 513 if postStat.Atime_ns >= preStat.Atime_ns { |
514 t.Errorf("Atime_ns didn't go backwards; was=%d, after=%d", | 514 t.Errorf("Atime_ns didn't go backwards; was=%d, after=%d", |
515 preStat.Atime_ns, | 515 preStat.Atime_ns, |
516 postStat.Atime_ns) | 516 postStat.Atime_ns) |
517 } | 517 } |
518 | 518 |
519 if postStat.Mtime_ns >= preStat.Mtime_ns { | 519 if postStat.Mtime_ns >= preStat.Mtime_ns { |
520 t.Errorf("Mtime_ns didn't go backwards; was=%d, after=%d", | 520 t.Errorf("Mtime_ns didn't go backwards; was=%d, after=%d", |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 } | 737 } |
738 | 738 |
739 b, err := ioutil.ReadFile("_obj/writetest") | 739 b, err := ioutil.ReadFile("_obj/writetest") |
740 if err != nil { | 740 if err != nil { |
741 t.Fatalf("ReadFile _obj/writetest: %v", err) | 741 t.Fatalf("ReadFile _obj/writetest: %v", err) |
742 } | 742 } |
743 if string(b) != "hello, WORLD\n" { | 743 if string(b) != "hello, WORLD\n" { |
744 t.Fatalf("after write: have %q want %q", string(b), "hello, WORL
D\n") | 744 t.Fatalf("after write: have %q want %q", string(b), "hello, WORL
D\n") |
745 } | 745 } |
746 } | 746 } |
LEFT | RIGHT |