mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
fs: close file streams with fd 0
Signed-off-by: greenhead <greenheadhq@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66131 Fixes: https://github.com/nodejs/node/issues/57905 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
462946a5fa
commit
2c26192314
2 files changed
+16
-2
No files matched your search
@@ -123,7 +123,7 @@ const FileHandleOperations = (handle) => {
|
||||
};
|
||||
|
||||
function close(stream, err, cb) {
|
||||
if (!stream.fd) {
|
||||
if (stream.fd == null) {
|
||||
cb(err);
|
||||
} else if (stream.flush) {
|
||||
stream[kFs].fsync(stream.fd, (flushErr) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
@@ -70,3 +70,17 @@ const originalFs = { fs };
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
for (const createStream of [fs.createReadStream, fs.createWriteStream]) {
|
||||
const stream = createStream(null, {
|
||||
fd: 0,
|
||||
fs: {
|
||||
...fs,
|
||||
close: common.mustCall((fd, callback) => {
|
||||
assert.strictEqual(fd, 0);
|
||||
callback(null);
|
||||
}),
|
||||
},
|
||||
});
|
||||
stream.destroy();
|
||||
}
|
||||
Reference in new issue
Block a user