Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fs: fix rmsync error swallowing
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkgoron committed May 16, 2021
1 parent d515441 commit 98ac82e
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 148 deletions.
4 changes: 2 additions & 2 deletions lib/internal/fs/rimraf.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function _unlinkSync(path, options) {
} else if (err.code === 'ENOENT') {
// The file is already gone.
return;
} else {
} else if (i === tries) {
throw err;
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ function _rmdirSync(path, options, originalErr) {
} else if (err.code === 'ENOENT') {
// The file is already gone.
return;
} else {
} else if (i === tries) {
throw err;
}
}
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-fs-mkdir-recursive-eaccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function makeDirectoryReadOnly(dir) {
let accessErrorCode = 'EACCES';
if (common.isWindows) {
accessErrorCode = 'EPERM';
execSync(`icacls ${dir} /inheritance:r`);
execSync(`icacls ${dir} /deny "everyone":W`);
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC,AD,WD)"`);
} else {
fs.chmodSync(dir, '444');
}
Expand All @@ -36,7 +35,7 @@ function makeDirectoryReadOnly(dir) {

function makeDirectoryWritable(dir) {
if (common.isWindows) {
execSync(`icacls ${dir} /grant "everyone":W`);
execSync(`icacls ${dir} /remove:d "everyone"`);
}
}

Expand Down
21 changes: 14 additions & 7 deletions test/parallel/test-fs-open-no-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ const debuglog = (arg) => {
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

{
fs.open(`${tmpdir.path}/dummy`, 'wx+', common.mustCall((err, fd) => {
debuglog('fs open() callback');
assert.ifError(err);
}));
debuglog('waiting for callback');
}
let openFd;

fs.open(`${tmpdir.path}/dummy`, 'wx+', common.mustCall((err, fd) => {
debuglog('fs open() callback');
assert.ifError(err);
openFd = fd;
}));
debuglog('waiting for callback');

process.on('beforeExit', common.mustCall(() => {
if (openFd) {
fs.closeSync(openFd);
}
}));
20 changes: 12 additions & 8 deletions test/parallel/test-fs-promises-file-handle-read-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ if (isMainThread || !workerData) {
});
});
fs.promises.open(file, 'r').then((handle) => {
fs.createReadStream(null, { fd: handle });
assert.throws(() => {
new Worker(__filename, {
workerData: { handle },
transferList: [handle]
try {
fs.createReadStream(null, { fd: handle });
assert.throws(() => {
new Worker(__filename, {
workerData: { handle },
transferList: [handle]
});
}, {
code: 25,
});
}, {
code: 25,
});
} finally {
return handle.close();
}
});
} else {
let output = '';
Expand Down
17 changes: 10 additions & 7 deletions test/parallel/test-fs-promises-file-handle-readFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ async function doReadAndCancel() {
{
const filePathForHandle = path.resolve(tmpDir, 'dogs-running.txt');
const fileHandle = await open(filePathForHandle, 'w+');
const buffer = Buffer.from('Dogs running'.repeat(10000), 'utf8');
fs.writeFileSync(filePathForHandle, buffer);
const signal = AbortSignal.abort();
await assert.rejects(readFile(fileHandle, { signal }), {
name: 'AbortError'
});
await fileHandle.close();
try {
const buffer = Buffer.from('Dogs running'.repeat(10000), 'utf8');
fs.writeFileSync(filePathForHandle, buffer);
const signal = AbortSignal.abort();
await assert.rejects(readFile(fileHandle, { signal }), {
name: 'AbortError'
});
} finally {
await fileHandle.close();
}
}

// Signal aborted on first tick
Expand Down
18 changes: 11 additions & 7 deletions test/parallel/test-fs-promises-file-handle-writeFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ async function validateWriteFile() {
async function doWriteAndCancel() {
const filePathForHandle = path.resolve(tmpDir, 'dogs-running.txt');
const fileHandle = await open(filePathForHandle, 'w+');
const buffer = Buffer.from('dogs running'.repeat(512 * 1024), 'utf8');
const controller = new AbortController();
const { signal } = controller;
process.nextTick(() => controller.abort());
await assert.rejects(writeFile(fileHandle, buffer, { signal }), {
name: 'AbortError'
});
try {
const buffer = Buffer.from('dogs running'.repeat(512 * 1024), 'utf8');
const controller = new AbortController();
const { signal } = controller;
process.nextTick(() => controller.abort());
await assert.rejects(writeFile(fileHandle, buffer, { signal }), {
name: 'AbortError'
});
} finally {
await fileHandle.close();
}
}

validateWriteFile()
Expand Down
Loading

0 comments on commit 98ac82e

Please sign in to comment.