Skip to content

Commit

Permalink
fs: don't conflate data and callback in appendFile
Browse files Browse the repository at this point in the history
PR-URL: #11607
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
seishun authored and addaleax committed Jun 17, 2017
1 parent e17cf59 commit 8154d15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ fs.writeFileSync = function(path, data, options) {
};

fs.appendFile = function(path, data, options, callback) {
callback = maybeCallback(arguments[arguments.length - 1]);
callback = maybeCallback(callback || options);
options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'a' });

// Don't make changes directly on options object
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-fs-append-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ fs.open(filename5, 'a+', function(e, fd) {
});
});

// test that a missing callback emits a warning, even if the last argument is a
// function.
const filename6 = join(common.tmpDir, 'append6.txt');
const warn = 'Calling an asynchronous function without callback is deprecated.';
common.expectWarning('DeprecationWarning', warn);
fs.appendFile(filename6, console.log);

process.on('exit', function() {
assert.strictEqual(12, ncallbacks);

Expand Down

0 comments on commit 8154d15

Please sign in to comment.