func (f *fs) handleRemove(r *fuse.RemoveRequest) { // TODO: Handle dir deletions correctly log.Println("Inside handleRemove") log.Println(r) _, err := f.rpc.api.Remove(f.getContext(), &pb.RemoveRequest{Parent: uint64(r.Node), Name: r.Name}) if err != nil { log.Fatalf("Failed to delete file: %v", err) } r.Respond() }
// Removes a file named req.Name from dir if it exists func (dir *Directory) Remove(req *fuse.RemoveRequest, intr fs.Intr) fuse.Error { filesystem.Lock(dir) defer filesystem.Unlock(dir) util.P_out(req.String()) if _, ok := dir.children[req.Name]; ok { dir.removeChild(req.Name) dir.dirty = true return nil } return fuse.ENOENT }
// Removes the inode described by req.Header.Node (doubles as rmdir) // Nota bene: this simply moves files into the Google Drive "Trash", it does not // delete them permanently. // Nota bene: there is no check preventing the removal of a directory which // contains files. func (sc *serveConn) remove(req *fuse.RemoveRequest) { if *readOnly { req.RespondError(fuse.EPERM) return } // TODO: if allow_other, require uid == invoking uid to allow writes // TODO: consider disallowing deletion of directories with contents.. but what error? pInode := uint64(req.Header.Node) parent, err := sc.db.FileByInode(pInode) if err != nil { debug.Printf("failed to get parent file: %v", err) req.RespondError(fuse.EIO) return } for _, cInode := range parent.Children { child, err := sc.db.FileByInode(cInode) if err != nil { debug.Printf("failed to get child file: %v", err) } if child.Title == req.Name { sc.service.Files.Delete(child.Id).Do() sc.db.RemoveFileById(child.Id, nil) req.Respond() return } } req.RespondError(fuse.ENOENT) }