hanwen / go-fuse

FUSE bindings for Go
Other
1.98k stars 315 forks source link

easy way to add a prefix to a loopback path? #155

Closed jmhodges closed 5 years ago

jmhodges commented 7 years ago

I've got a directory /path/to/foobar on disk that I'd like to alias to /another/weirdpath/to/foobar. I have a solution to that problem but I suspect there's an easier way to do it.

Currently, I'm using lots of mounts of nodefs.NewMemNodeFSRoot on to one another. Like, so:

func aliasDirTo(newPath, origPath string, root nodefs.Node, conn *nodefs.FileSystemConnector) error {
    parts := strings.Split(newPath, "/")
    for i, p := range parts[:len(parts)-1] {
        lastRoot := root
        child := lastRoot.Inode().GetChild(p)
        if child == nil {
            root = nodefs.NewMemNodeFSRoot("")
            st := conn.Mount(lastRoot.Inode(), p, root, nil)
            if !st.Ok() {
                return fmt.Errorf("unable to mount %s while making it as part of the new alias %s for %s: %s", strings.Join(parts[:i+1], "/"), newPath, origPath, st)
            }

        } else {
            root = child.Node()
        }
    }
    lastMountDir := parts[len(parts)-1]
    fs := pathfs.NewLoopbackFileSystem(origPath)
    nodeFS := pathfs.NewPathNodeFs(pathfs.NewReadonlyFileSystem(fs), &pathfs.PathNodeFsOptions{ClientInodes: true})
    st := conn.Mount(root.Inode(), lastMountDir, nodeFS.Root(), nil)
    if !st.Ok() {
        return fmt.Errorf("unable to mount last dir in %s as an alias of %s: %s", newPath, origPath, st)
    }
    return nil
}

That seems a little complicated and the large amount of mounts is funny (and makes the dirs show up in funny colors, of course).

Is there an easier way to make this happen?

hanwen commented 7 years ago

the obvious solution would be a symlink, but I suppose that doesn't work for some reason.

what does 'alias' mean? Do you want regular files in both directories to share inodes, for example?

jmhodges commented 7 years ago

Yeah, this is for supporting some Go tooling so symlinks don't work.

There's a build process I can't change easily whose artifacts are Go libraries that I need to have under a different name (and directory structure) in order to work with things like mockgen etc

jmhodges commented 7 years ago

(This is for bazel stuff that has a different idea from Go of how things should be laid out)

hanwen commented 7 years ago

is this bazel stuff public, or can you talk about it? I designed the original Go rules for Bazel, and am in contact with Bazel team still, so maybe there is a better way.

jmhodges commented 7 years ago

My GOPATH-creation code is not public, yet.

For context: that code makes the assumption that you'll get a go_default_library.a because you used gazelle to generate your BUILD files and turns that into the right file name dogs.a or whatever. This is with bazel 0.4.5 and 7cce22ee036166177d803efed6eea608a1ba37d9 in https://github.com/bazelbuild/rules_go

hanwen commented 5 years ago

closing due to inactivity.