-
Notifications
You must be signed in to change notification settings - Fork 742
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)); | ||
|
||
| } | ||
|
|
||
| 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('..'); | ||||||||
|
||||||||
| test.afterEach.always(t => { | |
| shell.rm('-rf', t.context.tmp); | |
| }); |
to include process.chdir(CWD) before the rm() call? I've filed #834 to provide a better, long-term solution.
The problem with cd('..') is that our code might throw exceptions, causing the cd('..') to not be executed (and so state would never be restored). Also, I think ava stops running a test case as soon as the first assertion fails, which is another case where cd('..') would be skipped.
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.
Yes, I've already had that case where an unrelated test would fail just because the previous one couldn't cd('..') anymore.
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 have added chdiring to the CWD after each test and also removed all now-gratuitous cd('..') lines in the file.
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.
nit: also assert .stderr and shell.error() are empty
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.
Going to add those. It's not been done anywhere in the ln() tests, and I mostly got inspiration from the other tests around there. 🙈
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.
Check.
Outdated
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.
Cleanup isn't necessary
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.
Removed that line.
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.