static INT64_T do_get_one_file(const char *hostport, const char *source_file, const char *target_file, int mode, INT64_T length, time_t stoptime) { FILE *file; int save_errno; INT64_T actual; file = fopen64(target_file, "w"); if(!file) return -1; fchmod(fileno(file), mode); actual = chirp_reli_getfile(hostport, source_file, file, stoptime); if(actual != length) { save_errno = errno; fclose(file); errno = save_errno; return -1; } if(length >= 0) { fclose(file); return length; } else { save_errno = errno; fclose(file); errno = save_errno; return -1; } }
INT64_T chirp_multi_getfile(const char *volume, const char *path, FILE * stream, time_t stoptime) { struct file_info info; if(!chirp_multi_lookup(volume, path, &info, stoptime)) return -1; return chirp_reli_getfile(info.rhost, info.rpath, stream, stoptime); }
static INT64_T do_cat(int argc, char **argv) { INT64_T actual; int i; for(i = 1; i < argc; i++) { char full_path[CHIRP_PATH_MAX]; complete_remote_path(argv[i], full_path); actual = chirp_reli_getfile(current_host, full_path, stdout, stoptime); if(actual < 0) { fprintf(stderr, "%s: %s\n", full_path, strerror(errno)); } } return 0; }
INT64_T chirp_global_getfile(const char *host, const char *path, FILE * stream, 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_getfile(mhost, mpath, stream, stoptime); } else if(not_empty(path)) { return chirp_reli_getfile(host, path, stream, stoptime); } else if(not_empty(host)) { if(server_lookup(host, stoptime)) { errno = EISDIR; return -1; } else { errno = EACCES; return -1; } } else { errno = EACCES; return -1; } }
int main(int argc, char *argv[]) { int did_explicit_auth = 0; int stdout_mode = 0; const char *hostname, *source_file, *target_file; time_t stoptime; FILE *file; INT64_T result; char c; char *tickets = NULL; debug_config(argv[0]); while((c = getopt(argc, argv, "a:d:i:t:vh")) != (char) -1) { switch (c) { case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 'd': debug_flags_set(optarg); break; case 'i': tickets = strdup(optarg); break; case 't': timeout = string_time_parse(optarg); break; case 'v': show_version(argv[0]); exit(0); break; case 'h': show_help(argv[0]); exit(0); break; } } if(!did_explicit_auth) auth_register_all(); if(tickets) { auth_ticket_load(tickets); free(tickets); } else if(getenv(CHIRP_CLIENT_TICKETS)) { auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS)); } else { auth_ticket_load(NULL); } if((argc - optind) < 3) { show_help(argv[0]); exit(0); } hostname = argv[optind]; source_file = argv[optind + 1]; target_file = argv[optind + 2]; stoptime = time(0) + timeout; if(!strcmp(target_file, "-")) { stdout_mode = 1; file = stdout; } if(stdout_mode) { result = chirp_reli_getfile(hostname, source_file, file, stoptime); } else { result = chirp_recursive_get(hostname, source_file, target_file, stoptime); } if(result < 0) { fprintf(stderr, "couldn't get %s:%s: %s\n", hostname, source_file, strerror(errno)); return 1; } else { return 0; } }