Remove invalid files from downloads list on startup (#2401)
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user