Skip to content

Commit

Permalink
Fix: Avoid extracting the same file multiple times at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm authored Sep 25, 2024
1 parent eea0b7c commit 98de350
Showing 1 changed file with 65 additions and 3 deletions.
68 changes: 65 additions & 3 deletions scripts/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,10 +1449,24 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix

for(let path in this.config.only)
{
const _path = p.join(this.path, path);
const globalExtracting = getGlobalExtracting(_path);

if(globalExtracting || fs.existsSync(p.join(this.tmp, path)))
{
if(globalExtracting) await globalExtracting.promise;
this.whenExtractFile(_path);
}
else
{
setGlobalExtracting(_path);
only.push(path);
}

if(!fs.existsSync(p.join(this.tmp, path)))
only.push(path);
else
this.whenExtractFile(p.join(this.path, path));
this.whenExtractFile(_path);
}

if(!only.length)
Expand All @@ -1475,13 +1489,18 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
{
let file = files[i];

if(fs.existsSync(p.join(this.tmp, file.pathInCompressed)))
const _path = p.join(this.path, file.pathInCompressed);
const globalExtracting = getGlobalExtracting(_path);

if(globalExtracting || fs.existsSync(p.join(this.tmp, file.pathInCompressed)))
{
this.whenExtractFile(p.join(this.path, file.pathInCompressed));
if(globalExtracting) await globalExtracting.promise;
this.whenExtractFile(_path);
someIsExtracted = true;
}
else
{
setGlobalExtracting(_path);
only.push(file.pathInCompressed);
}
}
Expand Down Expand Up @@ -1700,6 +1719,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
compressed: this.isCompressed(name),
};

globalWhenExtractFile(path);
this.callbackWhenFileExtracted(file);
}

Expand Down Expand Up @@ -2719,6 +2739,48 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix

}

var extractingPromises = {};
var extractingPromisesST = {};

function setGlobalExtracting(path)
{
extractingPromisesST[path] = setTimeout(function(){

globalWhenExtractFile(path);

}, 60000);

let _resolve = false;

extractingPromises[path] = {
promise: new Promise(async function(resolve, reject) {

_resolve = resolve;

}),
resolve: false,
};

extractingPromises[path].resolve = _resolve;
}

function getGlobalExtracting(path)
{
return extractingPromises[path] || false;
}

function globalWhenExtractFile(path)
{
if(extractingPromisesST[path]) clearTimeout(extractingPromisesST[path]);

if(extractingPromises[path])
{
const globalExtracting = extractingPromises[path];
delete extractingPromises[path];
globalExtracting.resolve();
}
}

// Use this to remove generated vector images if window.devicePixelRatio is changed
async function removeTmpVector()
{
Expand Down

0 comments on commit 98de350

Please sign in to comment.