Skip to content

Commit 666b906

Browse files
committed
proper directory listing with types
1 parent 620ee7f commit 666b906

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

fuse/ipns/ipns_unix.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,22 @@ func (s *Directory) Lookup(ctx context.Context, name string) (fs.Node, error) {
278278
func (dir *Directory) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
279279
var entries []fuse.Dirent
280280
for _, name := range dir.dir.List() {
281-
entries = append(entries, fuse.Dirent{Name: name, Type: fuse.DT_File})
281+
dirent := fuse.Dirent{Name: name}
282+
283+
// TODO: make dir.dir.List() return dirinfos
284+
child, err := dir.dir.Child(name)
285+
if err != nil {
286+
return nil, err
287+
}
288+
289+
switch child.Type() {
290+
case nsfs.TDir:
291+
dirent.Type = fuse.DT_Dir
292+
case nsfs.TFile:
293+
dirent.Type = fuse.DT_File
294+
}
295+
296+
entries = append(entries, dirent)
282297
}
283298

284299
if len(entries) > 0 {

ipnsfs/dir.go

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func (d *Directory) closeChild(name string) error {
105105
return d.parent.closeChild(d.name)
106106
}
107107

108+
func (d *Directory) Type() NodeType {
109+
return TDir
110+
}
111+
108112
func (d *Directory) childFile(name string) (*file, error) {
109113
fi, ok := d.files[name]
110114
if ok {

ipnsfs/file.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ type File interface {
1919
Seek(int64, int) (int64, error)
2020
Size() (int64, error)
2121
Flush() error
22-
GetNode() (*dag.Node, error)
2322
Truncate(int64) error
23+
FSNode
2424
}
2525

2626
type file struct {
@@ -107,6 +107,10 @@ func (fi *file) Truncate(size int64) error {
107107
return fi.mod.Truncate(size)
108108
}
109109

110+
func (fi *file) Type() NodeType {
111+
return TFile
112+
}
113+
110114
type readOnlyFile struct {
111115
*file
112116
}

ipnsfs/system.go

+8
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,16 @@ func (fs *Filesystem) GetRoot(name string) (*KeyRoot, error) {
8686
return nil, ErrNoSuch
8787
}
8888

89+
type NodeType int
90+
91+
const (
92+
TFile NodeType = iota
93+
TDir
94+
)
95+
8996
type FSNode interface {
9097
GetNode() (*dag.Node, error)
98+
Type() NodeType
9199
}
92100

93101
// KeyRoot represents the root of a filesystem tree pointed to by a given keypair

0 commit comments

Comments
 (0)