Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle zero bytes files (we can't send them)

Handle files that are deleted while they are opened (we don't send
them).
  • Loading branch information...
commit 3e0dc97ada0da483c3650eb4487db46a42fd1f92 1 parent c2fab36
@hanwen authored
Showing with 29 additions and 6 deletions.
  1. +18 −5 fs.go
  2. +6 −0 mtp.go
  3. +5 −1 test.sh
View
23 fs.go
@@ -9,6 +9,7 @@ import (
"io/ioutil"
"log"
"os"
+ "syscall"
"time"
)
@@ -113,18 +114,24 @@ func (n *fileNode) send() error {
if n.backing == "" {
log.Panicf("sending file without backing store: %q", n.file.Name())
}
-
fi, err := os.Stat(n.backing)
if err != nil {
log.Printf("could not do stat for send: %v", err)
return err
}
+ if fi.Size() == 0 {
+ log.Printf("cannot send 0 byte file %q", n.file.Name())
+ return syscall.EINVAL
+ }
f, err := os.Open(n.backing)
if err != nil {
return err
}
defer f.Close()
+ if n.file.Name() == "" {
+ return nil
+ }
log.Printf("Sending file %q to device: %d bytes.", n.file.Name(), fi.Size())
if n.file.Id() != 0 {
// Apparently, you can't overwrite things in MTP.
@@ -403,10 +410,15 @@ func (n *folderNode) Unlink(name string, c *fuse.Context) fuse.Status {
if f == nil {
return fuse.ENOENT
}
- err := n.fs.dev.DeleteObject(f.Id())
- if err != nil {
- log.Printf("DeleteObject failed: %v", err)
- return fuse.EIO
+
+ if f.Id() != 0 {
+ err := n.fs.dev.DeleteObject(f.Id())
+ if err != nil {
+ log.Printf("DeleteObject failed: %v", err)
+ return fuse.EIO
+ }
+ } else {
+ f.SetName("")
}
n.Inode().RmChild(name)
@@ -433,6 +445,7 @@ func (n *folderNode) Create(name string, flags uint32, mode uint32, context *fus
file: NewFile(0, n.id, n.storageId, name,
0, now, FILETYPE_UNKNOWN),
fs: n.fs,
+ dirty: true,
}
fn.backing = f.Name()
n.children[name] = fn.file
View
6 mtp.go
@@ -317,3 +317,9 @@ func (d *File) Filetype() int {
func (d *File) Name() string {
return C.GoString(d.filename)
}
+
+func (f *File) SetName(n string) {
+ old := f.filename
+ C.free(unsafe.Pointer(old))
+ f.filename = C.CString(n)
+}
View
6 test.sh
@@ -20,6 +20,10 @@ test $(cat "$root/mtpfs-test/test.txt") == "hello"
touch "$root/mtpfs-test/test.txt"
echo something else > "$root/mtpfs-test/test.txt"
+# can't send zero bytes file.
+! touch "$root/mtpfs-test/zerobytes.txt"
+rm "$root/mtpfs-test/zerobytes.txt"
+
mv "$root/mtpfs-test/test.txt" "$root/mtpfs-test/test2.txt"
! test -f "$root/mtpfs-test/test.txt"
test -f "$root/mtpfs-test/test2.txt"
@@ -41,5 +45,5 @@ test -d "$root/mtpfs-test/create"
test -f "$root/mtpfs-test/test2.txt"
test -f "$root/mtpfs-test/dest.txt"
! test -f "$root/mtpfs-test/src.txt"
-
+! test -f "$root/mtpfs-test/zerobytes.txt"
fusermount -u $mount
Please sign in to comment.
Something went wrong with that request. Please try again.