mirror of
https://github.com/fiatjaf/nak.git
synced 2025-08-13 06:20:47 -04:00
fs: logging and proper (?) handling of context passing (basically now we ignore the context given to us by the fuse library because they're weird).
This commit is contained in:
2
fs.go
2
fs.go
@@ -42,7 +42,7 @@ var fsCmd = &cli.Command{
|
||||
}
|
||||
|
||||
root := nostrfs.NewNostrRoot(
|
||||
ctx,
|
||||
context.WithValue(ctx, "log", log),
|
||||
sys,
|
||||
keyer.NewReadOnlyUser(c.String("pubkey")),
|
||||
mountpoint,
|
||||
|
@@ -30,7 +30,7 @@ type EntityDir struct {
|
||||
|
||||
var _ = (fs.NodeGetattrer)((*EntityDir)(nil))
|
||||
|
||||
func (e *EntityDir) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
|
||||
func (e *EntityDir) Getattr(_ context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
|
||||
publishedAt := uint64(e.evt.CreatedAt)
|
||||
out.Ctime = publishedAt
|
||||
|
||||
@@ -67,6 +67,8 @@ func CreateEntityDir(
|
||||
extension string,
|
||||
event *nostr.Event,
|
||||
) *fs.Inode {
|
||||
log := ctx.Value("log").(func(msg string, args ...any))
|
||||
|
||||
h := parent.EmbeddedInode().NewPersistentInode(
|
||||
ctx,
|
||||
&EntityDir{ctx: ctx, wd: wd, evt: event},
|
||||
@@ -179,14 +181,17 @@ func CreateEntityDir(
|
||||
defer cancel()
|
||||
r, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
if err != nil {
|
||||
log("failed to load image %s: %s\n", url, err)
|
||||
return nil, 0
|
||||
}
|
||||
resp, err := http.DefaultClient.Do(r)
|
||||
if err != nil {
|
||||
log("failed to load image %s: %s\n", url, err)
|
||||
return nil, 0
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 300 {
|
||||
log("failed to load image %s: %s\n", url, err)
|
||||
return nil, 0
|
||||
}
|
||||
w := &bytes.Buffer{}
|
||||
|
@@ -31,7 +31,7 @@ type EventDir struct {
|
||||
|
||||
var _ = (fs.NodeGetattrer)((*EventDir)(nil))
|
||||
|
||||
func (e *EventDir) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
|
||||
func (e *EventDir) Getattr(_ context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
|
||||
out.Mtime = uint64(e.evt.CreatedAt)
|
||||
return fs.OK
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ func NewNostrRoot(ctx context.Context, sys *sdk.System, user nostr.User, mountpo
|
||||
}
|
||||
}
|
||||
|
||||
func (r *NostrRoot) OnAdd(context.Context) {
|
||||
func (r *NostrRoot) OnAdd(_ context.Context) {
|
||||
if r.rootPubKey == "" {
|
||||
return
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func (r *NostrRoot) OnAdd(context.Context) {
|
||||
), true)
|
||||
}
|
||||
|
||||
func (r *NostrRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
|
||||
func (r *NostrRoot) Lookup(_ context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
|
||||
out.SetEntryTimeout(time.Minute * 5)
|
||||
|
||||
child := r.GetChild(name)
|
||||
@@ -84,8 +84,8 @@ func (r *NostrRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut)
|
||||
return child, fs.OK
|
||||
}
|
||||
|
||||
if pp, err := nip05.QueryIdentifier(ctx, name); err == nil {
|
||||
npubdir := CreateNpubDir(ctx, r.sys, r, r.wd, *pp)
|
||||
if pp, err := nip05.QueryIdentifier(r.ctx, name); err == nil {
|
||||
npubdir := CreateNpubDir(r.ctx, r.sys, r, r.wd, *pp)
|
||||
return npubdir, fs.OK
|
||||
}
|
||||
|
||||
@@ -96,10 +96,10 @@ func (r *NostrRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut)
|
||||
|
||||
switch p := pointer.(type) {
|
||||
case nostr.ProfilePointer:
|
||||
npubdir := CreateNpubDir(ctx, r.sys, r, r.wd, p)
|
||||
npubdir := CreateNpubDir(r.ctx, r.sys, r, r.wd, p)
|
||||
return npubdir, fs.OK
|
||||
case nostr.EventPointer:
|
||||
eventdir, err := FetchAndCreateEventDir(ctx, r, r.wd, r.sys, p)
|
||||
eventdir, err := FetchAndCreateEventDir(r.ctx, r, r.wd, r.sys, p)
|
||||
if err != nil {
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ var (
|
||||
_ = (fs.NodeGetattrer)((*ViewDir)(nil))
|
||||
)
|
||||
|
||||
func (n *ViewDir) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
|
||||
func (n *ViewDir) Getattr(_ context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
|
||||
now := nostr.Now()
|
||||
if n.filter.Until != nil {
|
||||
now = *n.filter.Until
|
||||
@@ -39,7 +39,7 @@ func (n *ViewDir) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOu
|
||||
return fs.OK
|
||||
}
|
||||
|
||||
func (n *ViewDir) Opendir(ctx context.Context) syscall.Errno {
|
||||
func (n *ViewDir) Opendir(_ context.Context) syscall.Errno {
|
||||
if n.fetched.CompareAndSwap(true, true) {
|
||||
return fs.OK
|
||||
}
|
||||
@@ -52,8 +52,8 @@ func (n *ViewDir) Opendir(ctx context.Context) syscall.Errno {
|
||||
aMonthAgo := now - 30*24*60*60
|
||||
n.filter.Since = &aMonthAgo
|
||||
|
||||
for ie := range n.sys.Pool.FetchMany(ctx, n.relays, n.filter, nostr.WithLabel("nakfs")) {
|
||||
basename, inode := n.create(ctx, n, ie.Event)
|
||||
for ie := range n.sys.Pool.FetchMany(n.ctx, n.relays, n.filter, nostr.WithLabel("nakfs")) {
|
||||
basename, inode := n.create(n.ctx, n, ie.Event)
|
||||
n.AddChild(basename, inode, true)
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ func (n *ViewDir) Opendir(ctx context.Context) syscall.Errno {
|
||||
filter.Until = &aMonthAgo
|
||||
|
||||
n.AddChild("@previous", n.NewPersistentInode(
|
||||
ctx,
|
||||
n.ctx,
|
||||
&ViewDir{
|
||||
ctx: n.ctx,
|
||||
sys: n.sys,
|
||||
@@ -72,8 +72,8 @@ func (n *ViewDir) Opendir(ctx context.Context) syscall.Errno {
|
||||
fs.StableAttr{Mode: syscall.S_IFDIR},
|
||||
), true)
|
||||
} else {
|
||||
for ie := range n.sys.Pool.FetchMany(ctx, n.relays, n.filter, nostr.WithLabel("nakfs")) {
|
||||
basename, inode := n.create(ctx, n, ie.Event)
|
||||
for ie := range n.sys.Pool.FetchMany(n.ctx, n.relays, n.filter, nostr.WithLabel("nakfs")) {
|
||||
basename, inode := n.create(n.ctx, n, ie.Event)
|
||||
n.AddChild(basename, inode, true)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user