Skip to content

Commit

Permalink
Fixed all known issues with copying files via the Finder.
Browse files Browse the repository at this point in the history
For #125.
  • Loading branch information
jacobsa committed Sep 10, 2015
2 parents 4895f09 + 679a940 commit d3b70cd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
5 changes: 3 additions & 2 deletions docs/semantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ look up child inodes. Unlike file inodes:

* gcsfuse does not keep track of modification time for
directories. There are no guarantees for the contents of `stat::st_mtime`
or equivalent.
or equivalent or the behavior of `utimes(2)` and similar.

* There are no guarantees about `stat::st_nlink`.

Expand Down Expand Up @@ -372,7 +372,8 @@ By default, all inodes in a gcsfuse file system show up as being owned by the
UID and GID of the gcsfuse process itself, i.e. the user who mounted the file
system. All files have permission bits `0644`, and all directories have
permission bits `0755` (but see below for issues with use by other users).
Changing permission bits is not supported.
Changing inode mode (using `chmod(2)` or similar) is unsupported, and changes
are silently ignored.

These defaults can be overriden with the `--uid`, `--gid`, `--file-mode`, and
`--dir-mode` flags.
Expand Down
23 changes: 6 additions & 17 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,38 +952,27 @@ func (fs *fileSystem) SetInodeAttributes(

in.Lock()
defer in.Unlock()
file, isFile := in.(*inode.FileInode)

// We don't support changing non-files.
file, ok := in.(*inode.FileInode)
if !ok {
err = fuse.ENOSYS
return
}

// Set the mtime, if requested.
if op.Mtime != nil {
// Set file mtimes.
if isFile && op.Mtime != nil {
err = file.SetMtime(ctx, *op.Mtime)
if err != nil {
err = fmt.Errorf("SetMtime: %v", err)
return
}
}

// Set the size, if specified.
if op.Size != nil {
// Truncate files.
if isFile && op.Size != nil {
err = file.Truncate(ctx, int64(*op.Size))
if err != nil {
err = fmt.Errorf("Truncate: %v", err)
return
}
}

// We don't support setting mode. (We silently ignore atime updates, as per
// docs/semantics.md.)
if op.Mode != nil {
err = fuse.ENOSYS
return
}
// We silently ignore updates to mode and atime.

// Fill in the response.
op.Attributes, op.AttributesExpiration, err = fs.getAttributes(ctx, in)
Expand Down
56 changes: 36 additions & 20 deletions internal/fs/local_modifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,35 @@ func (t *DirectoryTest) CreateHardLink() {
ExpectThat(err, Error(HasSubstr("not implemented")))
}

func (t *DirectoryTest) Chmod() {
var err error

// Create a directory.
p := path.Join(t.mfs.Dir(), "foo")
err = os.Mkdir(p, 0700)
AssertEq(nil, err)

// Attempt to chmod it. Chmod should succeed even though we don't do anything
// useful. The OS X Finder otherwise complains to the user when copying in a
// file.
err = os.Chmod(p, 0777)
ExpectEq(nil, err)
}

func (t *DirectoryTest) Chtimes() {
var err error

// Create a directory.
p := path.Join(t.mfs.Dir(), "foo")
err = os.Mkdir(p, 0700)
AssertEq(nil, err)

// Chtimes should succeed even though we don't do anything useful. The OS X
// Finder otherwise complains to the user when copying in a directory.
err = os.Chtimes(p, time.Now(), time.Now())
ExpectEq(nil, err)
}

////////////////////////////////////////////////////////////////////////
// File interaction
////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1680,15 +1709,15 @@ func (t *FileTest) Chmod() {
var err error

// Write a file.
fileName := path.Join(t.mfs.Dir(), "foo")
err = ioutil.WriteFile(fileName, []byte(""), 0700)
p := path.Join(t.mfs.Dir(), "foo")
err = ioutil.WriteFile(p, []byte(""), 0700)
AssertEq(nil, err)

// Attempt to chmod it. We don't support doing so.
err = os.Chmod(fileName, 0777)

AssertNe(nil, err)
ExpectThat(err, Error(HasSubstr("not implemented")))
// Attempt to chmod it. Chmod should succeed even though we don't do anything
// useful. The OS X Finder otherwise complains to the user when copying in a
// file.
err = os.Chmod(p, 0777)
ExpectEq(nil, err)
}

func (t *FileTest) Chtimes_InactiveFile() {
Expand Down Expand Up @@ -1784,19 +1813,6 @@ func (t *FileTest) Chtimes_OpenFile_Dirty() {
ExpectThat(fi.ModTime(), timeutil.TimeEq(newMtime))
}

func (t *FileTest) Chtimes_Directory() {
var err error

// Create a directory.
p := path.Join(t.mfs.Dir(), "foo")
err = os.Mkdir(p, 0700)
AssertEq(nil, err)

// Chtimes should fail; we don't support it for directories.
err = os.Chtimes(p, time.Now(), time.Now())
ExpectThat(err, Error(HasSubstr("not implemented")))
}

func (t *FileTest) Sync_Dirty() {
var err error
var n int
Expand Down

0 comments on commit d3b70cd

Please sign in to comment.