diff options
author | r1cebank <siyuangao@gmail.com> | 2017-10-06 11:06:35 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-10-12 18:02:14 -0700 |
commit | c885ea727da7ffd66deb5a775a0d1fb40f14a329 (patch) | |
tree | 640837602d14fcffd0b0307d5e8155921357b2d0 /lib | |
parent | af49e58211ea63d53900eb068eaa5f32ae1cf236 (diff) | |
download | android-node-v8-c885ea727da7ffd66deb5a775a0d1fb40f14a329.tar.gz android-node-v8-c885ea727da7ffd66deb5a775a0d1fb40f14a329.tar.bz2 android-node-v8-c885ea727da7ffd66deb5a775a0d1fb40f14a329.zip |
lib: deprecate fd usage for fs.truncate(Sync)
PR-URL: https://github.com/nodejs/node/pull/15990
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fs.js | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -63,6 +63,18 @@ const isWindows = process.platform === 'win32'; const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG); const errnoException = util._errnoException; +let truncateWarn = true; + +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; + } +} + function getOptions(options, defaultOptions) { if (options === null || options === undefined || typeof options === 'function') { @@ -783,6 +795,7 @@ fs.renameSync = function(oldPath, newPath) { fs.truncate = function(path, len, callback) { if (typeof path === 'number') { + showTruncateDeprecation(); return fs.ftruncate(path, len, callback); } if (typeof len === 'function') { @@ -808,6 +821,7 @@ fs.truncate = function(path, len, callback) { fs.truncateSync = function(path, len) { if (typeof path === 'number') { // legacy + showTruncateDeprecation(); return fs.ftruncateSync(path, len); } if (len === undefined) { |