aboutsummaryrefslogtreecommitdiffstats
path: root/get.c
diff options
context:
space:
mode:
Diffstat (limited to 'get.c')
-rw-r--r--get.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/get.c b/get.c
index 5758388..fe92ab3 100644
--- a/get.c
+++ b/get.c
@@ -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)