Skip to content

Commit 8749a57

Browse files
committed
Fixes #126 - --download option works incorrectly
1 parent 3ba7403 commit 8749a57

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

ios-deploy.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,38 +1387,29 @@ void copy_file_callback(afc_connection* afc_conn_p, const char *name,int file)
13871387
}
13881388
}
13891389

1390-
void mkdirhier(char *path)
1391-
{
1392-
char *slash;
1393-
struct stat buf;
1394-
1395-
if (path[0]=='.' && path[1]=='/') path+=2;
1396-
1397-
if ((slash = strrchr(path,'/'))) {
1398-
*slash = '\0';
1399-
if (stat(path,&buf)==0) {
1400-
*slash = '/';
1401-
return;
1402-
}
1403-
mkdirhier(path);
1404-
mkdir (path,0777);
1405-
*slash = '/';
1406-
}
1407-
1408-
return;
1390+
BOOL mkdirp(NSString* path) {
1391+
NSError* error = nil;
1392+
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:path
1393+
withIntermediateDirectories:YES
1394+
attributes:nil
1395+
error:&error];
1396+
return success;
14091397
}
14101398

14111399
void download_tree(AMDeviceRef device)
14121400
{
14131401
service_conn_t houseFd = start_house_arrest_service(device);
14141402
afc_connection* afc_conn_p = NULL;
14151403
char *dirname = NULL;
1404+
1405+
NSString* targetPath = [NSString pathWithComponents:@[ @(target_filename), @(list_root)] ];
1406+
mkdirp([targetPath stringByDeletingLastPathComponent]);
14161407

14171408
if (AFCConnectionOpen(houseFd, 0, &afc_conn_p) == 0) do {
14181409

14191410
if (target_filename) {
14201411
dirname = strdup(target_filename);
1421-
mkdirhier(dirname);
1412+
mkdirp(@(dirname));
14221413
if (mkdir(dirname,0777) && errno!=EEXIST) {
14231414
fprintf(stderr,"mkdir(\"%s\") failed: %s\n",dirname,strerror(errno));
14241415
break;

0 commit comments

Comments
 (0)