2013-10-10 08:46:57 +02:00
|
|
|
#include "qfile-utils.h"
|
2011-03-16 11:06:27 +01:00
|
|
|
|
2013-12-30 11:35:46 +01:00
|
|
|
char *get_abs_path(const char *cwd, const char *pathname)
|
2011-03-15 16:07:00 +01:00
|
|
|
{
|
2013-10-10 08:46:57 +02:00
|
|
|
char *ret;
|
|
|
|
if (pathname[0] == '/')
|
|
|
|
return strdup(pathname);
|
2014-04-22 00:56:52 +02:00
|
|
|
if (asprintf(&ret, "%s/%s", cwd, pathname) < 0)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return ret;
|
2011-03-15 16:07:00 +01:00
|
|
|
}
|
|
|
|
|
2013-12-30 11:35:46 +01:00
|
|
|
int do_fs_walk(const char *file)
|
2011-03-15 16:07:00 +01:00
|
|
|
{
|
|
|
|
char *newfile;
|
|
|
|
struct stat st;
|
|
|
|
struct dirent *ent;
|
|
|
|
DIR *dir;
|
|
|
|
|
|
|
|
if (lstat(file, &st))
|
|
|
|
gui_fatal("stat %s", file);
|
|
|
|
single_file_processor(file, &st);
|
|
|
|
if (!S_ISDIR(st.st_mode))
|
|
|
|
return 0;
|
|
|
|
dir = opendir(file);
|
|
|
|
if (!dir)
|
|
|
|
gui_fatal("opendir %s", file);
|
|
|
|
while ((ent = readdir(dir))) {
|
|
|
|
char *fname = ent->d_name;
|
|
|
|
if (!strcmp(fname, ".") || !strcmp(fname, ".."))
|
|
|
|
continue;
|
2014-04-22 00:56:52 +02:00
|
|
|
if (asprintf(&newfile, "%s/%s", file, fname) >= 0) {
|
|
|
|
do_fs_walk(newfile);
|
|
|
|
free(newfile);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "asprintf failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-03-15 16:07:00 +01:00
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
// directory metadata is resent; this makes the code simple,
|
|
|
|
// and the atime/mtime is set correctly at the second time
|
|
|
|
single_file_processor(file, &st);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-06 10:17:58 +02:00
|
|
|
int main(int argc, char **argv)
|
2011-03-15 16:07:00 +01:00
|
|
|
{
|
2011-07-06 10:17:58 +02:00
|
|
|
int i;
|
|
|
|
char *entry;
|
|
|
|
char *cwd;
|
|
|
|
char *sep;
|
|
|
|
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2012-08-25 01:26:19 +02:00
|
|
|
// this will allow checking for possible feedback packet in the middle of transfer
|
|
|
|
set_nonblock(0);
|
2014-02-07 05:32:57 +01:00
|
|
|
register_notify_progress(¬ify_progress);
|
2011-03-16 11:06:27 +01:00
|
|
|
notify_progress(0, PROGRESS_FLAG_INIT);
|
2011-05-26 00:12:14 +02:00
|
|
|
crc32_sum = 0;
|
2011-07-06 10:17:58 +02:00
|
|
|
cwd = getcwd(NULL, 0);
|
|
|
|
for (i = 1; i < argc; i++) {
|
2013-08-14 22:12:46 +02:00
|
|
|
if (strcmp(argv[i], "--ignore-symlinks")==0) {
|
|
|
|
ignore_symlinks = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-07-06 10:17:58 +02:00
|
|
|
entry = get_abs_path(cwd, argv[i]);
|
|
|
|
|
2011-03-16 10:48:27 +01:00
|
|
|
do {
|
|
|
|
sep = rindex(entry, '/');
|
|
|
|
if (!sep)
|
|
|
|
gui_fatal
|
|
|
|
("Internal error: nonabsolute filenames not allowed");
|
|
|
|
*sep = 0;
|
|
|
|
} while (sep[1] == 0);
|
2014-04-22 00:56:52 +02:00
|
|
|
if (entry[0] == 0) {
|
|
|
|
if (chdir("/") < 0) {
|
|
|
|
gui_fatal("Internal error: chdir(\"/\") failed?!");
|
|
|
|
}
|
|
|
|
} else if (chdir(entry))
|
2011-03-15 16:07:00 +01:00
|
|
|
gui_fatal("chdir to %s", entry);
|
|
|
|
do_fs_walk(sep + 1);
|
2011-07-06 10:17:58 +02:00
|
|
|
free(entry);
|
2011-03-15 16:07:00 +01:00
|
|
|
}
|
2011-05-26 00:12:14 +02:00
|
|
|
notify_end_and_wait_for_result();
|
2011-03-16 11:06:27 +01:00
|
|
|
notify_progress(0, PROGRESS_FLAG_DONE);
|
2011-03-15 16:07:00 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-10 08:46:57 +02:00
|
|
|
|
|
|
|
|