Skip to content

Commit f6556b6

Browse files
vkurchatkinchrisdickinson
authored andcommitted
fs: fix symlink error message
the arguments were swapped, so fs.symlink{Sync,} would report that the wrong file EEXIST'd in error. Fixes: nodejs/node-v0.x-archive#8651 Fixes: nodejs/node-v0.x-archive#4314 Fixes: nodejs/node-v0.x-archive#5381 PR-URL: nodejs/node-v0.x-archive#8657 Reviewed-by: Chris Dickinson <christopher.s.dickinson@gmail.com>
1 parent 00d7b13 commit f6556b6

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/node_file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,9 @@ static void Symlink(const FunctionCallbackInfo<Value>& args) {
515515
}
516516

517517
if (args[3]->IsFunction()) {
518-
ASYNC_DEST_CALL(symlink, args[3], *dest, *dest, *path, flags)
518+
ASYNC_DEST_CALL(symlink, args[3], *path, *dest, *path, flags)
519519
} else {
520-
SYNC_DEST_CALL(symlink, *path, *dest, *dest, *path, flags)
520+
SYNC_DEST_CALL(symlink, *dest, *path, *dest, *path, flags)
521521
}
522522
}
523523

test/simple/test-fs-error-messages.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ fs.link(existingFile, existingFile2, function(err) {
5656
assert.ok(0 <= err.message.indexOf(existingFile2));
5757
});
5858

59+
fs.symlink(existingFile, existingFile2, function(err) {
60+
assert.ok(0 <= err.message.indexOf(existingFile2));
61+
});
62+
5963
fs.unlink(fn, function(err) {
6064
assert.ok(0 <= err.message.indexOf(fn));
6165
});
@@ -153,6 +157,14 @@ try {
153157
assert.ok(0 <= err.message.indexOf(existingFile2));
154158
}
155159

160+
try {
161+
++expected;
162+
fs.symlinkSync(existingFile, existingFile2);
163+
} catch (err) {
164+
errors.push('symlink');
165+
assert.ok(0 <= err.message.indexOf(existingFile2));
166+
}
167+
156168
try {
157169
++expected;
158170
fs.unlinkSync(fn);

0 commit comments

Comments
 (0)