Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
squash: do not throw if file doesn't exist
  • Loading branch information
LiviaMedeiros committed Sep 12, 2022
commit 704fe670c57b917b87cb9ae9258de93e0fba6263
9 changes: 7 additions & 2 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,13 @@ async function readlink(path, options) {
async function symlink(target, path, type_) {
let type = (typeof type_ === 'string' ? type_ : null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is semver-major anyway, we might as well use validateString here, wdyt?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Something like validateOneOf(type, 'type', ['dir', 'file', 'junction', undefined]) would be perfect.
I'd also prefer to have this validation performed on all platforms for consistency.
However, technically it can break userland code (e.g. if someone used null or false), so full deprecation cycle might be safer.

if (isWindows && type === null) {
const absoluteTarget = pathModule.resolve(`${path}`, '..', `${target}`);
type = (await stat(absoluteTarget))?.isDirectory() ? 'dir' : 'file';
try {
const absoluteTarget = pathModule.resolve(`${path}`, '..', `${target}`);
type = (await stat(absoluteTarget)).isDirectory() ? 'dir' : 'file';
} catch {
// Default to 'file' if path is invalid or file does not exist
type = 'file';
}
}
target = getValidatedPath(target, 'target');
path = getValidatedPath(path);
Expand Down