Skip to content

Commit 66d4897

Browse files
committed
Fix: Check if the file is written to disk when extracting using 7zip
1 parent 161540e commit 66d4897

2 files changed

Lines changed: 56 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2626
- Option to ignore files and folders that match Regex or File pattern [`670bced`](https://github.com/ollm/OpenComic/commit/670bced3ed7413145119b401f974e15ea482ddf5)
2727
- Authentication support for OPDS (Basic and Digest) [`11c3aa8`](https://github.com/ollm/OpenComic/commit/11c3aa88efbff8adcc3fabbf4b066dcb7120b10a)
2828
- Use safeStorage for passwords and tokens [`6178ded`](https://github.com/ollm/OpenComic/commit/6178dedf1afe13c56b68bd3bd68010d80d30fdc6)
29-
- Change extraction of rar and tar to 7z to improve performance [`c0c2d6d`](https://github.com/ollm/OpenComic/commit/c0c2d6d61016241e70d4ee475e8d19567b8e71db)
29+
- Change extraction of `RAR` and `TAR` to 7zip to improve performance [`c0c2d6d`](https://github.com/ollm/OpenComic/commit/c0c2d6d61016241e70d4ee475e8d19567b8e71db)
3030
- Add suport for compressed `LZH`, `ACE`, `TAR.GZ`, `TAR.XZ`, `TAR.BZIP2` and `TAR.ZSTD` [`e7e7815`](https://github.com/ollm/OpenComic/commit/e7e7815d7a841c02354f9b5219fcdf348c10543b)
31-
- Support compressed files with password
31+
- Support compressed files with password [`9a6ef8e`](https://github.com/ollm/OpenComic/commit/9a6ef8e0a363e72e98634e827c50189bb2841047)
3232

3333
##### 🐛 Bug Fixes
3434

@@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4040
- Stuttering when decode big images (From sync decode to async when possible) [`d320aad`](https://github.com/ollm/OpenComic/commit/d320aad1d95e886d531dcab5721dc44c125cf028)
4141
- Move zoom using cursor after turning a pages not working property [`3012715`](https://github.com/ollm/OpenComic/commit/30127150751b1de611f95069e748eab68fcd2f51)
4242
- Turn page forward in manga mode (Only on non-arrow keys) [`bdbc0dc`](https://github.com/ollm/OpenComic/commit/bdbc0dc31ab37bdfcef570bf8f2130e39c08861e)
43+
- Check if the file is written to disk when extracting using 7zip
4344

4445
## [v1.4.1](https://github.com/ollm/OpenComic/releases/tag/v1.4.1) (08-02-2025)
4546

scripts/file-manager.js

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ var file = function(path, _config = false) {
221221
if(json.error && !this.config.fromThumbnailsGeneration && !this.config.subtask)
222222
dom.compressedError({message: json.error}, false, sha1(this.path));
223223

224+
setFileSizes(path, json.files);
225+
224226
return json.files;
225227
}
226228

@@ -244,6 +246,8 @@ var file = function(path, _config = false) {
244246
if(!json || json.mtime != mtime)
245247
cache.writeJson(compressed.cacheFile, {mtime: mtime, files: files, metadata: metadata});
246248

249+
setFileSizes(path, files);
250+
247251
return files;
248252

249253
}
@@ -1516,7 +1520,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
15161520
name: key,
15171521
path: file.path,
15181522
folder: file.folder ? true : false,
1519-
size: file.size || 0,
1523+
fileSize: file.fileSize || 0,
15201524
compressed: this.isCompressed(file.name),
15211525
};
15221526

@@ -1533,7 +1537,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
15331537
name: key,
15341538
path: p.join(this.path, _name),
15351539
folder: true,
1536-
size: 0,
1540+
fileSize: 0,
15371541
files: this._filesToMultidimension(files, value, _name),
15381542
});
15391543
}
@@ -1671,15 +1675,20 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
16711675

16721676
}
16731677

1674-
this.fixCorruptedName = function(name, pos = 0) {
1678+
this.isFullyWrittenToDisk = async function(path, realPath, intent = 0) {
1679+
1680+
const fileSize = fileSizes.get(path) ?? 0;
1681+
const stat = await fsp.stat(realPath);
1682+
const diskSize = stat.size;
16751683

1676-
if(//.test(name))
1684+
if(intent < 6 && (diskSize !== fileSize || (intent === 0 && diskSize === 0))) // Not fully written to disk, try again in 5 milliseconds
16771685
{
1678-
let ext = p.extname(name);
1679-
return pos+' - '+sha1(name)+(ext ? '.'+ext : '');
1686+
await app.sleep(5);
1687+
1688+
return this.isFullyWrittenToDisk(path, realPath, intent + 1);
16801689
}
16811690

1682-
return name;
1691+
return true;
16831692

16841693
}
16851694

@@ -1722,7 +1731,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
17221731
{
17231732
let name = _this.removeTmp(p.normalize(data.file));
17241733

1725-
files.push({name: name, path: p.join(_this.path, name), size: data.size});
1734+
files.push({name: name, path: p.join(_this.path, name), fileSize: data.size});
17261735
_this.setFileStatus(name, {extracted: false});
17271736

17281737
readSome = true;
@@ -1775,20 +1784,24 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
17751784

17761785
result = await new Promise(function(resolve, reject) {
17771786

1778-
_7z.on('data', function(data) {
1787+
_7z.on('data', async function(data) {
17791788

1780-
let extract = data.status == 'extracted' ? true : false;
1789+
const extract = data.status == 'extracted' ? true : false;
17811790

17821791
if(extract)
17831792
{
1784-
let name = _this.removeTmp(p.normalize(data.file));
1793+
_this.setProgress(_this.progressIndex++ / onlyLen);
1794+
1795+
const name = _this.removeTmp(p.normalize(data.file));
1796+
const path = p.join(_this.path, name);
1797+
const realPath = p.join(_this.tmp, name);
1798+
1799+
await _this.isFullyWrittenToDisk(path, realPath);
17851800

17861801
_this.setFileStatus(name, {extracted: extract});
1787-
_this.whenExtractFile(p.join(_this.path, name));
1802+
_this.whenExtractFile(path);
17881803

17891804
extractedSome = true;
1790-
1791-
_this.setProgress(_this.progressIndex++ / onlyLen);
17921805
}
17931806

17941807
}).on('progress', function(progress) {
@@ -2284,6 +2297,31 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
22842297

22852298
}
22862299

2300+
var fileSizes = new Map();
2301+
var fileSizesInMap = new Set();
2302+
2303+
function _setFileSizes(files)
2304+
{
2305+
for(let i = 0, len = files.length; i < len; i++)
2306+
{
2307+
const file = files[i];
2308+
2309+
if(file.files)
2310+
_setFileSizes(file.files);
2311+
else if(file.fileSize)
2312+
fileSizes.set(file.path, file.fileSize);
2313+
}
2314+
}
2315+
2316+
function setFileSizes(path, files)
2317+
{
2318+
if(fileSizesInMap.has(path))
2319+
return;
2320+
2321+
fileSizesInMap.add(path);
2322+
_setFileSizes(files);
2323+
}
2324+
22872325
var extractingPromises = {};
22882326
var extractingPromisesST = {};
22892327

@@ -3229,6 +3267,7 @@ module.exports = {
32293267
getBlob: getBlob,
32303268
revokeObjectURL: revokeObjectURL,
32313269
revokeAllObjectURL: revokeAllObjectURL,
3270+
fileSizes: function(){return fileSizes},
32323271
requestFileAccess: requestFileAccess,
32333272
filePassword: filePassword,
32343273
}

0 commit comments

Comments
 (0)