Skip to content

Commit 061827f

Browse files
authored
Fix: Extracting 7z in separate stacks to avoid errors when extracting many files
1 parent 244ff38 commit 061827f

File tree

3 files changed

+82
-36
lines changed

3 files changed

+82
-36
lines changed

scripts/file-manager.js

+71-33
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,26 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
16791679

16801680
}
16811681

1682+
this.stackOnlyInTasks = function(only, stackSize = 500) {
1683+
1684+
const tasks = [];
1685+
1686+
if(only)
1687+
{
1688+
for(let i = 0, len = Math.ceil(only.length / stackSize); i < len; i++)
1689+
{
1690+
tasks.push(only.slice(i * stackSize, i * stackSize + stackSize));
1691+
}
1692+
1693+
return tasks;
1694+
}
1695+
else
1696+
{
1697+
return [only];
1698+
}
1699+
1700+
}
1701+
16821702
this.fixCorruptedName = function(name, pos = 0) {
16831703

16841704
if(//.test(name))
@@ -1918,58 +1938,76 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
19181938
let only = this.config.only;
19191939
let _this = this;
19201940

1921-
let _7z = await this.open7z(true, this.config._only || false);
1922-
let extractedSome = false;
1941+
const onlyLen = this.config._only ? this.config._only.length : false;
1942+
const tasks = this.stackOnlyInTasks(this.config._only || false, 500);
19231943

1924-
return new Promise(function(resolve, reject) {
1944+
let result = false;
1945+
let error = false;
19251946

1926-
_7z.on('data', function(data) {
1947+
this.progressIndex = 1;
19271948

1928-
let extract = data.status == 'extracted' ? true : false;
1949+
for(let i = 0, len = tasks.length; i < len; i++)
1950+
{
1951+
const onlyStack = tasks[i];
19291952

1930-
if(extract)
1931-
{
1932-
let name = _this.removeTmp(p.normalize(data.file));
1953+
const _7z = await this.open7z(true, onlyStack);
1954+
let extractedSome = false;
19331955

1934-
_this.setFileStatus(name, {extracted: extract});
1935-
_this.whenExtractFile(p.join(_this.path, name));
1956+
result = await new Promise(function(resolve, reject) {
19361957

1937-
extractedSome = true;
1938-
}
1958+
_7z.on('data', function(data) {
19391959

1940-
}).on('progress', function(progress) {
1960+
let extract = data.status == 'extracted' ? true : false;
19411961

1942-
_this.setProgress(progress.percent / 100);
1962+
if(extract)
1963+
{
1964+
let name = _this.removeTmp(p.normalize(data.file));
19431965

1944-
}).on('end', function(data) {
1966+
_this.setFileStatus(name, {extracted: extract});
1967+
_this.whenExtractFile(p.join(_this.path, name));
19451968

1946-
console.timeEnd('extract7z: '+_this.path);
1969+
extractedSome = true;
19471970

1948-
_this.setProgress(1);
1971+
_this.setProgress(_this.progressIndex++ / onlyLen);
1972+
}
19491973

1950-
console.log('extract7z end: '+_this.path);
1974+
}).on('progress', function(progress) {
19511975

1952-
resolve();
1976+
if(!onlyLen)
1977+
_this.setProgress(progress.percent / 100);
19531978

1954-
}).on('error', function(error) {
1979+
}).on('end', function(data) {
19551980

1956-
if(extractedSome)
1957-
{
1958-
/*_this.setProgress(1);
1959-
resolve();*/
1981+
resolve();
19601982

1961-
_this.saveErrorToCache(error);
1962-
dom.compressedError(error, false, sha1(_this.path));
1963-
}
1964-
else
1965-
{
1966-
resolve(_this.extractIfTypeFromBinaryIsDifferent(error));
1967-
}
1983+
}).on('error', function(error) {
1984+
1985+
if(extractedSome)
1986+
{
1987+
/*_this.setProgress(1);
1988+
resolve();*/
1989+
1990+
_this.saveErrorToCache(error);
1991+
dom.compressedError(error, false, sha1(_this.path));
1992+
}
1993+
else
1994+
{
1995+
error = true;
1996+
resolve(_this.extractIfTypeFromBinaryIsDifferent(error));
1997+
}
1998+
1999+
});
19682000

19692001
});
19702002

1971-
});
1972-
2003+
if(error) return result;
2004+
}
2005+
2006+
this.setProgress(1);
2007+
2008+
console.timeEnd('extract7z: '+_this.path);
2009+
2010+
return result;
19732011
}
19742012

19752013

templates/reading.content.left.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
{{#if folder}}
55
<i class="material-icon">folder</i>
66
{{else}}
7-
<img class="reading-images sha-image-{{sha}}{{#if thumbnail}} show{{/if}}" src="{{chain 'escapeBackSlash' 'escapeQuotesSimples' thumbnail}}" onload="this.classList.add('show')">
7+
<div class="reading-images">
8+
<img class="sha-image-{{sha}}{{#if thumbnail}} show{{/if}}" src="{{chain 'escapeBackSlash' 'escapeQuotesSimples' thumbnail}}" onload="this.classList.add('show')">
9+
</div>
810
{{/if}}
911
</div>
1012
{{/each}}

themes/material-design/reading.css

+8-2
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,23 @@
9797
.reading-images
9898
{
9999
width: 80px;
100+
margin-left: calc(100% - 80px);
101+
text-align: center;
102+
}
103+
104+
.reading-images > *
105+
{
106+
max-width: 80px;
100107
border-radius: 7px;
101108
background-size: 100%;
102109
background-repeat: no-repeat;
103110
background-position: 50%;
104-
margin-left: calc(100% - 80px);
105111
border: 1px solid var(--md-sys-color-surface-variant);
106112
transition: 0.2s border;
107113
opacity: 0;
108114
}
109115

110-
.reading-images.show
116+
.reading-images > *.show
111117
{
112118
opacity: 1;
113119
}

0 commit comments

Comments
 (0)