| author | |
| committer | |
| log | 6a549a7f0cc337634c5dca6abf20eca53b572f21 |
| tree | ecb52dd0688ee0abf6089013095a7d21e66b97be |
| parent | 518197080748b3804d76030ad9f02969b01a679a |
Add a test to avoid regressions.
Fixes #34122 files changed, 22 insertions(+), 4 deletions(-)
lib/std/fs/file.zig+4-4| ... | ... | @@ -279,12 +279,12 @@ pub const File = struct { |
| 279 | 279 | } |
| 280 | 280 | const times = [2]os.timespec{ |
| 281 | 281 | os.timespec{ |
| 282 | .tv_sec = @divFloor(atime, std.time.ns_per_s), | |
| 283 | .tv_nsec = @mod(atime, std.time.ns_per_s), | |
| 282 | .tv_sec = math.cast(isize, @divFloor(atime, std.time.ns_per_s)) catch maxInt(isize), | |
| 283 | .tv_nsec = math.cast(isize, @mod(atime, std.time.ns_per_s)) catch maxInt(isize), | |
| 284 | 284 | }, |
| 285 | 285 | os.timespec{ |
| 286 | .tv_sec = @divFloor(mtime, std.time.ns_per_s), | |
| 287 | .tv_nsec = @mod(mtime, std.time.ns_per_s), | |
| 286 | .tv_sec = math.cast(isize, @divFloor(mtime, std.time.ns_per_s)) catch maxInt(isize), | |
| 287 | .tv_nsec = math.cast(isize, @mod(mtime, std.time.ns_per_s)) catch maxInt(isize), | |
| 288 | 288 | }, |
| 289 | 289 | }; |
| 290 | 290 | try os.futimens(self.handle, &times); |
lib/std/io/test.zig+18| ... | ... | @@ -629,3 +629,21 @@ test "File seek ops" { |
| 629 | 629 | try file.seekTo(1234); |
| 630 | 630 | std.testing.expect((try file.getPos()) == 1234); |
| 631 | 631 | } |
| 632 | ||
| 633 | test "updateTimes" { | |
| 634 | const tmp_file_name = "just_a_temporary_file.txt"; | |
| 635 | var file = try File.openWrite(tmp_file_name); | |
| 636 | defer { | |
| 637 | file.close(); | |
| 638 | std.fs.deleteFile(tmp_file_name) catch {}; | |
| 639 | } | |
| 640 | var stat_old = try file.stat(); | |
| 641 | // Set atime and mtime to 5s before | |
| 642 | try file.updateTimes( | |
| 643 | stat_old.atime - 5 * std.time.ns_per_s, | |
| 644 | stat_old.mtime - 5 * std.time.ns_per_s, | |
| 645 | ); | |
| 646 | var stat_new = try file.stat(); | |
| 647 | std.testing.expect(stat_new.atime < stat_old.atime); | |
| 648 | std.testing.expect(stat_new.mtime < stat_old.mtime); | |
| 649 | } |