Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemMapFs and Walk issues with leading / #450

Open
sweharris opened this issue Jan 30, 2025 · 0 comments
Open

MemMapFs and Walk issues with leading / #450

sweharris opened this issue Jan 30, 2025 · 0 comments

Comments

@sweharris
Copy link

sweharris commented Jan 30, 2025

If I create a directory called Hello and then do a Walk from "/" then the walk function is called with an error open /Hello: file does not exist.

Similarly if I create a directory called /Hello but do a Walk from "" then I get a similar error; open Hello: file does not exist

Clearly the Walk is finding the directory but then failing to get information about it!

The Mkdir and Walk starting points must either both be anchored at / or not.

example code:

package main

import (
        "fmt"
        "os"

        "github.com/spf13/afero"
)

func find_walk(path string, info os.FileInfo, err error) error {
        if err != nil {
             fmt.Println(err)
        } else {
             fmt.Println("Found", path)
        }
        return err
}

func main() {
        MyFs := afero.NewMemMapFs()
        MyFs.Mkdir("Hello", 0777)
        MyFs.Mkdir("Hello/There", 0777)
        MyFs.Create("Hello/There/Everyone")

        err := afero.Walk(MyFs, "/", find_walk)
        if err != nil {
             fmt.Println("Find failed", err)
        }
}

This returns the following:

% ./main
Found /
open /Hello: file does not exist
Find failed open /Hello: file does not exist

If I change the Walk to "" then it works:

Found
Found Hello
Found Hello/There
Found Hello/There/Everyone

Similarly if I do Mkdir with a leading / and if the Walk is from "" then I get the opposite error:

        MyFs.Mkdir("/Hello", 0777)
        MyFs.Mkdir("/Hello/There", 0777)
        MyFs.Create("/Hello/There/Everyone")
...

Found
Hello open Hello: file does not exist
Find failed open Hello: file does not exist

Even more fun is if the Mkdir is inconsistent! Starting from "/" returns things twice!

        MyFs.Mkdir("Hello", 0777)
        MyFs.Mkdir("/Hello/There", 0777)
        MyFs.Create("/Hello/There/Everyone")

        err := afero.Walk(MyFs, "/", find_walk)

...
Found /
Found /Hello
Found /Hello/There
Found /Hello/There/Everyone
Found /Hello
Found /Hello/There
Found /Hello/There/Everyone
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant