Conversation
src/rm.js
Outdated
| } | ||
|
|
||
| // Path is a symbolic link | ||
| if (stats.isSymbolicLink()) { |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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
}There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I think the original behavior has been maintained: noop for anything that isn't a directory, file or symlink.
|
@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 |
|
Let's add support for removing other file types in another PR. @freitagbr can you file the issue? |
|
Sure, I will do that. |
Fixes #519