Skip to content

Commit 98de350

Browse files
authored
Fix: Avoid extracting the same file multiple times at the same time
1 parent eea0b7c commit 98de350

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

scripts/file-manager.js

+65-3
Original file line numberDiff line numberDiff line change
@@ -1449,10 +1449,24 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
14491449

14501450
for(let path in this.config.only)
14511451
{
1452+
const _path = p.join(this.path, path);
1453+
const globalExtracting = getGlobalExtracting(_path);
1454+
1455+
if(globalExtracting || fs.existsSync(p.join(this.tmp, path)))
1456+
{
1457+
if(globalExtracting) await globalExtracting.promise;
1458+
this.whenExtractFile(_path);
1459+
}
1460+
else
1461+
{
1462+
setGlobalExtracting(_path);
1463+
only.push(path);
1464+
}
1465+
14521466
if(!fs.existsSync(p.join(this.tmp, path)))
14531467
only.push(path);
14541468
else
1455-
this.whenExtractFile(p.join(this.path, path));
1469+
this.whenExtractFile(_path);
14561470
}
14571471

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

1478-
if(fs.existsSync(p.join(this.tmp, file.pathInCompressed)))
1492+
const _path = p.join(this.path, file.pathInCompressed);
1493+
const globalExtracting = getGlobalExtracting(_path);
1494+
1495+
if(globalExtracting || fs.existsSync(p.join(this.tmp, file.pathInCompressed)))
14791496
{
1480-
this.whenExtractFile(p.join(this.path, file.pathInCompressed));
1497+
if(globalExtracting) await globalExtracting.promise;
1498+
this.whenExtractFile(_path);
14811499
someIsExtracted = true;
14821500
}
14831501
else
14841502
{
1503+
setGlobalExtracting(_path);
14851504
only.push(file.pathInCompressed);
14861505
}
14871506
}
@@ -1700,6 +1719,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
17001719
compressed: this.isCompressed(name),
17011720
};
17021721

1722+
globalWhenExtractFile(path);
17031723
this.callbackWhenFileExtracted(file);
17041724
}
17051725

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

27202740
}
27212741

2742+
var extractingPromises = {};
2743+
var extractingPromisesST = {};
2744+
2745+
function setGlobalExtracting(path)
2746+
{
2747+
extractingPromisesST[path] = setTimeout(function(){
2748+
2749+
globalWhenExtractFile(path);
2750+
2751+
}, 60000);
2752+
2753+
let _resolve = false;
2754+
2755+
extractingPromises[path] = {
2756+
promise: new Promise(async function(resolve, reject) {
2757+
2758+
_resolve = resolve;
2759+
2760+
}),
2761+
resolve: false,
2762+
};
2763+
2764+
extractingPromises[path].resolve = _resolve;
2765+
}
2766+
2767+
function getGlobalExtracting(path)
2768+
{
2769+
return extractingPromises[path] || false;
2770+
}
2771+
2772+
function globalWhenExtractFile(path)
2773+
{
2774+
if(extractingPromisesST[path]) clearTimeout(extractingPromisesST[path]);
2775+
2776+
if(extractingPromises[path])
2777+
{
2778+
const globalExtracting = extractingPromises[path];
2779+
delete extractingPromises[path];
2780+
globalExtracting.resolve();
2781+
}
2782+
}
2783+
27222784
// Use this to remove generated vector images if window.devicePixelRatio is changed
27232785
async function removeTmpVector()
27242786
{

0 commit comments

Comments
 (0)