From 3ec24a789a299461c53e27492624d10d414f4010 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 26 Oct 2018 19:22:28 +0200 Subject: 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. --- DomeKey/LicenseHandler.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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] -- cgit v1.2.3