Skip to content

Fix: rm behavior regarding symlinks#598

Merged
nfischer merged 3 commits intomasterfrom
rm-dir-symlink
Dec 9, 2016
Merged

Fix: rm behavior regarding symlinks#598
nfischer merged 3 commits intomasterfrom
rm-dir-symlink

Conversation

@freitagbr
Copy link
Copy Markdown
Contributor

Fixes #519

src/rm.js Outdated
}

// Path is a symbolic link
if (stats.isSymbolicLink()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we should turn this into an else-if ladder?

Also, what happens if this is a different type of file, such as a fifo (like mkfifo creates)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, we have lots of code duplication here that should probably get cleaned up. We call common.unlinkSync() in two different branches for isFile, and we should probably move the isDirectory branches into one:

if (isFile) {
  if (options.force || isWriteable()) {
    // remove
  } else {
    // error
  }
} else if (isDirectory()) {
  if (options.recursive) {
     // remove
  } else {
     // error
  }
} else if (isLink()) {
  // remove
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, that makes sense.

Regarding other file types, here are the types that fs.lstatSync recognizes:

stats.isFile()
stats.isDirectory()
stats.isBlockDevice()
stats.isCharacterDevice()
stats.isSymbolicLink()
stats.isFIFO()
stats.isSocket()

Out of these, I think it only really makes sense to unlink files, directories, symlinks, and maybe fifos. Maybe we should stick to those 4, and ignore anything else?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can add support for the others later. In this PR, we need to make sure that we have an else case that performs whatever would have been done before (assuming it was reasonable behavior) to avoid a breaking change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the original behavior has been maintained: noop for anything that isn't a directory, file or symlink.

@nfischer
Copy link
Copy Markdown
Member

nfischer commented Dec 9, 2016

@freitagbr what was the original behavior on the other file types, such as fifos? It looks like this approach will ignore those files, which probably isn't what we want. It may be sufficient to have one else to catch all of them (if that's consistent with previous behavior).

@nfischer
Copy link
Copy Markdown
Member

nfischer commented Dec 9, 2016

Let's add support for removing other file types in another PR. @freitagbr can you file the issue?

@nfischer nfischer added the fix Bug/defect, or a fix for such a problem label Dec 9, 2016
@nfischer nfischer merged commit ded1a3e into master Dec 9, 2016
@nfischer nfischer deleted the rm-dir-symlink branch December 9, 2016 07:45
@freitagbr
Copy link
Copy Markdown
Contributor Author

Sure, I will do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug/defect, or a fix for such a problem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants