aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-10-26 19:22:28 +0200
committerTeddy Wing2018-10-26 19:28:45 +0200
commit3ec24a789a299461c53e27492624d10d414f4010 (patch)
tree34456baaec863d6f6db8b22f909b6ae16664f3cd
parent4957da593c8a3b0cc81b3f122e4f8b93c8de46b3 (diff)
downloadDomeKey-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.m14
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]