static int traverse_dir (const char *id) { SeafDir *dir; GList *p; SeafDirent *seaf_dent; dir = seaf_fs_manager_get_seafdir (seaf->fs_mgr, id); if (!dir) { fprintf (stderr, "Failed to read dir %s\n", id); return -1; } for (p = dir->entries; p; p = p->next) { seaf_dent = (SeafDirent *)p->data; if (S_ISREG(seaf_dent->mode)) { printf ("check file %s\n", seaf_dent->name); return check_seafile (seaf_dent->id); } else if (S_ISDIR(seaf_dent->mode)) { printf ("check directory %s\n", seaf_dent->name); return traverse_dir (seaf_dent->id); } } seaf_dir_free (dir); return 0; }
int main (int argc, char **argv) { const gchar *srcdir; gchar *env_str; gchar *path = NULL; GError *err = NULL; /* for autotools integration */ if (! (srcdir = g_getenv ("srcdir"))) { srcdir = "."; } /* possible arg to override */ if (argc == 2) { srcdir = argv[1]; } else if (argc > 2) { fprintf (stderr, "USAGE: %s SRCDIR", argv[0]); return 1; } g_type_init (); #define setptr(ptr, val) (ptr = (g_free (ptr), val)) setptr (path, g_build_filename (srcdir, "environ", NULL)); get_file_content (path, &env_str, FALSE); setptr (path, g_build_filename (srcdir, "success", NULL)); traverse_dir (path, success_tests_item, env_str); setptr (path, g_build_filename (srcdir, "fail", NULL)); traverse_dir (path, fail_tests_item, env_str); setptr (path, NULL); #undef setptr g_free (env_str); return 0; }
void stat_cache_test (char *path) { struct timeval starttime, endtime; u_int64_t startusecs, endusecs; gettimeofday (&starttime, NULL); if (traverse_dir (path) < 0) return; gettimeofday (&endtime, NULL); startusecs = timeval_to_usecs (starttime); endusecs = timeval_to_usecs (endtime); fprintf (stdout, "Run: %"PRIu64" usecs ", (endusecs-startusecs)); fflush (stdout); }
static void check_readdir_shorttree(void **state) { statevar *sv = (statevar*) *state; const char *t1 = "alibaba/und/die/vierzig/räuber/"; create_dirs( t1 ); int files_cnt = 0; traverse_dir(state, CSYNC_TEST_DIR, &files_cnt); assert_string_equal( sv->result, "<DIR> C:/tmp/csync_test/alibaba" "<DIR> C:/tmp/csync_test/alibaba/und" "<DIR> C:/tmp/csync_test/alibaba/und/die" "<DIR> C:/tmp/csync_test/alibaba/und/die/vierzig" "<DIR> C:/tmp/csync_test/alibaba/und/die/vierzig/räuber" ); assert_int_equal(files_cnt, 0); }
static void mypub1(amqp_channel_t *chan, char *path) { struct stat sb; CTRACE("path=%s", path); if (stat(path, &sb) != 0) { perror("stat"); return; } if (S_ISDIR(sb.st_mode)) { if (traverse_dir(path, traversedir_cb, chan) != 0) { CTRACE("traverse_dir error"); } } else { CTRACE("file=%s", path); } }
// https://github.com/owncloud/client/issues/3128 https://github.com/owncloud/client/issues/2777 static void check_readdir_bigunicode(void **state) { statevar *sv = (statevar*) *state; // 1: ? ASCII: 239 - EF // 2: ? ASCII: 187 - BB // 3: ? ASCII: 191 - BF // 4: ASCII: 32 - 20 char *p = 0; asprintf( &p, "%s/%s", CSYNC_TEST_DIR, "goodone/" ); int rc = _tmkdir(p, MKDIR_MASK); assert_int_equal(rc, 0); SAFE_FREE(p); const char *t1 = "goodone/ugly\xEF\xBB\xBF\x32" ".txt"; asprintf( &p, "%s/%s", CSYNC_TEST_DIR, t1 ); rc = _tmkdir(p, MKDIR_MASK); SAFE_FREE(p); assert_int_equal(rc, 0); int files_cnt = 0; traverse_dir(state, CSYNC_TEST_DIR, &files_cnt); const char *expected_result = "<DIR> C:/tmp/csync_test/goodone" #ifndef __APPLE__ // On Mac, iconv will not return some files with fancy unicode. // Linux is not so picky about it and return everything and let the sync engine deal with it. "<DIR> C:/tmp/csync_test/goodone/ugly\xEF\xBB\xBF\x32" ".txt" #endif ; assert_string_equal( sv->result, expected_result); #ifdef __APPLE__ // Bad one is recognized though.. ! assert_string_equal( sv->ignored_dir, CSYNC_TEST_DIR "/goodone/" "ugly\xEF\xBB\xBF\x32" ".txt"); #endif assert_int_equal(files_cnt, 0); }
static void check_readdir_with_content(void **state) { statevar *sv = (statevar*) *state; int files_cnt = 0; const char *t1 = "warum/nur/40/Räuber/"; create_dirs( t1 ); create_file( t1, "Räuber Max.txt", "Der Max ist ein schlimmer finger"); create_file( t1, "пя́тница.txt", "Am Freitag tanzt der Ürk"); traverse_dir(state, CSYNC_TEST_DIR, &files_cnt); assert_string_equal( sv->result, "<DIR> C:/tmp/csync_test/warum" "<DIR> C:/tmp/csync_test/warum/nur" "<DIR> C:/tmp/csync_test/warum/nur/40" "<DIR> C:/tmp/csync_test/warum/nur/40/Räuber"); /* " C:/tmp/csync_test/warum/nur/40/Räuber/Räuber Max.txt" " C:/tmp/csync_test/warum/nur/40/Räuber/пя́тница.txt"); */ assert_int_equal(files_cnt, 2); /* Two files in the sub dir */ }
static int test_commit() { SeafRepo *repo; SeafCommit *commit; const char *commit_id; printf ("\n=== test commit\n"); repo = create_repo ("test-commit"); commit_id = first_commit (repo); printf ("*** print index\n"); if (print_index (repo) < 0) return -1; commit = seaf_commit_manager_get_commit (seaf->commit_mgr, commit_id); if (!commit) { fprintf (stderr, "Failed to get commit\n"); return -1; } if (traverse_dir (commit->root_id) < 0) return -1; /* status */ char *status = seaf_repo_status (repo); printf ("Status\n%s", status); g_assert (strcmp(status, "") == 0); g_free (status); seaf_commit_unref (commit); printf ("\n=== test commit succeeded.\n"); return 0; }
static void check_readdir_longtree(void **state) { statevar *sv = (statevar*) *state; /* Strange things here: Compilers only support strings with length of 4k max. * The expected result string is longer, so it needs to be split up in r1, r2 and r3 */ /* create the test tree */ const char *t1 = "vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln/VOLL RUM/"; create_dirs( t1 ); const char *r1 = "<DIR> C:/tmp/csync_test/vierzig" "<DIR> C:/tmp/csync_test/vierzig/mann" "<DIR> C:/tmp/csync_test/vierzig/mann/auf" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum"; const char *r2 = "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH"; const char *r3 = "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln" "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln/VOLL RUM"; /* assemble the result string ... */ int overall_len = 1+strlen(r1)+strlen(r2)+strlen(r3); int files_cnt = 0; char *result = c_malloc(overall_len); *result = '\0'; strcat(result, r1); strcat(result, r2); strcat(result, r3); traverse_dir(state, CSYNC_TEST_DIR, &files_cnt); assert_int_equal(files_cnt, 0); /* and compare. */ assert_string_equal( sv->result, result); }
/* * This function uses the vio_opendir, vio_readdir and vio_closedir functions * to traverse a file tree that was created before by the create_dir function. * * It appends a listing to the result member of the incoming struct in *state * that can be compared later to what was expected in the calling functions. * * The int parameter cnt contains the number of seen files (not dirs) in the * whole tree. * */ static void traverse_dir(void **state, const char *dir, int *cnt) { csync_vio_handle_t *dh; csync_vio_file_stat_t *dirent; statevar *sv = (statevar*) *state; CSYNC *csync = sv->csync; char *subdir; char *subdir_out; int rc; int is_dir; /* Format: Smuggle in the C: for unix platforms as its urgently needed * on Windows and the test can be nicely cross platform this way. */ #ifdef _WIN32 const char *format_str = "%s %s"; #else const char *format_str = "%s C:%s"; #endif dh = csync_vio_opendir(csync, dir); assert_non_null(dh); while( (dirent = csync_vio_readdir(csync, dh)) ) { assert_non_null(dirent); if (dirent->original_name) { sv->ignored_dir = c_strdup(dirent->original_name); continue; } assert_non_null(dirent->name); assert_int_equal( dirent->fields & CSYNC_VIO_FILE_STAT_FIELDS_TYPE, CSYNC_VIO_FILE_STAT_FIELDS_TYPE ); if( c_streq( dirent->name, "..") || c_streq( dirent->name, "." )) { continue; } is_dir = (dirent->type == CSYNC_VIO_FILE_TYPE_DIRECTORY) ? 1:0; assert_int_not_equal( asprintf( &subdir, "%s/%s", dir, dirent->name ), -1 ); assert_int_not_equal( asprintf( &subdir_out, format_str, is_dir ? "<DIR>":" ", subdir), -1 ); if( is_dir ) { if( !sv->result ) { sv->result = c_strdup( subdir_out); } else { int newlen = 1+strlen(sv->result)+strlen(subdir_out); char *tmp = sv->result; sv->result = c_malloc(newlen); strcpy( sv->result, tmp); SAFE_FREE(tmp); strcat( sv->result, subdir_out ); } } else { *cnt = *cnt +1; } output(subdir_out); if( is_dir ) { traverse_dir( state, subdir, cnt); } SAFE_FREE(subdir); SAFE_FREE(subdir_out); } csync_vio_file_stat_destroy(dirent); rc = csync_vio_closedir(csync, dh); assert_int_equal(rc, 0); }