Skip to content

Commit

Permalink
Merge pull request moby#4 from LK4D4/implement_chmod
Browse files Browse the repository at this point in the history
Implement chmod
  • Loading branch information
bradfitz committed May 23, 2014
2 parents 724b202 + fdbca23 commit 28272e9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
18 changes: 18 additions & 0 deletions vfuse/all_test.go
Expand Up @@ -448,3 +448,21 @@ dirwalk/sub/2.txt = -rw-r----- (size 7)
t.Errorf("Walk got:\n%s\n\nWant:\n%s", got.String(), want)
}
}

// Chmod file
func init() { addWorldTest("TestChmod") }
func TestChmod(t *testing.T) {
w := getWorld(t)
defer w.release()

w.writeFile(w.cpath("chmod/1.txt"), "test file")

os.Chmod(w.fpath("chmod/1.txt"), 0777)
st, err := os.Stat(w.cpath("chmod/1.txt"))
if err != nil {
t.Fatal(err)
}
if st.Mode().String() != "-rwxrwxrwx" {
t.Fatalf("Mode %s, expected %s", st.Mode(), os.FileMode(0777))
}
}
14 changes: 13 additions & 1 deletion vfuse/client/client.go
Expand Up @@ -94,6 +94,8 @@ func (s *Server) Run() {
res, err = s.handleReaddirRequest(m)
case *pb.ReadlinkRequest:
res, err = s.handleReadlinkRequest(m)
case *pb.ChmodRequest:
res, err = s.handleChmodRequest(m)
default:
log.Fatalf("client: unhandled request type %T", p.Body)
}
Expand Down Expand Up @@ -135,7 +137,7 @@ func mapMode(m os.FileMode) uint32 {
mode |= S_IFDIR
} else if m.IsRegular() {
mode |= S_IFREG
} else if m & os.ModeSymlink != 0 {
} else if m&os.ModeSymlink != 0 {
mode |= S_IFLNK
}
// TODO: more
Expand Down Expand Up @@ -190,3 +192,13 @@ func (s *Server) handleReadlinkRequest(req *pb.ReadlinkRequest) (proto.Message,
res.Target = &target
return res, nil
}

func (s *Server) handleChmodRequest(req *pb.ChmodRequest) (proto.Message, error) {
err := os.Chmod(filepath.Join(s.vol.Root, filepath.FromSlash(req.GetName())), os.FileMode(req.GetMode()))
res := new(pb.ChmodResponse)
if err != nil {
res.Err = mapError(err)
return res, nil
}
return res, nil
}
20 changes: 20 additions & 0 deletions vfuse/vfused/server.go
Expand Up @@ -253,6 +253,26 @@ func (fs *FS) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Stat
return fattr, fuse.OK
}

func (fs *FS) Chmod(name string, mode uint32, context *fuse.Context) fuse.Status {
vlogf("fs.Chmod(%q)", name)
resc, err := fs.sendPacket(&pb.ChmodRequest{
Name: &name,
Mode: &mode,
})
if err != nil {
return fuse.EIO
}
res, ok := (<-resc).(*pb.ChmodResponse)
if !ok {
vlogf("fs.Chmod(%q) = EIO because wrong type", name)
return fuse.EIO
}
if res.Err != nil {
return fuseError(res.Err)
}
return fuse.OK
}

//SetAttr(input *SetAttrIn, out *AttrOut) (code Status)

func (fs *FS) readFromClient() {
Expand Down

0 comments on commit 28272e9

Please sign in to comment.