mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
fs: fix writeFile signal does not close file
Fix an issue where the writeFile does not close the file when the signal is aborted. PR-URL: https://github.com/nodejs/node/pull/37402 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
52b3b54c14
commit
f2279f856e
1 file changed
+12
-1
@@ -334,6 +334,11 @@ function readFile(path, options, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.signal?.aborted) {
|
||||
callback(lazyDOMException('The operation was aborted', 'AbortError'));
|
||||
return;
|
||||
}
|
||||
|
||||
const flagsNumber = stringToFlags(options.flag);
|
||||
path = getValidatedPath(path);
|
||||
|
||||
@@ -1440,7 +1445,13 @@ function lutimesSync(path, atime, mtime) {
|
||||
|
||||
function writeAll(fd, isUserFd, buffer, offset, length, signal, callback) {
|
||||
if (signal?.aborted) {
|
||||
callback(lazyDOMException('The operation was aborted', 'AbortError'));
|
||||
if (isUserFd) {
|
||||
callback(lazyDOMException('The operation was aborted', 'AbortError'));
|
||||
} else {
|
||||
fs.close(fd, function() {
|
||||
callback(lazyDOMException('The operation was aborted', 'AbortError'));
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
// write(fd, buffer, offset, length, position, callback)
|
||||
|
||||
Reference in new issue
Block a user