diff options
author | Teddy Wing | 2018-10-27 02:22:55 +0200 |
---|---|---|
committer | Teddy Wing | 2018-10-27 02:22:55 +0200 |
commit | bcfbf591eb584c3b70f8e776057d52954c09bea3 (patch) | |
tree | 1c4076a790b305aed30aa8c20f715a77e6fc4ae5 | |
parent | 6ceb56fac5dcabc02db6ebb373073593ddec9a33 (diff) | |
download | DomeKey-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.m | 10 |
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]); } } |