diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 392ef09c2ca3e2..7172ac6ca95fb3 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -1832,12 +1832,15 @@ and replaced with an identical, public `path.toNamespacedPath()` method. -Type: Runtime +Type: End-of-Life `fs.truncate()` `fs.truncateSync()` usage with a file descriptor is deprecated. Please use `fs.ftruncate()` or `fs.ftruncateSync()` to work with diff --git a/lib/fs.js b/lib/fs.js index 4524e51dc4a966..41619ced0cc440 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -149,7 +149,6 @@ const { const permission = require('internal/process/permission'); -let truncateWarn = true; let fs; // Lazy loaded @@ -167,16 +166,6 @@ let ReadFileContext; let FileReadStream; let FileWriteStream; -function showTruncateDeprecation() { - if (truncateWarn) { - process.emitWarning( - 'Using fs.truncate with a file descriptor is deprecated. Please use ' + - 'fs.ftruncate with a file descriptor instead.', - 'DeprecationWarning', 'DEP0081'); - truncateWarn = false; - } -} - // Ensure that callbacks run in the global context. Only use this function // for callbacks that are passed to the binding layer, callbacks that are // invoked from JS already run in the proper scope. @@ -1031,10 +1020,6 @@ function renameSync(oldPath, newPath) { * @returns {void} */ function truncate(path, len, callback) { - if (typeof path === 'number') { - showTruncateDeprecation(); - return fs.ftruncate(path, len, callback); - } if (typeof len === 'function') { callback = len; len = 0; @@ -1064,11 +1049,6 @@ function truncate(path, len, callback) { * @returns {void} */ function truncateSync(path, len) { - if (typeof path === 'number') { - // legacy - showTruncateDeprecation(); - return fs.ftruncateSync(path, len); - } if (len === undefined) { len = 0; } diff --git a/test/parallel/test-fs-truncate-fd.js b/test/parallel/test-fs-truncate-fd.js deleted file mode 100644 index 51de2e5b91d3e8..00000000000000 --- a/test/parallel/test-fs-truncate-fd.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const path = require('path'); -const fs = require('fs'); -const tmpdir = require('../common/tmpdir'); -const tmp = tmpdir.path; -tmpdir.refresh(); -const filename = path.resolve(tmp, 'truncate-file.txt'); - -fs.writeFileSync(filename, 'hello world', 'utf8'); -const fd = fs.openSync(filename, 'r+'); - -const msg = 'Using fs.truncate with a file descriptor is deprecated.' + -' Please use fs.ftruncate with a file descriptor instead.'; - - -common.expectWarning('DeprecationWarning', msg, 'DEP0081'); -fs.truncate(fd, 5, common.mustSucceed(() => { - assert.strictEqual(fs.readFileSync(filename, 'utf8'), 'hello'); -})); - -process.once('beforeExit', () => { - fs.closeSync(fd); - fs.unlinkSync(filename); - console.log('ok'); -}); diff --git a/test/parallel/test-fs-truncate-sync.js b/test/parallel/test-fs-truncate-sync.js index 66250cf4386b34..c529fa6f3949fc 100644 --- a/test/parallel/test-fs-truncate-sync.js +++ b/test/parallel/test-fs-truncate-sync.js @@ -12,10 +12,7 @@ const filename = path.resolve(tmp, 'truncate-sync-file.txt'); fs.writeFileSync(filename, 'hello world', 'utf8'); -const fd = fs.openSync(filename, 'r+'); +fs.truncateSync(filename, 5); +assert(fs.readFileSync(filename).equals(Buffer.from('hello'))); -fs.truncateSync(fd, 5); -assert(fs.readFileSync(fd).equals(Buffer.from('hello'))); - -fs.closeSync(fd); fs.unlinkSync(filename); diff --git a/test/parallel/test-fs-truncate.js b/test/parallel/test-fs-truncate.js index efaeeca7173c12..eac64a627dfcec 100644 --- a/test/parallel/test-fs-truncate.js +++ b/test/parallel/test-fs-truncate.js @@ -33,9 +33,6 @@ tmpdir.refresh(); let stat; -const msg = 'Using fs.truncate with a file descriptor is deprecated.' + - ' Please use fs.ftruncate with a file descriptor instead.'; - // Check truncateSync fs.writeFileSync(filename, data); stat = fs.statSync(filename); @@ -64,10 +61,6 @@ fs.ftruncateSync(fd); stat = fs.statSync(filename); assert.strictEqual(stat.size, 0); -// truncateSync -common.expectWarning('DeprecationWarning', msg, 'DEP0081'); -fs.truncateSync(fd); - fs.closeSync(fd); // Async tests