question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error "Source and destination must not be the same" in move-sync on unicode normalization difference

See original GitHub issue
  • Operating System: macOs 10.15.7 (latest Catalina)
  • Node.js version: v14.15.3
  • fs-extra version: 9.0.1

First I’d like to thank you for fs-extra which is really great!

I’m fighting with an error when trying to move files: “Source and destination must not be the same.”

I filtered the src and destination with === and they are NOT the same -> so why is fs-extra rejecting me?

Digging deeper, they look the same. When comparing their normalized unicode representation, they are indeed the same. So I’m suspecting (but don’t really know) that fs-extra is doing a unicode normalization before validating src vs dest. (maybe Object.checkPathsSync (xxx/node_modules/fs-extra/lib/util/stat.js:51:11) [EDIT] the file system is doing unicode normalization.

If true, I believe this is incorrect. There are discussions for ex. in https://news.ycombinator.com/item?id=13953800 that states that for ex. APFS is treating pathes are “bags of bytes” and intentionally not normalizing (cf. linked https://mjtsai.com/blog/2017/03/24/apfss-bag-of-bytes-filenames/)

Hence I believe that fs-extra should not normalize. (not an expert, happy to be explained wrong)

~~somehow related to https://github.com/jprichardson/node-fs-extra/issues/759~~

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
RyanZimcommented, Jan 18, 2021

My apologies for the radio silence here; I’ve been super-busy, and put open-source on hold for a few days. Glad you managed to figure it out; filesystems in general tend to do weird things, which is why we abandoned comparing actual paths for inode checks.

0reactions
Offirmocommented, May 7, 2021

@manidlou sure. On a file system doing automatic unicode normalization:

const path = `voyage à Paris.jpg`.normalize('NFD') // user input = force normalization to an exotic one for demo purpose
const target_path = path.normalize('NFC') // systematic normalization of user input
assert(a !== b) // same visual appearance but not same binary reprensentation
fs_extra.moveSync(path, target_path) // error "same inode"

This is not a cosmetic fix, I read in a blog post recently someone having trouble storing then retrieving their file on S3 due to this kind of normalization being done by safari on file upload, then the database storing a different representation.

interesting reads:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error "Source and destination must not be the same" in move ...
Error "Source and destination must not be the same" in move-sync on unicode normalization difference.
Read more >
fs-extra: source and destination must not be the same. (cordova)
I get an error while building with cordova.
Read more >
FAQ - Normalization - Unicode
Q: Why should my program normalize strings? Programs should always compare canonical-equivalent Unicode strings as equal (For the details of this ...
Read more >
Error On Ionic Cordova Android Build "Source And Destination ...
[Bug] Cordova Build: Source and destination must not be the same See source code ... must not be the same in movesync on...
Read more >
ICU 72.1: unorm2.h File Reference
Returns a UNormalizer2 instance for Unicode NFC normalization. ... Writes the normalized form of the source string to the destination string (replacing its ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found