@@ -20,6 +20,9 @@ @implementation UploadManager {
2020
2121 // For retry
2222 NSInteger retryCount;
23+
24+ //
25+ NSString *workingDirectory;
2326}
2427
2528+(void )setupDBClientsManager {
@@ -41,6 +44,11 @@ - (instancetype)init {
4144 return self;
4245}
4346
47+ - (void )createNewWorkingDirectory {
48+ workingDirectory = [NSTemporaryDirectory () stringByAppendingPathComponent: [[NSUUID UUID ] UUIDString ]];
49+ [ABLog log: @" New temporaray working directory %@ " , workingDirectory];
50+ }
51+
4452#pragma mark - UnZip IPA File
4553
4654-(void )uploadIPAFile : (NSURL *)ipaFileURL {
@@ -53,11 +61,12 @@ -(void)uploadIPAFile:(NSURL *)ipaFileURL{
5361 __block NSString *payloadEntry;
5462 __block NSString *infoPlistPath;
5563
56- NSString *tempDir = [NSTemporaryDirectory () stringByAppendingPathComponent: [[NSUUID UUID ] UUIDString ]];
64+ // Create new temp working directory
65+ [self createNewWorkingDirectory ];
5766
58- [ABLog log: @" Extracting Files to - %@ " , tempDir ];
67+ [ABLog log: @" Extracting Files to - %@ " , workingDirectory ];
5968 dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_BACKGROUND , 0 ), ^{
60- [SSZipArchive unzipFileAtPath: ipaPath toDestination: NSTemporaryDirectory () overwrite: YES password: nil progressHandler: ^(NSString * _Nonnull entry, unz_file_info zipInfo, long entryNumber, long total) {
69+ [SSZipArchive unzipFileAtPath: ipaPath toDestination: workingDirectory overwrite: YES password: nil progressHandler: ^(NSString * _Nonnull entry, unz_file_info zipInfo, long entryNumber, long total) {
6170 strongify (self);
6271 dispatch_async (dispatch_get_main_queue (), ^{
6372 [self showStatus: @" Extracting files..." andShowProgressBar: YES withProgress: -1 ];
@@ -86,7 +95,7 @@ -(void)uploadIPAFile:(NSURL *)ipaFileURL{
8695 NSString *mobileProvisionPath = [payloadEntry stringByAppendingPathComponent: @" embedded.mobileprovision" ].lowercaseString ;
8796 if ([entry.lowercaseString isEqualToString: mobileProvisionPath]){
8897 [ABLog log: @" Found mobileprovision at path = %@ " ,mobileProvisionPath];
89- mobileProvisionPath = [tempDir stringByAppendingPathComponent: mobileProvisionPath];
98+ mobileProvisionPath = [workingDirectory stringByAppendingPathComponent: mobileProvisionPath];
9099 self.project .mobileProvision = [[MobileProvision alloc ] initWithPath: mobileProvisionPath];
91100 }
92101 }
@@ -112,7 +121,7 @@ -(void)uploadIPAFile:(NSURL *)ipaFileURL{
112121
113122 // get info.plist
114123 [ABLog log: @" Final Info.plist path = %@ " ,infoPlistPath];
115- [self .project setIpaInfoPlist: [NSDictionary dictionaryWithContentsOfFile: [tempDir stringByAppendingPathComponent: infoPlistPath]]];
124+ [self .project setIpaInfoPlist: [NSDictionary dictionaryWithContentsOfFile: [workingDirectory stringByAppendingPathComponent: infoPlistPath]]];
116125
117126 // show error if info.plist is nil or invalid
118127 if (![self .project isValidProjectInfoPlist ]) {
@@ -170,14 +179,13 @@ -(void)uploadIPAFileWithoutUnzip:(NSURL *)ipaURL{
170179 [self dbUploadFile: ipaURL.resourceSpecifier.stringByRemovingPercentEncoding to: self .project.dbIPAFullPath.absoluteString mode: [[DBFILESWriteMode alloc ] initWithOverwrite ]];
171180 }];
172181 }
173- [ABLog log: @" Temporaray Folder %@ " , NSTemporaryDirectory ()];
174182}
175183
176184
177185#pragma mark - UNIQUE Link Handlers
178186-(void )handleAfterUniqueJsonMetaDataLoaded {
179187 if (self.project .uniqueLinkJsonMetaData ){
180- NSURL *path = [NSURL fileURLWithPath: [NSTemporaryDirectory () stringByAppendingPathComponent: FILE_NAME_UNIQUE_JSON ]];
188+ NSURL *path = [NSURL fileURLWithPath: [workingDirectory stringByAppendingPathComponent: FILE_NAME_UNIQUE_JSON ]];
181189 weakify (self);
182190 // download appinfo.json file
183191 [[[DBClientsManager authorizedClient ].filesRoutes downloadUrl: self .project.uniqueLinkJsonMetaData.pathDisplay overwrite: YES destination: path]
@@ -204,7 +212,7 @@ -(void)handleAfterUniqueJsonMetaDataLoaded{
204212
205213-(NSDictionary *)getUniqueJsonDict {
206214 NSError *error;
207- NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData: [NSData dataWithContentsOfFile: [NSTemporaryDirectory () stringByAppendingPathComponent: FILE_NAME_UNIQUE_JSON ]] options: kNilOptions error: &error];
215+ NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData: [NSData dataWithContentsOfFile: [workingDirectory stringByAppendingPathComponent: FILE_NAME_UNIQUE_JSON ]] options: kNilOptions error: &error];
208216 [ABLog log: @" %@ : %@ " ,FILE_NAME_UNIQUE_JSON ,dictionary];
209217 return dictionary;
210218}
@@ -323,7 +331,7 @@ -(void)updateUniquLinkDictinory:(NSMutableDictionary *)dictUniqueLink{
323331}
324332
325333-(void )writeUniqueJsonWithDict : (NSDictionary *)jsonDict {
326- NSString *path = [NSTemporaryDirectory () stringByAppendingPathComponent: FILE_NAME_UNIQUE_JSON ];
334+ NSString *path = [workingDirectory stringByAppendingPathComponent: FILE_NAME_UNIQUE_JSON ];
327335 if ([[NSFileManager defaultManager ] fileExistsAtPath: path]){
328336 [[NSFileManager defaultManager ] removeItemAtPath: path error: nil ];
329337 }
@@ -334,7 +342,7 @@ -(void)writeUniqueJsonWithDict:(NSDictionary *)jsonDict{
334342
335343-(void )uploadUniqueLinkJsonFile {
336344 self.dbFileType = DBFileTypeJson;
337- NSURL *path = [NSURL fileURLWithPath: [NSTemporaryDirectory () stringByAppendingPathComponent: FILE_NAME_UNIQUE_JSON ]];
345+ NSURL *path = [NSURL fileURLWithPath: [workingDirectory stringByAppendingPathComponent: FILE_NAME_UNIQUE_JSON ]];
338346
339347 // set mode for appinfo.json file to upload/update
340348 DBFILESWriteMode *mode = (self.project .uniqueLinkJsonMetaData ) ? [[DBFILESWriteMode alloc ] initWithUpdate: self .project.uniqueLinkJsonMetaData.rev] : [[DBFILESWriteMode alloc ] initWithOverwrite ];
0 commit comments