aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-10-27 02:22:55 +0200
committerTeddy Wing2018-10-27 02:22:55 +0200
commitbcfbf591eb584c3b70f8e776057d52954c09bea3 (patch)
tree1c4076a790b305aed30aa8c20f715a77e6fc4ae5
parent6ceb56fac5dcabc02db6ebb373073593ddec9a33 (diff)
downloadDomeKey-bcfbf591eb584c3b70f8e776057d52954c09bea3.tar.bz2
LicenseHandler(addLicense:): Delete license file at the start
Previously, you couldn't replace the existing license file using the `--license` flag. If you somehow got an invalid license installed, you'd get an error message asking you to add your license again: "Try adding your license again using the `--license` flag." But this wouldn't work to replace the existing license. The copy operation would fail complaining about the file already existing. The behaviour of the method now is to always replace the license file, just in case it's necessary. We use the existing "move to trash" method, and make sure we ignore "does not exist" errors, because typically when you run `--license`, you're not going to have a `license.plist` file installed at the start, so for our purposes, that's not an error.
-rw-r--r--DomeKey/LicenseHandler.m10
1 files changed, 9 insertions, 1 deletions
diff --git a/DomeKey/LicenseHandler.m b/DomeKey/LicenseHandler.m
index da6d29f..70a59ad 100644
--- a/DomeKey/LicenseHandler.m
+++ b/DomeKey/LicenseHandler.m
@@ -32,6 +32,8 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist";
NSError *error = nil;
+ [self trashFileAtURL:[self licensePath]];
+
// Copy license file to XDG_DATA_HOME
BOOL copied = [[NSFileManager defaultManager]
copyItemAtPath:[filePath stringByExpandingTildeInPath]
@@ -91,7 +93,13 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist";
URLByAppendingPathComponent:[self trashedLicenseFilename]]
error:&error];
- if (!moved) {
+ if (
+ !moved &&
+ !(
+ [error code] == NSFileNoSuchFileError &&
+ [error domain] == NSCocoaErrorDomain
+ )
+ ) {
eprintf("%s\n", [[error localizedDescription] UTF8String]);
}
}