mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Handle stored dates that are in the future (#2914)
This is a correctness fix for system profile submission checking, periodic cache cleanup, and failed signed feed expiration check.
This commit is contained in:
3 files changed
+40
-22
No files matched your search
Vendored
+21
-18
@@ -58,28 +58,31 @@ static NSTimeInterval OLD_ITEM_DELETION_INTERVAL = 86400 * 10; // 10 days
|
||||
{
|
||||
NSMutableArray<NSString *> *filePathsToRemove = [NSMutableArray array];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if ([fileManager fileExistsAtPath:directory]) {
|
||||
NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:directory];
|
||||
NSDate *currentDate = [NSDate date];
|
||||
for (NSString *filename in directoryEnumerator)
|
||||
{
|
||||
NSDictionary<NSString *, id> *fileAttributes = [fileManager attributesOfItemAtPath:[directory stringByAppendingPathComponent:filename] error:NULL];
|
||||
if (fileAttributes != nil)
|
||||
{
|
||||
NSDate *lastModificationDate = [fileAttributes objectForKey:NSFileModificationDate];
|
||||
if ([currentDate timeIntervalSinceDate:lastModificationDate] >= OLD_ITEM_DELETION_INTERVAL)
|
||||
{
|
||||
[filePathsToRemove addObject:[directory stringByAppendingPathComponent:filename]];
|
||||
|
||||
NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:directory];
|
||||
NSDate *currentDate = [NSDate date];
|
||||
for (NSString *filename in directoryEnumerator) {
|
||||
NSString *filePath = [directory stringByAppendingPathComponent:filename];
|
||||
NSDictionary<NSString *, id> *fileAttributes = [fileManager attributesOfItemAtPath:filePath error:NULL];
|
||||
if (fileAttributes != nil) {
|
||||
NSDate *lastModificationDate = [fileAttributes objectForKey:NSFileModificationDate];
|
||||
NSTimeInterval timeIntervalSinceLastModificationDate = [currentDate timeIntervalSinceDate:lastModificationDate];
|
||||
if (timeIntervalSinceLastModificationDate >= OLD_ITEM_DELETION_INTERVAL) {
|
||||
[filePathsToRemove addObject:[directory stringByAppendingPathComponent:filename]];
|
||||
} else if (timeIntervalSinceLastModificationDate < 0) {
|
||||
// Reset the modification date if it's far out in the future
|
||||
NSError *resetModificationDateError = nil;
|
||||
if (![fileManager setAttributes:@{NSFileModificationDate: currentDate} ofItemAtPath:filePath error:&resetModificationDateError]) {
|
||||
SULog(SULogLevelError, @"Failed to reset modification date of file modified in future: %@", resetModificationDateError.localizedDescription);
|
||||
}
|
||||
}
|
||||
|
||||
[directoryEnumerator skipDescendants];
|
||||
}
|
||||
|
||||
for (NSString *filename in filePathsToRemove)
|
||||
{
|
||||
[fileManager removeItemAtPath:filename error:NULL];
|
||||
}
|
||||
[directoryEnumerator skipDescendants];
|
||||
}
|
||||
|
||||
for (NSString *filename in filePathsToRemove) {
|
||||
[fileManager removeItemAtPath:filename error:NULL];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+10
-3
@@ -1249,14 +1249,21 @@ static NSString *escapeURLComponent(NSString *str) {
|
||||
BOOL sendingSystemProfile = [self sendsSystemProfile];
|
||||
|
||||
// Let's only send the system profiling information once per week at most, so we normalize daily-checkers vs. biweekly-checkers and the such.
|
||||
NSDate *currentDate = [NSDate date];
|
||||
if (sendingSystemProfile) {
|
||||
NSDate *lastSubmitDate = [_host objectForUserDefaultsKey:SULastProfileSubmitDateKey ofClass:NSDate.class];
|
||||
if (!lastSubmitDate) {
|
||||
lastSubmitDate = [NSDate distantPast];
|
||||
}
|
||||
const NSTimeInterval oneWeek = 60 * 60 * 24 * 7;
|
||||
NSTimeInterval timeSinceLastSubmission = [lastSubmitDate timeIntervalSinceNow] * -1;
|
||||
if (timeSinceLastSubmission < oneWeek) {
|
||||
|
||||
NSTimeInterval timeSinceLastSubmission = [currentDate timeIntervalSinceDate:lastSubmitDate];
|
||||
|
||||
if (timeSinceLastSubmission < 0) {
|
||||
// Ignore dates far out in the future
|
||||
sendingSystemProfile = NO;
|
||||
[_host setObject:currentDate forUserDefaultsKey:SULastProfileSubmitDateKey];
|
||||
} else if (timeSinceLastSubmission < oneWeek) {
|
||||
sendingSystemProfile = NO;
|
||||
}
|
||||
}
|
||||
@@ -1272,7 +1279,7 @@ static NSString *escapeURLComponent(NSString *str) {
|
||||
if (sendingSystemProfile)
|
||||
{
|
||||
parameters = [parameters arrayByAddingObjectsFromArray:[self systemProfileArray]];
|
||||
[_host setObject:[NSDate date] forUserDefaultsKey:SULastProfileSubmitDateKey];
|
||||
[_host setObject:currentDate forUserDefaultsKey:SULastProfileSubmitDateKey];
|
||||
}
|
||||
if ([parameters count] == 0) { return baseFeedURL; }
|
||||
|
||||
|
||||
Vendored
+9
-1
@@ -171,7 +171,15 @@
|
||||
[hostForFailedSigningValidationDate setObject:currentDate forUserDefaultsKey:initialFailedFeedSigningValidationDateKey];
|
||||
canRecoverFromSigningValidationFailure = NO;
|
||||
} else {
|
||||
canRecoverFromSigningValidationFailure = ([currentDate timeIntervalSinceDate:firstFailedSigningValidationDate] >= failureExpirationInterval);
|
||||
NSTimeInterval timeIntervalSinceFirstFailedValidationDate = [currentDate timeIntervalSinceDate:firstFailedSigningValidationDate];
|
||||
|
||||
if (timeIntervalSinceFirstFailedValidationDate < 0) {
|
||||
// Record first signing validation date if stored date is far out in future
|
||||
[hostForFailedSigningValidationDate setObject:currentDate forUserDefaultsKey:initialFailedFeedSigningValidationDateKey];
|
||||
canRecoverFromSigningValidationFailure = NO;
|
||||
} else {
|
||||
canRecoverFromSigningValidationFailure = (timeIntervalSinceFirstFailedValidationDate >= failureExpirationInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user