Skip to content

Commit

Permalink
fix(pipe) EACESS write error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Apr 14, 2020
1 parent aea0384 commit 18b527b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion lib/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ function pipe(allStreams, options, callback) {
error = e;
destroy(finish, write);
readError = true;
writeError = true;

if (!end && !finish)
onResult();
Expand All @@ -124,6 +123,9 @@ function pipe(allStreams, options, callback) {
if (readError && !isFsWriteStream)
return onEnd();

if (readError && writeOpened)
return onEnd();

if (bothFinish || justEnd)
return onEnd();

Expand Down
25 changes: 18 additions & 7 deletions test/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const test = require('supertape');

const random = Math.random();

test('empty buffer | write file', async (t) => {
test('empty buffer | write file: error directory', async (t) => {
const inStream = new Readable({
read() {},
});
Expand Down Expand Up @@ -129,16 +129,18 @@ test('file1 | file2: write open EACESS: big file', (t) => {
});
});

test('file1 | file2: read open ENOENT', (t) => {
test('file1 | file2: read open ENOENT', async (t) => {
const tmp = os.tmpdir();
const name = path.basename(__filename);
const nameTmp = path.join(tmp, name + random);

tryPipe(__filename + random, nameTmp, (error) => {
t.ok(error, error && error.message);

t.end();
});
const read = fs.createReadStream(__filename + random);
const write = fs.createWriteStream(nameTmp);

const [error] = await tryToCatch(_pipe, [read, write]);
t.ok(error, error && error.message);

t.end();
});

test('file1 | file2: error read EISDIR', (t) => {
Expand Down Expand Up @@ -321,6 +323,15 @@ test('put file', (t) => {
});
});

test('read file| through| write directory: error', async (t) => {
const transform = through2((chunk, enc, cb) => cb(null, chunk));
const [e] = await tryToCatch(_pipe, [fs.createReadStream('/sdlfj'), transform, fs.createWriteStream('/dsfsdf')]);
//const [e] = await tryToCatch(_pipe, [fs.createReadStream('/sdlfj'), fs.createWriteStream('/dsfsdf')]);

t.equal(e.code, 'EACCES', 'should equal');
t.end();
});

test('put file | unzip', (t) => {
const server = http.createServer((req, res) => {
const gunzip = zlib.createGunzip();
Expand Down

0 comments on commit 18b527b

Please sign in to comment.