diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-30 17:21:01 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-30 17:21:22 +0200 |
commit | 8a572a7cf41d220f6afbf4ea9a65710edf885e98 (patch) | |
tree | 18fd584bd315f8d78ee9ce4606e92e7d302a2645 /get.c | |
parent | Second commit (diff) | |
download | anysum-8a572a7cf41d220f6afbf4ea9a65710edf885e98.tar.gz anysum-8a572a7cf41d220f6afbf4ea9a65710edf885e98.tar.bz2 anysum-8a572a7cf41d220f6afbf4ea9a65710edf885e98.tar.xz |
m + add -W[no-]xlink and -W[no-]xdev
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | get.c | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -10,8 +10,10 @@ struct recursion_buffer { static int -calculate_and_print(const char *file, struct barrier_group *group, struct global_data *global, struct recursion_buffer *recbuf) +calculate_and_print(const char *file, struct barrier_group *group, struct global_data *global, + struct recursion_buffer *recbuf, int is_top, int xlink, int xdev, dev_t dev) { + static struct stat st; struct dirent *f; DIR *dir; size_t i, len, old_len; @@ -21,6 +23,20 @@ calculate_and_print(const char *file, struct barrier_group *group, struct global dir = opendir(file); if (!dir) goto as_file; + if (!is_top && !xlink) { + if (lstat(file, &st)) + goto recusion_error_print; + if (S_ISLNK(st.st_mode)) + return 0; + } + if (!xdev) { + if (fstat(dirfd(dir), &st)) + goto recusion_error_print; + if (is_top) + dev = st.st_dev; + else if (st.st_dev != dev) + return 0; + } if (recbuf->size - recbuf->len < strlen(file) + 1U) { recbuf->size = recbuf->len + strlen(file) + 1U; recbuf->buf = erealloc(recbuf->buf, recbuf->size); @@ -32,17 +48,20 @@ calculate_and_print(const char *file, struct barrier_group *group, struct global recbuf->buf[recbuf->len++] = '/'; len = recbuf->len; while ((errno = 0, f = readdir(dir))) { + if (f->d_name[0] == '.' && !f->d_name[f->d_name[1] == '.' ? 2 : 1]) + continue; if (recbuf->size - len < strlen(f->d_name) + 1U) { recbuf->size = len + strlen(f->d_name) + 1U; recbuf->buf = erealloc(recbuf->buf, recbuf->size); } stpcpy(&recbuf->buf[len], f->d_name); - if (calculate_and_print(recbuf->buf, group, global, recbuf)) + if (calculate_and_print(recbuf->buf, group, global, recbuf, 0, xlink, xdev, dev)) goto recusion_error; } recbuf->len = old_len; recbuf->buf[recbuf->len] = '\0'; if (errno) { + recusion_error_print: weprintf("%s:", file); recusion_error: closedir(dir); @@ -63,7 +82,8 @@ as_file: int calculate_and_print_each(char **files, struct algorithm *algorithms, size_t nalgorithms, - size_t nthreads, enum format format, int hexinput, int recursive) + size_t nthreads, enum format format, int hexinput, int recursive, + int xdev, int xlink) { struct recursion_buffer recbuf = {NULL, 0, 0}; size_t wanted_nalgorithms = nalgorithms; @@ -85,7 +105,7 @@ calculate_and_print_each(char **files, struct algorithm *algorithms, size_t nalg createbarriergroup(&group, nthreads, &global); for (; *files; files++) - if (calculate_and_print(*files, &group, &global, recursive ? &recbuf : NULL)) + if (calculate_and_print(*files, &group, &global, recursive ? &recbuf : NULL, 1, xlink, xdev, 0)) ret = 2; if (global.nalgorithms != wanted_nalgorithms) |