diff options
author | Teddy Wing | 2018-10-26 19:22:28 +0200 |
---|---|---|
committer | Teddy Wing | 2018-10-26 19:28:45 +0200 |
commit | 3ec24a789a299461c53e27492624d10d414f4010 (patch) | |
tree | 34456baaec863d6f6db8b22f909b6ae16664f3cd | |
parent | 4957da593c8a3b0cc81b3f122e4f8b93c8de46b3 (diff) | |
download | DomeKey-3ec24a789a299461c53e27492624d10d414f4010.tar.bz2 |
LicenseHandler: Use current date string in file moved to trash
To prevent errors resulting from trying to move the license file to the
trash when a file with the same name already exists there, use a custom
file name with a time stamp.
Instead of naming the trashed file "license.plist", prepend "dome-key-"
to the filename to make it clear to users that the file came from
DomeKey. Append the current date in the format "2018-10-26-19.28.13"
before the file extension.
-rw-r--r-- | DomeKey/LicenseHandler.m | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/DomeKey/LicenseHandler.m b/DomeKey/LicenseHandler.m index 576e255..780efef 100644 --- a/DomeKey/LicenseHandler.m +++ b/DomeKey/LicenseHandler.m @@ -75,7 +75,8 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist"; BOOL moved = [[NSFileManager defaultManager] moveItemAtURL:[self licensePath] - toURL:trash_url + toURL:[trash_url + URLByAppendingPathComponent:[self trashedLicenseFilename]] error:&error]; if (!moved) { @@ -89,6 +90,17 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist"; // If license does validate, print a success message } ++ (NSString *)trashedLicenseFilename +{ + NSDate *now = [NSDate date]; + NSDateFormatter *date_formatter = [[NSDateFormatter alloc] init]; + [date_formatter setDateFormat:@"yyyy-MM-dd-HH.mm.ss"]; + NSString *date_string = [date_formatter stringFromDate:now]; + return [NSString + stringWithFormat:@"dome-key-license-%@.plist", + date_string]; +} + + (NSURL *)licensePath { return [[XDG domeKeyDataPath] |