| ... | @@ -1651,6 +1651,21 @@ test "AtomicFile" { | ... | @@ -1651,6 +1651,21 @@ test "AtomicFile" { |
| 1651 | \\ this is a test file | 1651 | \\ this is a test file |
| 1652 | ; | 1652 | ; |
| 1653 | | 1653 | |
| | 1654 | // link() succeeds with no file already present |
| | 1655 | { |
| | 1656 | var af = try ctx.dir.createFileAtomic(io, test_out_file, .{ .replace = false }); |
| | 1657 | defer af.deinit(io); |
| | 1658 | try af.file.writeStreamingAll(io, test_content); |
| | 1659 | try af.link(io); |
| | 1660 | } |
| | 1661 | // link() returns error.PathAlreadyExists if file already present |
| | 1662 | { |
| | 1663 | var af = try ctx.dir.createFileAtomic(io, test_out_file, .{ .replace = false }); |
| | 1664 | defer af.deinit(io); |
| | 1665 | try af.file.writeStreamingAll(io, test_content); |
| | 1666 | try expectError(error.PathAlreadyExists, af.link(io)); |
| | 1667 | } |
| | 1668 | // replace() succeeds if file already present |
| 1654 | { | 1669 | { |
| 1655 | var af = try ctx.dir.createFileAtomic(io, test_out_file, .{ .replace = true }); | 1670 | var af = try ctx.dir.createFileAtomic(io, test_out_file, .{ .replace = true }); |
| 1656 | defer af.deinit(io); | 1671 | defer af.deinit(io); |