INT64_T chirp_global_getdir(const char *host, const char *path, chirp_dir_t callback, void *arg, time_t stoptime) { if(is_multi_path(host)) { char mhost[CHIRP_PATH_MAX]; char mpath[CHIRP_PATH_MAX]; parse_multi_path(path, mhost, mpath); return chirp_multi_getdir(mhost, mpath, callback, arg, stoptime); } else if(not_empty(path)) { return chirp_reli_getdir(host, path, callback, arg, stoptime); } else if(not_empty(host)) { return chirp_reli_getdir(host, "/", callback, arg, stoptime); } else { if(server_table_load(stoptime)) { char *key; void *item; hash_table_firstkey(server_table); while(hash_table_nextkey(server_table, &key, &item)) { callback(key, arg); } callback("multi", arg); return 0; } else { errno = ENOENT; return -1; } } }
INT64_T chirp_multi_getdir(const char *volume, const char *path, chirp_dir_t callback, void *arg, time_t stoptime) { char lpath[CHIRP_PATH_MAX]; if(!volume[0]) { callback(".", arg); callback("..", arg); return 0; } else if(!chirp_multi_lpath(volume, path, lpath, stoptime)) { return -1; } else { return chirp_reli_getdir(current_volume->host, lpath, callback, arg, stoptime); } }
static INT64_T do_get_one_dir(const char *hostport, const char *source_file, const char *target_file, int mode, time_t stoptime) { char new_source_file[CHIRP_PATH_MAX]; char new_target_file[CHIRP_PATH_MAX]; struct list *work_list; const char *name; INT64_T result; INT64_T total = 0; work_list = list_create(); result = mkdir(target_file, mode); if(result == 0 || errno == EEXIST) { result = chirp_reli_getdir(hostport, source_file, add_to_list, work_list, stoptime); if(result >= 0) { while((name = list_pop_head(work_list))) { if(!strcmp(name, ".")) continue; if(!strcmp(name, "..")) continue; sprintf(new_source_file, "%s/%s", source_file, name); sprintf(new_target_file, "%s/%s", target_file, name); result = chirp_recursive_get(hostport, new_source_file, new_target_file, stoptime); free((char *) name); if(result < 0) break; total += result; } } else { result = -1; } } else { result = -1; } while((name = list_pop_head(work_list))) free((char *) name); list_delete(work_list); if(result >= 0) { return total; } else { return -1; } }