Skip to content

MemMapFs.Stat does not handle empty string as expected #522

Description

@zoddicus

os.Stat("") will return an error, stat : no such file or directory, where as MemMapFs.Stat() does not return an error. Instead it returns a populated FileInfo:

FileInfo.Name() == ""
FileInfo.Size() == 42
FileInfo.Mode() == "drwxr-xr-x"
FileInfo.ModTime() == "2025-07-30 16:15:24.211543491 -0400 EDT m=+0.000353724"
FileInfo.IsDir() == true

This can be worked around by having special case handling for empty strings in the code calling into Stat(), but that kinda defeats the purpose of having an injectable FS for testing.

A test showing this difference in behaviour:

func TestMemMapFsStat(t *testing.T) {
       fs := &MemMapFs{}
       {
               f, err := fs.Stat("")
               if err != nil {
                       fmt.Printf("fs.Stat() err is %s\n", err.Error())
               } else {
                       fmt.Println("fs.Stat() err is nil")
                        fmt.Println(f.Name())
                        fmt.Println(f.Size())
                        fmt.Println(f.Mode())
                        fmt.Println(f.ModTime())
                        fmt.Println(f.IsDir())
               }
       }
       {
               f, err := os.Stat("")
               if err != nil {
                       fmt.Printf("os.Stat() err is %s\n", err.Error())
               } else {
                       fmt.Println("os.Stat() err is nil")
                        fmt.Println(f.Name())
                        fmt.Println(f.Size())
                        fmt.Println(f.Mode())
                        fmt.Println(f.ModTime())
                        fmt.Println(f.IsDir())
               }
       }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions