Fixes #126 - --download option works incorrectly

This commit is contained in:
Shazron Abdullah 2015-05-19 13:50:47 -07:00
parent 3ba7403a39
commit 8749a57936

View File

@ -1387,25 +1387,13 @@ void copy_file_callback(afc_connection* afc_conn_p, const char *name,int file)
} }
} }
void mkdirhier(char *path) BOOL mkdirp(NSString* path) {
{ NSError* error = nil;
char *slash; BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:path
struct stat buf; withIntermediateDirectories:YES
attributes:nil
if (path[0]=='.' && path[1]=='/') path+=2; error:&error];
return success;
if ((slash = strrchr(path,'/'))) {
*slash = '\0';
if (stat(path,&buf)==0) {
*slash = '/';
return;
}
mkdirhier(path);
mkdir (path,0777);
*slash = '/';
}
return;
} }
void download_tree(AMDeviceRef device) void download_tree(AMDeviceRef device)
@ -1413,12 +1401,15 @@ void download_tree(AMDeviceRef device)
service_conn_t houseFd = start_house_arrest_service(device); service_conn_t houseFd = start_house_arrest_service(device);
afc_connection* afc_conn_p = NULL; afc_connection* afc_conn_p = NULL;
char *dirname = NULL; char *dirname = NULL;
NSString* targetPath = [NSString pathWithComponents:@[ @(target_filename), @(list_root)] ];
mkdirp([targetPath stringByDeletingLastPathComponent]);
if (AFCConnectionOpen(houseFd, 0, &afc_conn_p) == 0) do { if (AFCConnectionOpen(houseFd, 0, &afc_conn_p) == 0) do {
if (target_filename) { if (target_filename) {
dirname = strdup(target_filename); dirname = strdup(target_filename);
mkdirhier(dirname); mkdirp(@(dirname));
if (mkdir(dirname,0777) && errno!=EEXIST) { if (mkdir(dirname,0777) && errno!=EEXIST) {
fprintf(stderr,"mkdir(\"%s\") failed: %s\n",dirname,strerror(errno)); fprintf(stderr,"mkdir(\"%s\") failed: %s\n",dirname,strerror(errno));
break; break;