GeezerVison is showing github.com — fs: fix writeFile signal does not close file · nodejs/node@f2279f8
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/fs.js +12-1Lines changed: 12 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -334,6 +334,11 @@ function readFile(path, options, callback) { |
334 | 334 | return; |
335 | 335 | } |
336 | 336 |
|
| 337 | + if (options.signal?.aborted) { |
| 338 | + callback(lazyDOMException('The operation was aborted', 'AbortError')); |
| 339 | + return; |
| 340 | + } |
| 341 | + |
337 | 342 | const flagsNumber = stringToFlags(options.flag); |
338 | 343 | path = getValidatedPath(path); |
339 | 344 |
|
@@ -1440,7 +1445,13 @@ function lutimesSync(path, atime, mtime) { |
1440 | 1445 |
|
1441 | 1446 | function writeAll(fd, isUserFd, buffer, offset, length, signal, callback) { |
1442 | 1447 | if (signal?.aborted) { |
1443 | | - callback(lazyDOMException('The operation was aborted', 'AbortError')); |
| 1448 | + if (isUserFd) { |
| 1449 | + callback(lazyDOMException('The operation was aborted', 'AbortError')); |
| 1450 | + } else { |
| 1451 | + fs.close(fd, function() { |
| 1452 | + callback(lazyDOMException('The operation was aborted', 'AbortError')); |
| 1453 | + }); |
| 1454 | + } |
1444 | 1455 | return; |
1445 | 1456 | } |
1446 | 1457 | // write(fd, buffer, offset, length, position, callback) |
|