Skip to content

vfs: fix unicode normalization on macOS - fixes #7072 - #7620

Merged
ncw merged 1 commit into
rclone:masterfrom
nielash:fix-vfs-normalization
Mar 6, 2024
Merged

ncw merged 1 commit into
rclone:masterfrom
nielash:fix-vfs-normalization

Conversation

@nielash

@nielash nielash commented Feb 8, 2024 •

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

Before this change, the VFS layer did not properly handle unicode normalization, which caused problems particularly for users of macOS. While attempts were made to handle it with various -o modules=iconv combinations, this was an imperfect solution, as no one combination allowed both NFC and NFD content to simultaneously be both visible and editable via Finder.

After this change, the VFS supports --no-unicode-normalization (default false) via the existing --vfs-case-insensitive logic, which is extended to apply to both case insensitivity and unicode normalization form.

This change also adds an additional flag, --vfs-block-norm-dupes, to address a probably rare but potentially possible scenario where a directory contains multiple duplicate filenames after applying case and unicode normalization settings. In such a scenario, this flag (disabled by default) hides the duplicates. This comes with a performance tradeoff, as rclone will have to scan the entire directory for duplicates when listing a directory. For this reason, it is recommended to leave this disabled if not needed. However, macOS users may wish to consider using it, as otherwise, if a remote directory contains both NFC and NFD versions of the same filename, an odd situation will occur: both versions of the file will be visible in the mount, and both will appear to be editable, however, editing either version will actually result in only the NFD version getting edited under the hood. --vfs-block-norm-dupes prevents this confusion by detecting this scenario, hiding the duplicates, and logging an error, similar to how this is handled in rclone sync.

Was the change discussed in an issue or in the forum before?

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

@kapitainsky

kapitainsky commented Feb 8, 2024 •

Copy link
Copy Markdown
Contributor

Thank you very much for tackling this pesky issue with your PR! macOS users will be grateful:)

I have been testing this feature for the last few days and it works like a charm with whatever NFC/NFD objects I throw at mount or remote. And everything is accessible on macOS using both terminal and Finder.

This looks like true solution to years old problem with NFC/NFD on macOS. It works perfectly with both macFUSE and FUSE-T. No more any snake oil iconv options needed - it never really fully worked anyway.

@ncw I see that #7072 is on v1.66 milestones list (it was also on v1.65:)) so hopefully you can include it in the upcoming rclone release.

@kapitainsky

Copy link
Copy Markdown
Contributor

Is there any issue stopping this change from being merged?

@kapitainsky

Copy link
Copy Markdown
Contributor

I am sorry for pestering but as this is something causing issues in my daily rclone usage I keep a close eye on this possible fix.

@ncw Has this change have a chance to be included in the next rclone release? Or is there still something needed required to do it?

@ncw ncw left a comment

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.

I think this looks sound :-)

I have some quibbles with the use of the global config though - see inline!

Thank you !

Comment thread vfs/dir.go Resolved
Comment thread vfs/vfs_case_test.go Resolved
Comment thread vfs/vfs_case_test.go Resolved
Comment thread cmd/cmount/mount.go Resolved
Comment thread vfs/dir.go Resolved
Comment thread vfs/dir.go Resolved
@nielash

nielash commented Feb 29, 2024

Copy link
Copy Markdown
Contributor Author

@ncw very helpful feedback, thank you! I think fs.AddConfig will work well for the actual code, but I'm not sure it will work for passing options from the tests, because it seems that the VFS methods do not actually take a ctx function parameter -- they all just use context.TODO(). Should I try to change them to take a function param?

Another option is maybe to make a new VFS option, although it seems not ideal to have lots of options that kind of do the same thing (like we kind of already have with vfs.Opt.CaseInsensitive and ci.IgnoreCaseSync).

Whatever you think is best is fine with me 🙂

@nielash
nielash force-pushed the fix-vfs-normalization branch from 90dbe8b to 77c8596 Compare March 4, 2024 03:28
@nielash

nielash commented Mar 4, 2024

Copy link
Copy Markdown
Contributor Author

Here's a revised version that addresses most of the feedback. The production code now uses fs.AddConfig. The one change I did not fully make is changing the test code to use fs.AddConfig, because of what I mentioned in my previous comment. For now I have addressed that concern in a different way (by restoring the prior value after the test), but I remain open to different solutions if you prefer!

@ncw ncw left a comment

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.

I think your use of context in the tests is fine! The VFS doesn't have contexts and that is because the underlying Go interfaces don't take contexts which is unfortunate.

However on further reflection I think we should try to avoid having to change the context in the main code - see the notes I put inline! Reading it is fine and expected but changing it is not ideal.

Comment thread vfs/dir.go Resolved
@nielash
nielash force-pushed the fix-vfs-normalization branch from 77c8596 to f0c5b6c Compare March 5, 2024 10:01
@nielash

nielash commented Mar 5, 2024

Copy link
Copy Markdown
Contributor Author

Makes sense! Here's a new version with this changed.

Comment thread vfs/dir.go Resolved
Before this change, the VFS layer did not properly handle unicode normalization,
which caused problems particularly for users of macOS. While attempts were made
to handle it with various `-o modules=iconv` combinations, this was an imperfect
solution, as no one combination allowed both NFC and NFD content to
simultaneously be both visible and editable via Finder.

After this change, the VFS supports `--no-unicode-normalization` (default `false`)
via the existing `--vfs-case-insensitive` logic, which is extended to apply to both
case insensitivity and unicode normalization form.

This change also adds an additional flag, `--vfs-block-norm-dupes`, to address a
probably rare but potentially possible scenario where a directory contains
multiple duplicate filenames after applying case and unicode normalization
settings. In such a scenario, this flag (disabled by default) hides the
duplicates. This comes with a performance tradeoff, as rclone will have to scan
the entire directory for duplicates when listing a directory. For this reason,
it is recommended to leave this disabled if not needed. However, macOS users may
wish to consider using it, as otherwise, if a remote directory contains both NFC
and NFD versions of the same filename, an odd situation will occur: both
versions of the file will be visible in the mount, and both will appear to be
editable, however, editing either version will actually result in only the NFD
version getting edited under the hood. `--vfs-block-norm-dupes` prevents this
confusion by detecting this scenario, hiding the duplicates, and logging an
error, similar to how this is handled in `rclone sync`.
@nielash
nielash force-pushed the fix-vfs-normalization branch from f0c5b6c to e637517 Compare March 6, 2024 14:46

@ncw ncw left a comment

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.

This looks great now - thank you :-)

I'll merge it.

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.

new feature: VFS auto normalization

3 participants