-
Notifications
You must be signed in to change notification settings - Fork 739
Allow ln destination to be an existing directory, fixes #832 #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
3fe1a67
4008596
50e6ca8
582414d
9392c55
946ab48
c57f7ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,10 @@ function _ln(options, source, dest) { | |
var isAbsolute = (path.resolve(source) === sourcePath); | ||
dest = path.resolve(process.cwd(), String(dest)); | ||
|
||
if (fs.existsSync(dest) && common.statFollowLinks(dest).isDirectory(dest)) { | ||
dest = path.resolve(dest, path.basename(sourcePath)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, that shouldn't matter here, should it? It has been So given that we are guaranteed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I've replaced There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you're right. It's ok to |
||
} | ||
|
||
if (fs.existsSync(dest)) { | ||
if (!options.force) { | ||
common.error('Destination file exists', { continue: true }); | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -48,6 +48,14 @@ test('destination already exists', t => { | |||||||
t.is(result.code, 1); | ||||||||
}); | ||||||||
|
||||||||
test('destination already exists inside directory', t => { | ||||||||
shell.cd(t.context.tmp); | ||||||||
const result = shell.ln('-s', 'file1', './'); | ||||||||
t.truthy(shell.error()); | ||||||||
t.is(result.code, 1); | ||||||||
shell.cd('..'); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line isn't necessary. We restore state inside beforeEach(). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, nevermind. I get the described behaviour when I remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Re-added line 56, see comment below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this is a bug. As a safer workaround, could you edit these lines: Lines 18 to 20 in 9035b27
to include The problem with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I've already had that case where an unrelated test would fail just because the previous one couldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added |
||||||||
}); | ||||||||
|
||||||||
test('non-existent source', t => { | ||||||||
const result = shell.ln(`${t.context.tmp}/noexist`, `${t.context.tmp}/linkfile1`); | ||||||||
t.truthy(shell.error()); | ||||||||
|
@@ -137,6 +145,19 @@ test('To current directory', t => { | |||||||
shell.cd('..'); | ||||||||
}); | ||||||||
|
||||||||
test('Inside existing directory', t => { | ||||||||
shell.cd(t.context.tmp); | ||||||||
const result = shell.ln('-s', 'external/node_script.js', './'); | ||||||||
t.is(result.code, 0); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: also assert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going to add those. It's not been done anywhere in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check. |
||||||||
t.truthy(fs.existsSync('node_script.js')); | ||||||||
t.is( | ||||||||
fs.readFileSync('external/node_script.js').toString(), | ||||||||
fs.readFileSync('node_script.js').toString() | ||||||||
); | ||||||||
shell.rm('node_script.js'); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanup isn't necessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed that line. |
||||||||
shell.cd('..'); | ||||||||
}); | ||||||||
|
||||||||
test('-f option', t => { | ||||||||
const result = shell.ln('-f', `${t.context.tmp}/file1.js`, `${t.context.tmp}/file2.js`); | ||||||||
t.is(result.code, 0); | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
isDirectory()
accepts arguments: https://nodejs.org/api/fs.html#fs_stats_isdirectoryThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. That was definitely not on purpose. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.