|
@@ -135,6 +135,12 @@ static NSString *const kTrashDirectoryName = @"trash";
|
|
|
return [self _dbExecute:sql];
|
|
|
}
|
|
|
|
|
|
+- (void)_dbCheckpoint {
|
|
|
+ if (![self _dbIsReady]) return;
|
|
|
+ // Cause a checkpoint to occur, merge `sqlite-wal` file to `sqlite` file.
|
|
|
+ sqlite3_wal_checkpoint(_db, NULL);
|
|
|
+}
|
|
|
+
|
|
|
- (BOOL)_dbExecute:(NSString *)sql {
|
|
|
if (sql.length == 0) return NO;
|
|
|
if (![self _dbIsReady]) return NO;
|
|
@@ -777,7 +783,10 @@ static NSString *const kTrashDirectoryName = @"trash";
|
|
|
|
|
|
switch (_type) {
|
|
|
case YYKVStorageTypeSQLite: {
|
|
|
- return [self _dbDeleteItemsWithSizeLargerThan:size];
|
|
|
+ if ([self _dbDeleteItemsWithSizeLargerThan:size]) {
|
|
|
+ [self _dbCheckpoint];
|
|
|
+ return YES;
|
|
|
+ }
|
|
|
} break;
|
|
|
case YYKVStorageTypeFile:
|
|
|
case YYKVStorageTypeMixed: {
|
|
@@ -785,7 +794,10 @@ static NSString *const kTrashDirectoryName = @"trash";
|
|
|
for (NSString *name in filenames) {
|
|
|
[self _fileDeleteWithName:name];
|
|
|
}
|
|
|
- return [self _dbDeleteItemsWithSizeLargerThan:size];
|
|
|
+ if ([self _dbDeleteItemsWithSizeLargerThan:size]) {
|
|
|
+ [self _dbCheckpoint];
|
|
|
+ return YES;
|
|
|
+ }
|
|
|
} break;
|
|
|
}
|
|
|
return NO;
|
|
@@ -797,7 +809,10 @@ static NSString *const kTrashDirectoryName = @"trash";
|
|
|
|
|
|
switch (_type) {
|
|
|
case YYKVStorageTypeSQLite: {
|
|
|
- return [self _dbDeleteItemsWithTimeEarlierThan:time];
|
|
|
+ if ([self _dbDeleteItemsWithTimeEarlierThan:time]) {
|
|
|
+ [self _dbCheckpoint];
|
|
|
+ return YES;
|
|
|
+ }
|
|
|
} break;
|
|
|
case YYKVStorageTypeFile:
|
|
|
case YYKVStorageTypeMixed: {
|
|
@@ -805,7 +820,10 @@ static NSString *const kTrashDirectoryName = @"trash";
|
|
|
for (NSString *name in filenames) {
|
|
|
[self _fileDeleteWithName:name];
|
|
|
}
|
|
|
- return [self _dbDeleteItemsWithTimeEarlierThan:time];
|
|
|
+ if ([self _dbDeleteItemsWithTimeEarlierThan:time]) {
|
|
|
+ [self _dbCheckpoint];
|
|
|
+ return NO;
|
|
|
+ }
|
|
|
} break;
|
|
|
}
|
|
|
return NO;
|
|
@@ -837,6 +855,7 @@ static NSString *const kTrashDirectoryName = @"trash";
|
|
|
if (!suc) break;
|
|
|
}
|
|
|
} while (total > maxSize && items.count > 0 && suc);
|
|
|
+ if (suc) [self _dbCheckpoint];
|
|
|
return suc;
|
|
|
}
|
|
|
|
|
@@ -866,6 +885,7 @@ static NSString *const kTrashDirectoryName = @"trash";
|
|
|
if (!suc) break;
|
|
|
}
|
|
|
} while (total > maxCount && items.count > 0 && suc);
|
|
|
+ if (suc) [self _dbCheckpoint];
|
|
|
return suc;
|
|
|
}
|
|
|
|
|
@@ -904,6 +924,7 @@ static NSString *const kTrashDirectoryName = @"trash";
|
|
|
}
|
|
|
if (progress) progress(total - left, total);
|
|
|
} while (left > 0 && items.count > 0 && suc);
|
|
|
+ if (suc) [self _dbCheckpoint];
|
|
|
if (end) end(!suc);
|
|
|
}
|
|
|
}
|