static INT64_T do_localpath(int argc, char **argv) { char localpath[CHIRP_LINE_MAX]; char full_path[CHIRP_LINE_MAX]; int result; if(argc == 2) { complete_remote_path(argv[1], full_path); } else { complete_remote_path(".", full_path); } result = chirp_reli_localpath(current_host, full_path, localpath, sizeof(localpath), stoptime); if(result >= 0) { localpath[result] = 0; printf("%s\n", localpath); } return result; }
INT64_T get_local_path(char *local_path, char *path, time_t stoptime) { char *hostname, *chirp_path; char *p; int i, count; p = strchr(path, '/'); if(p == NULL || p != path) { getcwd(local_path, CHIRP_PATH_MAX); strcat(local_path, "/"); strcat(local_path, path); if(local_path[strlen(local_path) - 1] != '/') strcat(local_path, "/"); return 0; } else { if(strncmp(p + 1, "chirp/", 6) != 0) { // Given path is already a local path, return directly. strcpy(local_path, path); if(local_path[strlen(local_path) - 1] != '/') strcat(local_path, "/"); return 0; } } hostname = (char *) malloc(CHIRP_PATH_MAX * sizeof(char)); // allocate space for the source host if(hostname == NULL) { fprintf(stderr, "Allocating hostname memory failed! \n"); return -1; } gethostname(hostname, CHIRP_PATH_MAX); // this may not have domain name, though! if(hostname == NULL) { printf("no hostname!\n"); return -1; } INT64_T retval; // get chirp path count = 0; for(i = 0; i < strlen(path); i++) { if(path[i] == '/') count++; if(count == 3) break; } if(count != 3) { fprintf(stderr, "Cannot resolve chirp path - %s. Failed!\n", path); return -1; } while(i < strlen(path)) { i++; if(path[i] != '/') break; } chirp_path = path + i - 1; for(i = 0; i < CHIRP_PATH_MAX; i++) local_path[i] = '\0'; debug(D_CHIRP, "chirp_path: %s\n", chirp_path); debug(D_CHIRP, "local_path before resolve: %s\n", local_path); // get local path for the given chirp path on current machine retval = chirp_reli_localpath(hostname, chirp_path, local_path, CHIRP_PATH_MAX, stoptime); if(retval < 0) { return retval; } else { debug(D_CHIRP, "local_path after resolve: %s\n", local_path); if(local_path[strlen(local_path) - 1] != '/') strcat(local_path, "/"); return 0; } }