Repository navigation
fix: reject zip.compressDir when a file cannot be read #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,20 @@ describe('test/zip/index.test.js', () => { | |
| assert(fs.existsSync(destFile)); | ||
| }); | ||
|
|
||
| it('zip.compressDir(dir, destFile) should reject when a file cannot be read', async () => { | ||
| if (isWindows || process.getuid() === 0) return; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Report unsupported runs as skipped. On Windows or when running as root, the test returns normally and Mocha reports it as passed without checking error forwarding. Use a function callback and
|
||
| const sourceDir = path.join(os.tmpdir(), randomUUID()); | ||
| fs.mkdirSync(sourceDir); | ||
| fs.writeFileSync(path.join(sourceDir, 'locked.txt'), 'locked'); | ||
| fs.chmodSync(path.join(sourceDir, 'locked.txt'), 0o000); | ||
|
Comment on lines
+116
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the temporary source directory. Each non-root Unix run leaves
|
||
| destDir = path.join(os.tmpdir(), randomUUID()); | ||
| fs.mkdirSync(destDir, { recursive: true }); | ||
| await assert.rejects( | ||
| compressing.zip.compressDir(sourceDir, path.join(destDir, 'out.zip')), | ||
| { code: 'EACCES' } | ||
| ); | ||
| }); | ||
|
|
||
| it('zip.compressDir(dir, destStream, { ignoreBase: true })', async () => { | ||
| const sourceDir = path.join(__dirname, '..', 'fixtures'); | ||
| destDir = path.join(os.tmpdir(), randomUUID()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cancel active inputs when forwarding a ZipFile error.
If a long-running stream entry is active and a later file disappears between the two stat calls, yazl emits an error for the file. The outer pipeline fails, but the active input can continue to be read and compressed because it is not part of that pipeline. This can retain resources after the caller receives the error. Cancel active inputs and internal streams when the archive fails. (raw.githubusercontent.com)