spf13 / afero

A FileSystem Abstraction System for Go
Apache License 2.0
5.93k stars 508 forks source link

MemMapFs not checking for permissions #335

Open staticdev opened 2 years ago

staticdev commented 2 years ago

How to reproduce:

package main

import (
    "log"

    "github.com/spf13/afero"
)

func main() {
    folderName := "secret"
    fsys := afero.NewMemMapFs()
    fsys.Mkdir(folderName, 0700)
    afero.WriteFile(fsys, "secret/filename", []byte(""), 0700)

    _, err := fsys.Stat("secret/filename")
    if err != nil {
        log.Fatal(err)
    }
    fsys.Chmod("secret", 0000)
    _, err = fsys.Stat("secret/filename")
    if err != nil {
        log.Fatal(err)
    }
}

If you do the same with NewOsFs() instead of NewMemMapFs() you get the error on second Stat (which is the intended behavior since the secret folder has no read permissions).

May be related to https://github.com/spf13/afero/issues/327