Skip to content

new feature: VFS auto normalization #7072

Closed

Description

@kapitainsky

Immediate goal of this enhancement is to fix macOS rclone mount which at the moment does not work properly regardless of mounting method used - macOSFUSE or FUSE-T. Optionally normalized VFS can bring other benefits as well e.g. some less common or future filesystems rclone users can work with and normalization constraints imposed.

The background issue and possible solutions have been discussed on the forum:

https://forum.rclone.org/t/possible-special-character-encoding-issue-on-macos/39048/30

At the moment many cloud storage destinations (and rclone virtual crypt remote) allow to store both NFC and NFD encoded files/directories names. Also rclone allows to upload/download both forms.

This in general works trouble free on Linux and Windows but breaks rclone mount functionality in macOS - depending on mount options either only NFC or only NFD content is visible/accessible - this is unfortunate consequence of Apple design decision to be different than rest of the world and use exclusively NFD in their APIs. We won't change it.

Experimentation and testing, including attempts to improve situation with FUSE-T (it has now - since v1.0.20 - -o nfc option which should help with NFC path) lead me to believe that last missing part of the puzzle is rclone VFS lack of normalization.

I would like to propose to add optional normalization to VFS.

New option:

--vfs-normalize OFF/NFC/NFD - with OFF being default

When set to NFC or NFD it would apply characters normalization to served content.

Edge case to watch is situation where two names differ only by normalization and coexist in the same folder e.g.:

$ rclone lsf crypt:TEST

CONFLICTéééFILE.txt
CONFLICTéééFILE.txt

one file is NFC and other is NFD. Only solution I see for such case is use only one name and log ERROR.

