Skip to content

Commit

Permalink
fix rename non-empty directories sometimes returning wrong error
Browse files Browse the repository at this point in the history
  • Loading branch information
kahing committed Oct 22, 2015
1 parent cdcbc84 commit ca3fc3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions internal/goofys_test.go
Expand Up @@ -214,6 +214,7 @@ func (s *GoofysTest) setupDefaultEnv(t *C) (bucket string) {
"file1": nil,
"file2": nil,
"dir1/file3": nil,
"dir2/dir3/": nil,
"dir2/dir3/file4": nil,
"empty_dir/": nil,
"zero": bytes.NewReader([]byte{}),
Expand Down Expand Up @@ -547,6 +548,13 @@ func (s *GoofysTest) TestRename(t *C) {
err := root.Rename(s.fs, &from, root, &to)
t.Assert(err, Equals, fuse.ENOTEMPTY)

dir2, err := root.LookUp(s.fs, aws.String("dir2"))
t.Assert(err, IsNil)

from, to = "dir3", "new_dir"
err = dir2.Rename(s.fs, &from, root, &to)
t.Assert(err, Equals, fuse.ENOTEMPTY)

from, to = "empty_dir", "dir1"
err = root.Rename(s.fs, &from, root, &to)
t.Assert(err, Equals, fuse.ENOTEMPTY)
Expand Down
7 changes: 5 additions & 2 deletions internal/handles.go
Expand Up @@ -266,7 +266,7 @@ func isEmptyDir(fs *Goofys, fullName string) (isDir bool, err error) {
params := &s3.ListObjectsInput{
Bucket: &fs.bucket,
Delimiter: aws.String("/"),
MaxKeys: aws.Int64(1),
MaxKeys: aws.Int64(2),
Prefix: &fullName,
}

Expand All @@ -278,7 +278,10 @@ func isEmptyDir(fs *Goofys, fullName string) (isDir bool, err error) {
if len(resp.CommonPrefixes) > 0 || len(resp.Contents) > 1 {
err = fuse.ENOTEMPTY
isDir = true
} else if len(resp.Contents) == 1 {
return
}

if len(resp.Contents) == 1 {
isDir = true

if *resp.Contents[0].Key != fullName {
Expand Down

0 comments on commit ca3fc3c

Please sign in to comment.