Browse Source

overwriting smarts in place, if i really want to make it better should probably just increment the file name in some way

Kevin Bradley 7 months ago
parent
commit
40fae27545

+ 1 - 1
bootstrapTool/Classes/HelperClass.h

@@ -1,7 +1,7 @@
 
 @interface HelperClass: NSObject
 
-+ (BOOL)shouldContinueWithError:(NSString *)errorMessage;
++ (BOOL)shouldContinueWithPrompt:(NSString *)prompt;
 + (NSArray *)returnForProcess:(NSString *)call;
 + (InputPackage *)packageForDeb:(NSString *)debFile;
 + (NSString *)octalFromSymbols:(NSString *)theSymbols;

+ 4 - 4
bootstrapTool/Classes/HelperClass.m

@@ -96,7 +96,7 @@
         }];
         DLog(@"\nFiles to process: %@\n", filesToProcess);
         NSString *error = [NSString stringWithFormat:@" [WARNING] We are about to delete '%@' from the bootstrap, this cannot be undone!", deletePackage];
-        if(![HelperClass shouldContinueWithError:error]){
+        if(![HelperClass shouldContinueWithPrompt:error]){
             return -1;
         }
         [filesToProcess enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
@@ -254,10 +254,10 @@
     return atoi(buf);
 }
 
-+ (BOOL)shouldContinueWithError:(NSString *)errorMessage {
-    NSString *errorString = [NSString stringWithFormat:@"\n%@ Are you sure you want to continue? [y/n]?", errorMessage];
++ (BOOL)shouldContinueWithPrompt:(NSString *)prompt {
+    NSString *promptString = [NSString stringWithFormat:@"\n%@ Are you sure you want to continue? [y/n]?", prompt];
     char c;
-    printf("%s", [errorString UTF8String] );
+    printf("%s", [promptString UTF8String] );
     c=getchar();
     while(c!='y' && c!='n') {
         if (c!='\n'){

+ 28 - 5
bootstrapTool/Classes/InputPackage.m

@@ -187,7 +187,7 @@
             
             NSString *error = [NSString stringWithFormat:@" [WARNING] %@ will overwrite the following files: \n\n\t%@\n\n", self.path.lastPathComponent, [safePackage.overwriteFiles componentsJoinedByString:@"\n\t"]];
             if (!self.forceOverwrite) {
-                if(![HelperClass shouldContinueWithError:error]){
+                if(![HelperClass shouldContinueWithPrompt:error]){
                     
                     return -1;
                 }
@@ -564,9 +564,20 @@
         DLog(@"[INFO] moving %@ to %@", oldPath, newPath);
         [FM moveItemAtPath:oldPath toPath:newPath error:nil];
     }];
-    NSString *depArchiveInfo = [NSString stringWithFormat:@"%@ -b %@ %@", dpkg, self.packageName, [self fullPackageName]];
+    NSString *fullName = [self fullPackageName];
+    if ([FM fileExistsAtPath:fullName]){
+        NSString *overwritePrompt = [NSString stringWithFormat:@"%@ already exists, continuing will overwrite it.", fullName];
+        BOOL shouldOverwrite = [HelperClass shouldContinueWithPrompt:overwritePrompt];
+        if (shouldOverwrite) {
+            [FM removeItemAtPath:fullName error:nil];
+        } else {
+            DLog(@"Not overwriting file... bailing out!");
+            return;
+        }
+    }
+    NSString *depArchiveInfo = [NSString stringWithFormat:@"%@ -b %@ %@", dpkg, self.packageName, fullName];
     if (fakeRoot) {
-        depArchiveInfo = [NSString stringWithFormat:@"%@ %@ -b %@ %@", fakeRoot, dpkg, self.packageName, [self fullPackageName]];
+        depArchiveInfo = [NSString stringWithFormat:@"%@ %@ -b %@ %@", fakeRoot, dpkg, self.packageName, fullName];
     }
     [[HelperClass returnForProcess:depArchiveInfo] componentsJoinedByString:@"\n"];
     DLog(@"\nDone!\n\n");
@@ -715,9 +726,21 @@
         DLog(@"[INFO] moving %@ to %@", oldPath, newPath);
         [FM moveItemAtPath:oldPath toPath:newPath error:nil];
     }];
-    NSString *depArchiveInfo = [NSString stringWithFormat:@"%@ -b %@", dpkg, self.packageName];
+    
+    NSString *fullName = [self fullPackageName];
+    if ([FM fileExistsAtPath:fullName]){
+        NSString *overwritePrompt = [NSString stringWithFormat:@"%@ already exists, do you want to overwrite it? [y/n]", fullName];
+        BOOL shouldOverwrite = [HelperClass shouldContinueWithPrompt:overwritePrompt];
+        if (shouldOverwrite) {
+            [FM removeItemAtPath:fullName error:nil];
+        } else {
+            DLog(@"Not overwriting file... bailing out!");
+            return;
+        }
+    }
+    NSString *depArchiveInfo = [NSString stringWithFormat:@"%@ -b %@ %@", dpkg, self.packageName, fullName];
     if (fakeRoot) {
-        depArchiveInfo = [NSString stringWithFormat:@"%@ %@ -b %@", fakeRoot, dpkg, self.packageName];
+        depArchiveInfo = [NSString stringWithFormat:@"%@ %@ -b %@ %@", fakeRoot, dpkg, self.packageName, fullName];
     }
     [[HelperClass returnForProcess:depArchiveInfo] componentsJoinedByString:@"\n"];
     DLog(@"\nDone!\n\n");