[mob][config] Skip deleting temp encrypted files for upload
This commit is contained in:
parent
588bf74202
commit
2de5b641a7
|
@ -103,20 +103,7 @@ class Configuration {
|
||||||
_documentsDirectory = (await getApplicationDocumentsDirectory()).path;
|
_documentsDirectory = (await getApplicationDocumentsDirectory()).path;
|
||||||
_tempDocumentsDirPath = _documentsDirectory + "/temp/";
|
_tempDocumentsDirPath = _documentsDirectory + "/temp/";
|
||||||
final tempDocumentsDir = Directory(_tempDocumentsDirPath);
|
final tempDocumentsDir = Directory(_tempDocumentsDirPath);
|
||||||
try {
|
await _cleanUpStaleFiles(tempDocumentsDir);
|
||||||
final currentTime = DateTime.now().microsecondsSinceEpoch;
|
|
||||||
if (tempDocumentsDir.existsSync() &&
|
|
||||||
(_preferences.getInt(lastTempFolderClearTimeKey) ?? 0) <
|
|
||||||
(currentTime - kTempFolderDeletionTimeBuffer)) {
|
|
||||||
await tempDocumentsDir.delete(recursive: true);
|
|
||||||
await _preferences.setInt(lastTempFolderClearTimeKey, currentTime);
|
|
||||||
_logger.info("Cleared temp folder");
|
|
||||||
} else {
|
|
||||||
_logger.info("Skipping temp folder clear");
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
_logger.warning(e);
|
|
||||||
}
|
|
||||||
tempDocumentsDir.createSync(recursive: true);
|
tempDocumentsDir.createSync(recursive: true);
|
||||||
final tempDirectoryPath = (await getTemporaryDirectory()).path;
|
final tempDirectoryPath = (await getTemporaryDirectory()).path;
|
||||||
_thumbnailCacheDirectory = tempDirectoryPath + "/thumbnail-cache";
|
_thumbnailCacheDirectory = tempDirectoryPath + "/thumbnail-cache";
|
||||||
|
@ -144,6 +131,40 @@ class Configuration {
|
||||||
SuperLogging.setUserID(await _getOrCreateAnonymousUserID()).ignore();
|
SuperLogging.setUserID(await _getOrCreateAnonymousUserID()).ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _cleanUpStaleFiles deletes all files in the temp directory that are older
|
||||||
|
// than kTempFolderDeletionTimeBuffer except the the temp encrypted files for upload.
|
||||||
|
// Those file are deleted by file uploader after the upload is complete or those
|
||||||
|
// files are not being used / tracked.
|
||||||
|
Future<void> _cleanUpStaleFiles(Directory tempDocumentsDir) async {
|
||||||
|
try {
|
||||||
|
final currentTime = DateTime.now().microsecondsSinceEpoch;
|
||||||
|
if (tempDocumentsDir.existsSync() &&
|
||||||
|
(_preferences.getInt(lastTempFolderClearTimeKey) ?? 0) <
|
||||||
|
(currentTime - kTempFolderDeletionTimeBuffer)) {
|
||||||
|
// list all files in the temp directory
|
||||||
|
final files = tempDocumentsDir.listSync();
|
||||||
|
for (final file in files) {
|
||||||
|
if (file is File) {
|
||||||
|
if (file.path.contains(uploadTempFilePrefix)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_logger.info("Deleting file: ${file.path}");
|
||||||
|
await file.delete();
|
||||||
|
} else if (file is Directory) {
|
||||||
|
await file.delete(recursive: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// await tempDocumentsDir.delete(recursive: true);
|
||||||
|
await _preferences.setInt(lastTempFolderClearTimeKey, currentTime);
|
||||||
|
_logger.info("Cleared temp folder");
|
||||||
|
} else {
|
||||||
|
_logger.info("Skipping temp folder clear");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
_logger.warning(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> logout({bool autoLogout = false}) async {
|
Future<void> logout({bool autoLogout = false}) async {
|
||||||
if (SyncService.instance.isSyncInProgress()) {
|
if (SyncService.instance.isSyncInProgress()) {
|
||||||
SyncService.instance.stopSync();
|
SyncService.instance.stopSync();
|
||||||
|
|
Loading…
Reference in a new issue