diff options
author | Bruno Jouhier <bjouhier@gmail.com> | 2015-02-07 19:27:20 +0100 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2015-02-21 12:13:21 -0500 |
commit | c82e580a5019b460350457198054e41dfaa5fc0c (patch) | |
tree | 13de38e7b272a0a4e07baa8f82bf059cd8a4f8b1 /test/parallel/test-fs-truncate-fd.js | |
parent | 4fcbb8aaaf32e57d5ec1c23460c0d2c86da4fe6e (diff) | |
download | android-node-v8-c82e580a5019b460350457198054e41dfaa5fc0c.tar.gz android-node-v8-c82e580a5019b460350457198054e41dfaa5fc0c.tar.bz2 android-node-v8-c82e580a5019b460350457198054e41dfaa5fc0c.zip |
fs: properly handle fd passed to truncate()
Currently, fs.truncate() silently fails when a file descriptor
is passed as the first argument. This commit changes this
behavior to properly call fs.ftruncate().
PR-URL: https://github.com/joyent/node/pull/9161
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Conflicts:
lib/fs.js
Diffstat (limited to 'test/parallel/test-fs-truncate-fd.js')
-rw-r--r-- | test/parallel/test-fs-truncate-fd.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/parallel/test-fs-truncate-fd.js b/test/parallel/test-fs-truncate-fd.js new file mode 100644 index 0000000000..6e9628db86 --- /dev/null +++ b/test/parallel/test-fs-truncate-fd.js @@ -0,0 +1,25 @@ +var common = require('../common'); +var assert = require('assert'); +var path = require('path'); +var fs = require('fs'); +var tmp = common.tmpDir; +if (!fs.existsSync(tmp)) + fs.mkdirSync(tmp); +var filename = path.resolve(tmp, 'truncate-file.txt'); + +var success = 0; + +fs.writeFileSync(filename, 'hello world', 'utf8'); +var fd = fs.openSync(filename, 'r+'); +fs.truncate(fd, 5, function(err) { + assert.ok(!err); + assert.equal(fs.readFileSync(filename, 'utf8'), 'hello'); + success++; +}); + +process.on('exit', function() { + fs.closeSync(fd); + fs.unlinkSync(filename); + assert.equal(success, 1); + console.log('ok'); +}); |