Skip to content

Commit

Permalink
fix permission handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Feb 11, 2022
1 parent bb3f5aa commit f32fbf7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
50 changes: 36 additions & 14 deletions pkg/projectionfs/projection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
* limitations under the License.
*/

package projectionfs
package projectionfs_test

import (
"os"

"github.com/mandelsoft/vfs/pkg/osfs"
"github.com/mandelsoft/vfs/pkg/projectionfs"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

Expand All @@ -30,22 +32,21 @@ import (
)

var _ = Describe("projection filesystem", func() {
var fs vfs.FileSystem
var mem vfs.FileSystem

BeforeEach(func() {
var err error
Context("plain", func() {
var fs vfs.FileSystem
var mem vfs.FileSystem

mem = memoryfs.New()
BeforeEach(func() {
var err error

mem.MkdirAll("d1/d1d1/d1d1d1/a", os.ModePerm)
mem.MkdirAll("d1/d1d1/d1d1d2/b", os.ModePerm)
mem.MkdirAll("d2/d2d1", os.ModePerm)
fs, err = New(mem, "d1")
Expect(err).To(Succeed())
})
mem = memoryfs.New()

Context("plain", func() {
mem.MkdirAll("d1/d1d1/d1d1d1/a", os.ModePerm)
mem.MkdirAll("d1/d1d1/d1d1d2/b", os.ModePerm)
mem.MkdirAll("d2/d2d1", os.ModePerm)
fs, err = projectionfs.New(mem, "d1")
Expect(err).To(Succeed())
})

It("root", func() {
ExpectFolders(fs, "/", []string{"d1d1"}, nil)
Expand Down Expand Up @@ -89,4 +90,25 @@ var _ = Describe("projection filesystem", func() {
Expect(fi.Mode() & (os.ModeType)).To(Equal(os.ModeSymlink))
})
})

Context("tempfs", func() {
var tempfs vfs.FileSystem

BeforeEach(func() {
t, err := osfs.NewTempFileSystem()
Expect(err).To(Succeed())
tempfs = t
})

AfterEach(func() {
vfs.Cleanup(tempfs)
})

It("handles permission problem", func() {
Expect(tempfs.Mkdir("test", 0)).To(Succeed())
err := tempfs.Mkdir("test/sub", 0)
Expect(err).To(HaveOccurred())
Expect(os.IsPermission(err)).To(BeTrue())
})
})
})
2 changes: 1 addition & 1 deletion pkg/utils/mappedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (m *MappedFileSystem) mapPath(path string, link ...bool) (vfs.FileSystem, s
if err != nil && !os.IsPermission(err) {
return nil, "", "", err
}
if fi.Mode()&os.ModeSymlink != 0 && (getlink || strings.Contains(path, vfs.PathSeparatorString)) {
if (fi != nil && fi.Mode()&os.ModeSymlink != 0) && (getlink || strings.Contains(path, vfs.PathSeparatorString)) {
links++
if links > 255 {
return nil, "", "", errors.New("AbsPath: too many links")
Expand Down

0 comments on commit f32fbf7

Please sign in to comment.