| 1 | // Symlink node for the /ipns FUSE mount. go-fuse only builds on linux, darwin, and freebsd. |
| 2 | //go:build (linux || darwin || freebsd) && !nofuse |
| 3 | |
| 4 | package ipns |
| 5 | |
| 6 | import ( |
| 7 | "context" |
| 8 | "syscall" |
| 9 | |
| 10 | "github.com/hanwen/go-fuse/v2/fs" |
| 11 | "github.com/hanwen/go-fuse/v2/fuse" |
| 12 | ) |
| 13 | |
| 14 | type Link struct { |
| 15 | fs.Inode |
| 16 | Target string |
| 17 | } |
| 18 | |
| 19 | func (l *Link) Getattr(_ context.Context, _ fs.FileHandle, out *fuse.AttrOut) syscall.Errno { |
| 20 | log.Debug("Link attr.") |
| 21 | out.Attr.Mode = 0o555 |
| 22 | return 0 |
| 23 | } |
| 24 | |
| 25 | func (l *Link) Readlink(_ context.Context) ([]byte, syscall.Errno) { |
| 26 | log.Debugf("ReadLink: %s", l.Target) |
| 27 | return []byte(l.Target), 0 |
| 28 | } |
| 29 | |
| 30 | var ( |
| 31 | _ fs.NodeGetattrer = (*Link)(nil) |
| 32 | _ fs.NodeReadlinker = (*Link)(nil) |
| 33 | ) |