Skip to content

Commit a4f556f

Browse files
authored
fs: remove ability to call truncate with fd
PR-URL: #57567 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 4a7d501 commit a4f556f

File tree

5 files changed

+6
-60
lines changed

5 files changed

+6
-60
lines changed

doc/api/deprecations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,12 +1832,15 @@ and replaced with an identical, public `path.toNamespacedPath()` method.
18321832

18331833
<!-- YAML
18341834
changes:
1835+
- version: REPLACEME
1836+
pr-url: https://github.com/nodejs/node/pull/57567
1837+
description: End-of-Life.
18351838
- version: v9.0.0
18361839
pr-url: https://github.com/nodejs/node/pull/15990
18371840
description: Runtime deprecation.
18381841
-->
18391842

1840-
Type: Runtime
1843+
Type: End-of-Life
18411844

18421845
`fs.truncate()` `fs.truncateSync()` usage with a file descriptor is
18431846
deprecated. Please use `fs.ftruncate()` or `fs.ftruncateSync()` to work with

lib/fs.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ const {
149149

150150
const permission = require('internal/process/permission');
151151

152-
let truncateWarn = true;
153152
let fs;
154153

155154
// Lazy loaded
@@ -167,16 +166,6 @@ let ReadFileContext;
167166
let FileReadStream;
168167
let FileWriteStream;
169168

170-
function showTruncateDeprecation() {
171-
if (truncateWarn) {
172-
process.emitWarning(
173-
'Using fs.truncate with a file descriptor is deprecated. Please use ' +
174-
'fs.ftruncate with a file descriptor instead.',
175-
'DeprecationWarning', 'DEP0081');
176-
truncateWarn = false;
177-
}
178-
}
179-
180169
// Ensure that callbacks run in the global context. Only use this function
181170
// for callbacks that are passed to the binding layer, callbacks that are
182171
// invoked from JS already run in the proper scope.
@@ -1031,10 +1020,6 @@ function renameSync(oldPath, newPath) {
10311020
* @returns {void}
10321021
*/
10331022
function truncate(path, len, callback) {
1034-
if (typeof path === 'number') {
1035-
showTruncateDeprecation();
1036-
return fs.ftruncate(path, len, callback);
1037-
}
10381023
if (typeof len === 'function') {
10391024
callback = len;
10401025
len = 0;
@@ -1064,11 +1049,6 @@ function truncate(path, len, callback) {
10641049
* @returns {void}
10651050
*/
10661051
function truncateSync(path, len) {
1067-
if (typeof path === 'number') {
1068-
// legacy
1069-
showTruncateDeprecation();
1070-
return fs.ftruncateSync(path, len);
1071-
}
10721052
if (len === undefined) {
10731053
len = 0;
10741054
}

test/parallel/test-fs-truncate-fd.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/parallel/test-fs-truncate-sync.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ const filename = path.resolve(tmp, 'truncate-sync-file.txt');
1212

1313
fs.writeFileSync(filename, 'hello world', 'utf8');
1414

15-
const fd = fs.openSync(filename, 'r+');
15+
fs.truncateSync(filename, 5);
16+
assert(fs.readFileSync(filename).equals(Buffer.from('hello')));
1617

17-
fs.truncateSync(fd, 5);
18-
assert(fs.readFileSync(fd).equals(Buffer.from('hello')));
19-
20-
fs.closeSync(fd);
2118
fs.unlinkSync(filename);

test/parallel/test-fs-truncate.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ tmpdir.refresh();
3333

3434
let stat;
3535

36-
const msg = 'Using fs.truncate with a file descriptor is deprecated.' +
37-
' Please use fs.ftruncate with a file descriptor instead.';
38-
3936
// Check truncateSync
4037
fs.writeFileSync(filename, data);
4138
stat = fs.statSync(filename);
@@ -64,10 +61,6 @@ fs.ftruncateSync(fd);
6461
stat = fs.statSync(filename);
6562
assert.strictEqual(stat.size, 0);
6663

67-
// truncateSync
68-
common.expectWarning('DeprecationWarning', msg, 'DEP0081');
69-
fs.truncateSync(fd);
70-
7164
fs.closeSync(fd);
7265

7366
// Async tests

0 commit comments

Comments
 (0)