Skip to content
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
12 changes: 11 additions & 1 deletion fsimpl/localfs/localfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package localfs
import (
"os"
"path"
"path/filepath"

"github.com/hugelgupf/p9/fsimpl/templatefs"
"github.com/hugelgupf/p9/internal"
Expand Down Expand Up @@ -267,7 +268,7 @@ func (l *Local) Renamed(parent p9.File, newName string) {
// SetAttr implements p9.File.SetAttr.
func (l *Local) SetAttr(valid p9.SetAttrMask, attr p9.SetAttr) error {
// When truncate(2) is called on Linux, Linux will try to set time & size. Fake it. Sorry.
supported := p9.SetAttrMask{Size: true, MTime: true, CTime: true}
supported := p9.SetAttrMask{Size: true, MTime: true, CTime: true, ATime: true}
if !valid.IsSubsetOf(supported) {
return linux.ENOSYS
}
Expand All @@ -279,3 +280,12 @@ func (l *Local) SetAttr(valid p9.SetAttrMask, attr p9.SetAttr) error {
}
return nil
}

// UnlinkAt implements p9.File.UnlinkAt
func (l *Local) UnlinkAt(name string, flags uint32) error {
// Construct the full path
fullPath := filepath.Join(l.path, name)

// Remove the file or directory
return os.Remove(fullPath)
}
2 changes: 2 additions & 0 deletions fsimpl/localfs/localfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ func TestLocalFS(t *testing.T) {
defer os.RemoveAll(tempDir)

test.TestFile(t, Attacher(tempDir))
test.TestReadOnlyFS(t, Attacher(tempDir))
test.TestReadWriteFS(t, Attacher(tempDir))
}
30 changes: 30 additions & 0 deletions fsimpl/test/filetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,33 @@ func testSameFile(t *testing.T, f1, f2 p9.File) {
t.Errorf("Attributes of same files do not match: %v and %v", f1Attr, f2Attr)
}
}

func TestReadWriteFS(t *testing.T, attach p9.Attacher) {
root, err := attach.Attach()
if err != nil {
t.Fatalf("Failed to attach to %v: %v", attach, err)
}
defer root.Close()

// Create a dummy file to unlink
const dummyFileName = "dummy_file.txt"
f, _, _, err := root.Create(dummyFileName, p9.ReadWrite, 0666, p9.NoUID, p9.NoGID)
if err != nil {
t.Fatalf("Create failed: %v", err)
}
f.Close()

// Attempt to unlink the file
if err := root.UnlinkAt(dummyFileName, 0); err != nil {
t.Errorf("Unlinkat failed: %v", err)
}
// Check that it does not exist anymore
dirents, err := readdir(root)
if err != nil {
t.Fatal(err)
}
file2dirent := dirents.Find(dummyFileName)
if file2dirent != nil {
t.Errorf("Dirents(%v).Find(file2) = %v, but should be nil", dirents, file2dirent)
}
}