Activity

  1. added this to the v1.64 milestone on Jun 23, 2023
  2. ncw commented on Jun 23, 2023

    @ncw
    Member

    I think this should be achievable relatively easily.

    All file / dir objects are ultimately made from the directory cache. So we only need to do the normalized comparison in the directory cache searching routine.

    We actually do this already for case sensitive / insensitive file systems.

    So first we look for an exact match which is a quick hash look up, and then we look for a case insensitive match which involves comparing every item.

    rclone/vfs/dir.go

    Lines 710 to 732 in 2c50f26

    func (d *Dir) stat(leaf string) (Node, error) {
    d.mu.Lock()
    defer d.mu.Unlock()
    err := d._readDir()
    if err != nil {
    return nil, err
    }
    item, ok := d.items[leaf]
    if !ok && d.vfs.Opt.CaseInsensitive {
    leafLower := strings.ToLower(leaf)
    for name, node := range d.items {
    if strings.ToLower(name) == leafLower {
    if ok {
    // duplicate case insensitive match is an error
    return nil, fmt.Errorf("duplicate filename %q detected with --vfs-case-insensitive set", leaf)
    }
    // found a case insensitive match
    ok = true
    item = node
    }
    }
    }

    We could do something very similar for the normalization options too. I think we'd want to make a normalization function which does the (NFC, NFD) and/or (lower case) and just run through the loop once. We do exactly this in the sync routines so factoring this out would be sensible.

    rclone/fs/march/march.go

    Lines 58 to 71 in 2c50f26

    // Now create the matching transform
    // ..normalise the UTF8 first
    if !m.NoUnicodeNormalization {
    m.transforms = append(m.transforms, norm.NFC.String)
    }
    // ..if destination is caseInsensitive then make it lower case
    // case Insensitive | src | dst | lower case compare |
    // | No | No | No |
    // | Yes | No | No |
    // | No | Yes | Yes |
    // | Yes | Yes | Yes |
    if m.Fdst.Features().CaseInsensitive || ci.IgnoreCaseSync {
    m.transforms = append(m.transforms, strings.ToLower)
    }

    Edge case to watch is situation where two names differ only by normalization and coexist in the same folder

    We currently just use the first one in the case vs CASE comparison. That is the easy thing to do. To detect a collision would require scanning the whole directory which would take on average twice as long.

    Worth the extra CPU for an ERROR message?

    New option:

    --vfs-normalize OFF/NFC/NFD - with OFF being default

    Assuming we are only using the normalize option to find matching file names and not actually returning them to the OS then we can get away with using NFC only and this would match this flag which only does NFC normalization.

      --no-unicode-normalization   Don't normalize unicode characters in filenames
    

    Once thing I am unclear on though - do you think we need to apply that normalization to the file names sent to the OS - is that your intention? So we receive an NFC file name from Google Drive (say) and send the macOS kernel an NFD file name according to the flag? That will be a bit more work (but not much). I think this might be what the FUSE-T option -o nfc does though so maybe isn't necessary?

  3. kapitainsky commented on Jun 23, 2023

    @kapitainsky
    ContributorAuthor

    Once thing I am unclear on though - do you think we need to apply that normalization to the file names sent to the OS - is that your intention?

    Yes this is the most important thing actually and whole purpose of this - it is about sending to OS normalized names. Today we have a problem that remotes can contain both NFC and NFD names - it works on Linux but breaks macOS.

    I think this might be what the FUSE-T option -o nfc does though so maybe isn't necessary?

    This option converts names received from OS (macOS uses NFD) and makes sure that NFS mount receives NFC - so all NFS content is NFC. It also makes NFC content to work with macOS APIs.
    It breaks when some content in remote is already NFD - files are not visible/directories are not browsable.

    On macOS it happens for example when user uses rclone copy/sync - NFD names are saved in remote.

    With --vfs-normalize to make macOS mount work we could either:

    1. --vfs-normalize NFD - this is what macOS likes the most I think

    REMOTE -----------------------> MOUNT
    NFC -> RCLONE -> NFD -> FUSE -> NFD <---- rclone normalized NFC->NFD
    NFD -> RCLONE -> NFD -> FUSE -> NFD

    MOUNT -----------------------> REMOTE
    NFC -> FUSE -> NFC -> RCLONE -> NFC
    NFD -> FUSE -> NFD -> RCLONE -> NFD

    1. --vfs-normalize NFC and use -o nfc

    REMOTE -----------------------> MOUNT
    NFC -> RCLONE -> NFC -> FUSE -> NFD
    NFD -> RCLONE -> NFC -> FUSE -> NFD <---- rclone normalized NFD->NFC

    MOUNT -----------------------> REMOTE
    NFC -> FUSE -> NFC -> RCLONE -> NFC
    NFD -> FUSE -> NFC-> RCLONE -> NFC

    It is difficult to say which one will behave better on macOS - I think that both would work. But with NFC/NFD and macOS I have learnt that only testing can tell.

  4. kapitainsky commented on Jun 23, 2023

    @kapitainsky
    ContributorAuthor

    The key purpose of this enhancement is to fix rclone mount on macOS.

    Today it simply does not work - does not matter with macFUSE or FUSE-T. And is unfixable by -o modules=iconv,from_code=UTF-8,to_code=UTF-8 or -o modules=iconv,from_code=UTF-8,to_code=UTF-8-MAC workaround. It only helps in some cases and creates new issues - like for example that files can not be open in Finder (macOS file browser)

    image

  5. ncw commented on Jun 23, 2023

    @ncw
    Member

    I think what I'll do is try the smallest patch that could work first. That would fix the "... can't be found" errors I think but it wouldn't normalize the returns to the OS. This might mean we need the -o nfc flag. If that doesn't work I can do the further parts..

  6. kapitainsky commented on Jun 23, 2023

    @kapitainsky
    ContributorAuthor

    Cool. I am happy at all stages to test - I do not need binary build I can happily build myself from git clone. I have my test bed - crypt with carefully crafted mix of NFC/NFD files and folders:) so far it breaks everything.

    I hoped that fuse-t can handle it fully but does not seem to be possible.

  7. kapitainsky commented on Jun 23, 2023

    @kapitainsky
    ContributorAuthor

    Note:

    With --vfs-normalize set to NFC or NFD iconv should not be applied:

    rclone/cmd/cmount/mount.go

    Lines 120 to 126 in fcb912a

    if runtime.GOOS == "darwin" {
    if !findOption("modules=iconv", options) {
    iconv := "modules=iconv,from_code=UTF-8,to_code=UTF-8-MAC"
    options = append(options, "-o", iconv)
    fs.Debugf(nil, "Adding \"-o %s\" for macOS", iconv)
    }
    }

    It is crude way to actually try to normalize to NFD- but it stopped working fully with advent of APFS FS few years ago and changes in normalization in all macOS - also I suspect not 100% correct way macFUSE handles it. I actually suspect it never worked 100% before neither - but nowadays it is more apparent.

    Still should be there for old Apple computers users - this is why --vfs-normalize should be optional

  8. kapitainsky commented on Jul 27, 2023

    @kapitainsky
    ContributorAuthor

    Sorry to keep pestering... but can it be implemented one day? I am not skilled enough in go to give it a go. I do try to earn my karma points on the forum instead:) I do believe that it is missing piece of macOS rclone mount to work predictably and consistently - and now it is disaster people using it do not realize.

    I managed to convince author of fuse-t to make changes helping to alleviate problems moving forward. But without option to normalize mount to NFD on rclone side it is only half measure.

  9. ncw commented on Jul 28, 2023

    @ncw
    Member

    Sorry to keep pestering... but can it be implemented one day? I am not skilled enough in go to give it a go. I do try to earn my karma points on the forum instead:)

    You have lots of karma indeed :-)

    I put this on the 1.64 milestone which isn't a guarantee that it will make that release, but it will be on my radar at least!

  10. modified the milestones: v1.64, v1.65 on Sep 11, 2023
  11. modified the milestones: v1.65, v1.66 on Jan 3, 2024
  12. 25 remaining items

  13. kapitainsky commented on Feb 7, 2024

    @kapitainsky
    ContributorAuthor

    @nielash sorry for pestering:) do you think your improvements (normalisation and nfsmount writes on macOS) can be PR-ed?:) These are fixes I was waiting for years so now trying to make sure that they are not lost:)

    I have been using them the last few days and this is day and night compared to what it was before in terms of macOS rclone mount compatibility.

    I bet some bits can be still ironed but the best way is to get exposure to myriad of use cases we can't even imagine - simply make it live. rclone nfsmount made to release in disastrous stage - effectively useless so compared to it your changes are gold.

  14. nielash commented on Feb 7, 2024

    @nielash
    Contributor

    I have been using them the last few days and this is day and night compared to what it was before in terms of macOS rclone mount compatibility.

    Very glad to hear that 🙂

    Yes, I can submit PRs. I was planning to also look at some of the other nfsmount issues you mentioned (--volname and unmounting), but as they are less critical maybe it's best to submit the most important changes first and fix the rest later. What do you think?

    rclone nfsmount made to release in disastrous stage - effectively useless so compared to it your changes are gold.

    🤣

  15. kapitainsky commented on Feb 7, 2024

    @kapitainsky
    ContributorAuthor

    Yes, I can submit PRs. I was planning to also look at some of the other nfsmount issues you mentioned (--volname and unmounting), but as they are less critical maybe it's best to submit the most important changes first and fix the rest later. What do you think?

    IMO normalisation is fully working and is ready to be included in rclone release. I even took time to understand your code) it looks very clean and logical.

    nfsmount - I do appreciate good engineering so have to say that indeed maybe better to solve known issues and make it real feature not just some half baked thing.

    Most importantly normalisation works perfectly with macFUSE/FUSE-T so it immediately solves old issue. nfsmount is very nice addition but not critical.

  16. nielash commented on Feb 13, 2024

    @nielash
    Contributor

    @kapitainsky I made a proof-of-concept for a rclone convmv command. Very much still a WIP, but if you are interested: nielash@1d6be93

    Examples of what it does: Link

  17. kapitainsky commented on Feb 16, 2024

    @kapitainsky
    ContributorAuthor

    @kapitainsky I made a proof-of-concept for a rclone convmv command. Very much still a WIP, but if you are interested: nielash@1d6be93

    Examples of what it does: Link

    I have managed to compile it and run few simple tests. All worked! I think that it is very cool small utility. When needed it is purely irreplaceable. Things like this make rclone truly pro utility. Thank you very much for doing it.

  18. added a commit that references this issue on Mar 6, 2024
    fd8faeb
  19. added a commit that references this issue on Jul 20, 2026
    8623fb5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions