Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vfs: Implement unlink #9

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions fuse/hanwen/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func (fs *FS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name string,
}

func (fs *FS) Forget(nodeid, nlookup uint64) {
fs.fs.DeleteInode(nodeid)
}

func (fs *FS) GetAttr(cancel <-chan struct{}, input *fuse.GetAttrIn, out *fuse.AttrOut) (code fuse.Status) {
Expand Down Expand Up @@ -237,7 +236,6 @@ func (fs *FS) Unlink(cancel <-chan struct{}, header *fuse.InHeader, name string)
zap.Error(err))
return fuse.EAGAIN
}

return fuse.OK
}

Expand Down
2 changes: 1 addition & 1 deletion vfs/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (dh *DirHandle) Next() (ino *Inode, err error) {
}

ino = newInode(dh.ino.ID, o)
err = dh.fs.SetInode(ino, time.Minute)
err = dh.fs.SetInode(ino, time.Hour)
if err != nil {
return
}
Expand Down
22 changes: 19 additions & 3 deletions vfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,19 @@ func NewFS(cfg *Config) (fs *FS, err error) {
}

func (fs *FS) Delete(parent uint64, name string) (err error) {
panic("implement me")
ino, err := fs.GetEntry(parent, name)
if err != nil {
return
}
err = fs.s.Delete(ino.Path)
if err != nil {
return
}
err = fs.DeleteInode(ino)
if err != nil {
return
}
return
}

func (fs *FS) DeleteDir(path string) (err error) {
Expand Down Expand Up @@ -145,8 +157,12 @@ func (fs *FS) GetInode(id uint64) (ino *Inode, err error) {
return
}

func (fs *FS) DeleteInode(id uint64) (err error) {
err = fs.meta.Delete(meta.InodeKey(id))
func (fs *FS) DeleteInode(ino *Inode) (err error) {
err = fs.meta.Delete(meta.InodeKey(ino.ID))
if err != nil {
return fmt.Errorf("del inode: %w", err)
}
err = fs.meta.Delete(meta.EntryKey(ino.ParentID, ino.Name))
if err != nil {
return fmt.Errorf("del inode: %w", err)
}
Expand Down