Uses proper filtering in import/search.

This commit is contained in:
Andrea Mazzoleni 2014-11-19 22:55:24 +01:00
parent 22dcc028df
commit e625fc1292
3 changed files with 65 additions and 25 deletions

View file

@ -236,7 +236,7 @@ static void import_dir(struct snapraid_state* state, const char* dir)
}
while (1) {
char path[PATH_MAX];
char path_next[PATH_MAX];
struct stat st;
const char* name;
struct dirent* dd;
@ -259,9 +259,7 @@ static void import_dir(struct snapraid_state* state, const char* dir)
if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0)))
continue;
pathprint(path, sizeof(path), "%s", dir);
pathslash(path, sizeof(path));
pathcat(path, sizeof(path), name);
pathprint(path_next, sizeof(path_next), "%s%s", dir, name);
#if HAVE_STRUCT_DIRENT_D_STAT
/* convert dirent to lstat result */
@ -273,27 +271,28 @@ static void import_dir(struct snapraid_state* state, const char* dir)
/* Note that here we cannot call here lstat_sync(), because we don't know what kind */
/* of file is it, and lstat_sync() doesn't always work */
if (st.st_mode == 0) {
if (lstat(path, &st) != 0) {
if (lstat(path_next, &st) != 0) {
/* LCOV_EXCL_START */
fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path, strerror(errno));
fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
}
#else
/* get lstat info about the file */
if (lstat(path, &st) != 0) {
if (lstat(path_next, &st) != 0) {
/* LCOV_EXCL_START */
fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path, strerror(errno));
fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
#endif
if (S_ISREG(st.st_mode)) {
import_file(state, path, st.st_size);
import_file(state, path_next, st.st_size);
} else if (S_ISDIR(st.st_mode)) {
import_dir(state, path);
pathslash(path_next, sizeof(path_next));
import_dir(state, path_next);
}
}
@ -307,8 +306,14 @@ static void import_dir(struct snapraid_state* state, const char* dir)
void state_import(struct snapraid_state* state, const char* dir)
{
char path[PATH_MAX];
printf("Importing...\n");
import_dir(state, dir);
/* add the final slash */
pathimport(path, sizeof(path), dir);
pathslash(path, sizeof(path));
import_dir(state, path);
}