| 1 | // directory-relative cleanup reaches the deliberately over-PATH_MAX fixture filename. |
| 2 | module hookfixtures |
| 3 | |
| 4 | import os |
| 5 | |
| 6 | #include <fcntl.h> |
| 7 | #include <unistd.h> |
| 8 | #include <errno.h> |
| 9 | |
| 10 | fn C.unlinkat(i32, &char, i32) i32 |
| 11 | |
| 12 | pub fn deep_directory(root string) string { |
| 13 | return root + ('/' + 'd'.repeat(190)).repeat(20) |
| 14 | } |
| 15 | |
| 16 | pub fn long_filename() string { |
| 17 | return 'f'.repeat(232) + '.hook' |
| 18 | } |
| 19 | |
| 20 | pub fn cleanup_long_paths(base string) ! { |
| 21 | for backend in ['old', 'native', 'public'] { |
| 22 | directory := deep_directory(os.join_path(base, 'long-hook-file', backend, 'root')) |
| 23 | fd := C.open(unsafe { &char(directory.str) }, C.O_RDONLY | C.O_DIRECTORY | C.O_CLOEXEC) |
| 24 | if fd < 0 { |
| 25 | if C.errno == C.ENOENT { continue } |
| 26 | return os.last_error() |
| 27 | } |
| 28 | defer { if C.close(fd) != 0 { eprintln(os.last_error()) } } |
| 29 | name := long_filename() |
| 30 | if C.unlinkat(fd, unsafe { &char(name.str) }, 0) != 0 && C.errno != C.ENOENT { |
| 31 | return os.last_error() |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |