Skip to content

move: support changing case in case-insensitive systems - #801

Closed
manidlou wants to merge 13 commits into
v10from
mani/move-case-insensitive
Closed

manidlou wants to merge 13 commits into
v10from
mani/move-case-insensitive

Conversation

@manidlou

Copy link
Copy Markdown
Collaborator

Resolves #759.

@manidlou manidlou self-assigned this May 16, 2020
@manidlou manidlou added this to the 10.0.0 milestone May 16, 2020
@manidlou manidlou linked an issue May 16, 2020 that may be closed by this pull request
@RyanZim

RyanZim commented May 16, 2020

Copy link
Copy Markdown
Collaborator

@manidlou Did you verify this actually changes the case displayed in the file manager or on the command line, for Mac or Windows?

@manidlou

Copy link
Copy Markdown
Collaborator Author

@RyanZim that's definitely required and I wanted to do that but I don't have neither of those systems. I appreciate if anyone could verify that on Mac and Windows! Feel free to let me know if the changes don't work and I will work on it then! I also might be able to have access to my friend's macbook tomorrow, so I'll let you know then.

@manidlou

Copy link
Copy Markdown
Collaborator Author

I verified that on Mac and it successfully changed the case.

@JPeer264 JPeer264 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Works now perfectly on my Mac

Comment thread lib/move/move.js Resolved
manidlou and others added 2 commits June 21, 2020 13:31
No breaking changes for us, just performance improvements
Comment thread lib/util/stat.js Outdated
const statSync = (file) => nodeSupportsBigInt ? fs.statSync(file, { bigint: true }) : fs.statSync(file)
const lstatSync = (file) => nodeSupportsBigInt ? fs.lstatSync(file, { bigint: true }) : fs.lstatSync(file)

const isCaseInsensitiveSystem = process.platform === 'darwin' || process.platform === 'win32'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Linux also has case-insensitive filesystems, and it can network mount CIFS which is also case-insensitive. So the only way to test this is to see if you can access a file on the filesystem you want to work with via another casing that doesn't exist yet.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I agree that it doesn't include all case-insensitive file systems. Basically a better approach would be to actually probe the file system to find out about its case-sensitivity. It might have some performance drawback but ultimately that would be a better approach.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

But wouldn't you have to do that for every directory you access?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If directories are mounted on different file systems, yes! Basically, finding case-sensitivity of a file system is a complex thing! If we want to be 100% safe, we need to check where the directories are mounted, and also if there is any subsystem that has its own case comparison table.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So wouldn't it be easier to just rename the file and pass any errors to the user instead?

Comment thread lib/util/stat.js Outdated
const srcBaseName = path.basename(src)
const destBaseName = path.basename(dest)
if (funcName === 'move' &&
isCaseInsensitiveSystem &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

perhaps better to simply not test for this. If the stat() result is the same, it's the same file.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

... And in that case, just call rename(). I can't think of a case where it would fail

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That makes sense! I am ok with not checking for case sensitivity of the system as this is not comprehensive enough!

@RyanZim

RyanZim commented Jan 18, 2021

Copy link
Copy Markdown
Collaborator

@manidlou ping!

@manidlou

Copy link
Copy Markdown
Collaborator Author

Sorry for the long pause! Been extremely busy! I will have a look at this again.

@RyanZim RyanZim left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM; except test descriptions need updated, since there's nothing OS-specific anymore (shouldn't say "based on the OS").

@manidlou

Copy link
Copy Markdown
Collaborator Author

Since this will merge into v10, and I am a bit worried if we wait for long time, we might end up having some merge conflicts! So I merged current master into v10 and rebased this one so that we will have a clean merge!

@RyanZim

RyanZim commented Feb 17, 2021

Copy link
Copy Markdown
Collaborator

@manidlou Honestly, I suspect I'll end up manually cherry-picking everything related to v10, since it's taken so long. Just leave this PR as-is for now.

RyanZim pushed a commit that referenced this pull request Apr 1, 2021
@RyanZim

RyanZim commented Apr 1, 2021 •

Copy link
Copy Markdown
Collaborator

Landed on master in c8bd383.

@RyanZim RyanZim closed this Apr 1, 2021
@RyanZim
RyanZim deleted the mani/move-case-insensitive branch April 1, 2021 20:26
RyanZim added a commit that referenced this pull request Sep 22, 2026
* Treat Unicode-normalization-only renames like case-only renames

Moving a file to a name that differs only in Unicode normalization
form (NFC vs NFD) throws "Source and destination must not be the
same." on filesystems that auto-normalize, such as APFS, even though
the source and destination are visually identical and the user is
just renaming the file. This mirrors the case-insensitive rename bug
fixed in #801, so it gets the same fix: when the basenames differ but
resolve to the same inode, and they're equal after either
lowercasing or NFC normalization, treat it as a rename instead of
raising the same-path error.

Fixes #859

* Add tests for capitalization change at the same time

* Normalize both case and unicode forms together when comparing

---------

Co-authored-by: Ryan Zimmerman <opensrc@ryanzim.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot move file to change case on case insensitive fs

7 participants