Remove invalid files from downloads list on startup (#2401)

This commit is contained in:
Tasos Boulis
2022-11-18 18:58:32 +02:00
committed by GitHub
parent 9ba36de30e
commit b4e21b5c5e
3 changed files with 59 additions and 2 deletions

View File

@@ -174,16 +174,25 @@ export class DownloadsManager extends JsonFileManager<DownloadedItems> {
for (const fileId in downloads) {
if (Object.prototype.hasOwnProperty.call(downloads, fileId)) {
const file = downloads[fileId];
if (this.isInvalidFile(file)) {
delete downloads[fileId];
modified = true;
continue;
}
// Remove update if app was updated and restarted
if (fileId === APP_UPDATE_KEY) {
if (appVersionManager.lastAppVersion === downloads[APP_UPDATE_KEY].filename) {
if (appVersionManager.lastAppVersion === file.filename) {
delete downloads[APP_UPDATE_KEY];
modified = true;
continue;
} else {
continue;
}
}
const file = downloads[fileId];
if (file.state === 'completed') {
if (!file.location || !fs.existsSync(file.location)) {
downloads[fileId].state = 'deleted';
@@ -632,6 +641,13 @@ export class DownloadsManager extends JsonFileManager<DownloadedItems> {
private isAppUpdate = (item: DownloadedItem): boolean => {
return item.type === DownloadItemTypeEnum.UPDATE;
};
private isInvalidFile(file: DownloadedItem) {
return (typeof file !== 'object') ||
!file.filename ||
!file.state ||
!file.type;
}
}
let downloadsManager = new DownloadsManager(downloadsJson);