Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,23 @@ static bool check_path_should_skip(const char *path)
return false;
}

#define WALK_PATH_MAX_DEPTH 256

static int walk_path_recursive(sftp_session sftp, const char *path,
struct path_resolve_args *a)
struct path_resolve_args *a, unsigned int depth)
{
char next_path[PATH_MAX + 1];
struct dirent *e;
struct stat st;
MDIR *d;
int ret;

if (depth > WALK_PATH_MAX_DEPTH) {
pr_err("directory nesting too deep (>%d): %s",
WALK_PATH_MAX_DEPTH, path);
return -1;
}

if (mscp_stat(path, &st, sftp) < 0) {
pr_err("stat: %s: %s", path, strerrno());
return -1;
Expand Down Expand Up @@ -245,7 +253,7 @@ static int walk_path_recursive(sftp_session sftp, const char *path,
continue;
}

walk_path_recursive(sftp, next_path, a);
walk_path_recursive(sftp, next_path, a, depth + 1);
/* do not stop even when walk_path_recursive returns
* -1 due to an unreadable file. go to a next
* file. Thus, do not pass error messages via
Expand All @@ -262,7 +270,7 @@ static int walk_path_recursive(sftp_session sftp, const char *path,
int walk_src_path(sftp_session src_sftp, const char *src_path,
struct path_resolve_args *a)
{
return walk_path_recursive(src_sftp, src_path, a);
return walk_path_recursive(src_sftp, src_path, a, 0);
}

/* based on
Expand Down