- Operating System: Debian 9
- Node.js version: 8.9.3
fs-extra version: 5.0.0
Hi there. I ran into some cases where remove() was unable to remove a directory due to filename encoding issues. I believe there are similar issues using empty, copy, and move operations (and their sync counterparts - basically anything that relies on fs.readdir / fs.readdirSync).
My issue arose when trying to fs.remove() some directories that were created from an unzip operation. During removes / rimraf's tree walk, some of the returned directories seemed not to exist (although they did), causing the final unlink operation to fail (since it wasn't actually successfully emptied).
It seems that, in general, names on a file system are just byte sequences, which are not guaranteed to represent fully valid strings. This causes the bytes-> string -> bytes operation, that happens when listing and then operating on items in a directory using Node, to not always produce the same file name that it read.
This encoding problem has been a known Node issue for a while, which is why an option was added to return Buffers from fs.readdir. My suggestion is to update the affected methods to use this Buffer option. I'm happy to work on a PR, but I wanted to at least get some feedback and discuss the issue before diving in.
Here are a couple Node issues relating to the file name encoding problem:
nodejs/node-v0.x-archive#2387
nodejs/node#5616
Thanks!
fs-extraversion: 5.0.0Hi there. I ran into some cases where
remove()was unable to remove a directory due to filename encoding issues. I believe there are similar issues usingempty,copy, andmoveoperations (and their sync counterparts - basically anything that relies onfs.readdir/fs.readdirSync).My issue arose when trying to
fs.remove()some directories that were created from an unzip operation. Duringremoves /rimraf's tree walk, some of the returned directories seemed not to exist (although they did), causing the finalunlinkoperation to fail (since it wasn't actually successfully emptied).It seems that, in general, names on a file system are just byte sequences, which are not guaranteed to represent fully valid strings. This causes the bytes-> string -> bytes operation, that happens when listing and then operating on items in a directory using Node, to not always produce the same file name that it read.
This encoding problem has been a known Node issue for a while, which is why an option was added to return
Buffers fromfs.readdir. My suggestion is to update the affected methods to use thisBufferoption. I'm happy to work on a PR, but I wanted to at least get some feedback and discuss the issue before diving in.Here are a couple Node issues relating to the file name encoding problem:
nodejs/node-v0.x-archive#2387
nodejs/node#5616
Thanks!