From bcfbf591eb584c3b70f8e776057d52954c09bea3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 27 Oct 2018 02:22:55 +0200 Subject: 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. --- DomeKey/LicenseHandler.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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]); } } -- cgit v1.2.3