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

5 files changed

Lines changed: 6 additions & 60 deletions

File tree

‎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
constpermission=require('internal/process/permission');
155155

156-
lettruncateWarn=true;
157156
letfs;
158157

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

174-
functionshowTruncateDeprecation(){
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
functiontruncate(path,len,callback){
1038-
if(typeofpath==='number'){
1039-
showTruncateDeprecation();
1040-
returnfs.ftruncate(path,len,callback);
1041-
}
10421027
if(typeoflen==='function'){
10431028
callback=len;
10441029
len=0;
@@ -1068,11 +1053,6 @@ function truncate(path, len, callback) {
10681053
* @returns {void}
10691054
*/
10701055
functiontruncateSync(path,len){
1071-
if(typeofpath==='number'){
1072-
// legacy
1073-
showTruncateDeprecation();
1074-
returnfs.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-
constfd=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
letstat;
3535

36-
constmsg='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)