Skip to content

Commit fabf938

Browse files
anonrigRafaelGSS
authored andcommitted
fs: remove ability to call truncate with fd
PR-URL: #57567 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent d5e9edc commit fabf938

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
@@ -153,7 +153,6 @@ const {
153153

154154
const permission = require('internal/process/permission');
155155

156-
let truncateWarn = true;
157156
let fs;
158157

159158
// Lazy loaded
@@ -171,16 +170,6 @@ let ReadFileContext;
171170
let FileReadStream;
172171
let FileWriteStream;
173172

174-
function showTruncateDeprecation() {
175-
if (truncateWarn) {
176-
process.emitWarning(
177-
'Using fs.truncate with a file descriptor is deprecated. Please use ' +
178-
'fs.ftruncate with a file descriptor instead.',
179-
'DeprecationWarning', 'DEP0081');
180-
truncateWarn = false;
181-
}
182-
}
183-
184173
// Ensure that callbacks run in the global context. Only use this function
185174
// for callbacks that are passed to the binding layer, callbacks that are
186175
// invoked from JS already run in the proper scope.
@@ -1035,10 +1024,6 @@ function renameSync(oldPath, newPath) {
10351024
* @returns {void}
10361025
*/
10371026
function truncate(path, len, callback) {
1038-
if (typeof path === 'number') {
1039-
showTruncateDeprecation();
1040-
return fs.ftruncate(path, len, callback);
1041-
}
10421027
if (typeof len === 'function') {
10431028
callback = len;
10441029
len = 0;
@@ -1068,11 +1053,6 @@ function truncate(path, len, callback) {
10681053
* @returns {void}
10691054
*/
10701055
function truncateSync(path, len) {
1071-
if (typeof path === 'number') {
1072-
// legacy
1073-
showTruncateDeprecation();
1074-
return fs.ftruncateSync(path, len);
1075-
}
10761056
if (len === undefined) {
10771057
len = 0;
10781058
}

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy