diff --git a/fs.go b/fs.go index 1f7f30c..ba80089 100644 --- a/fs.go +++ b/fs.go @@ -13,7 +13,6 @@ import ( "fiatjaf.com/nostr" "fiatjaf.com/nostr/keyer" "github.com/fatih/color" - "github.com/fiatjaf/nak/nostrfs" "github.com/urfave/cli/v3" "github.com/winfsp/cgofuse/fuse" ) @@ -63,7 +62,7 @@ var fsCmd = &cli.Command{ apat = time.Hour * 24 * 365 * 3 } - root := nostrfs.NewNostrRoot( + root := NewFSRoot( context.WithValue( context.WithValue( ctx, @@ -74,7 +73,7 @@ var fsCmd = &cli.Command{ sys, kr, mountpoint, - nostrfs.Options{ + FSOptions{ AutoPublishNotesTimeout: apnt, AutoPublishArticlesTimeout: apat, }, @@ -83,12 +82,12 @@ var fsCmd = &cli.Command{ // create the server log("- mounting at %s... ", color.HiCyanString(mountpoint)) - // Create cgofuse host + // create cgofuse host host := fuse.NewFileSystemHost(root) host.SetCapReaddirPlus(true) host.SetUseIno(true) - // Mount the filesystem + // mount the filesystem mountArgs := []string{"-s", mountpoint} if isVerbose { mountArgs = append([]string{"-d"}, mountArgs...) diff --git a/fs_other.go b/fs_other.go index ccc2894..fe9c244 100644 --- a/fs_other.go +++ b/fs_other.go @@ -15,6 +15,6 @@ var fsCmd = &cli.Command{ Description: `doesn't work on Windows and OpenBSD.`, DisableSliceFlagSeparator: true, Action: func(ctx context.Context, c *cli.Command) error { - return fmt.Errorf("this doesn't work on Windows and OpenBSD.") + return fmt.Errorf("this doesn't work on OpenBSD.") }, } diff --git a/nostrfs/root.go b/fs_root.go similarity index 99% rename from nostrfs/root.go rename to fs_root.go index a76f426..f61ee94 100644 --- a/nostrfs/root.go +++ b/fs_root.go @@ -1,8 +1,8 @@ -package nostrfs +package main import ( "context" - "encoding/json" + stdjson "encoding/json" "fmt" "net/http" "path/filepath" @@ -718,7 +718,7 @@ func (r *FSRoot) createEventDirLocked(name string, pointer nostr.EventPointer) b dirNode.children["content."+ext] = contentNode // add event.json - eventJSON, _ := json.MarshalIndent(evt, "", " ") + eventJSON, _ := stdjson.MarshalIndent(evt, "", " ") eventJSONPath := dirPath + "/event.json" eventJSONNode := &FSNode{ ino: r.nextIno, diff --git a/fs_windows.go b/fs_windows.go index 8dfcc15..d1dc1a3 100644 --- a/fs_windows.go +++ b/fs_windows.go @@ -12,7 +12,6 @@ import ( "fiatjaf.com/nostr" "fiatjaf.com/nostr/keyer" "github.com/fatih/color" - "github.com/fiatjaf/nak/nostrfs" "github.com/urfave/cli/v3" "github.com/winfsp/cgofuse/fuse" ) @@ -62,7 +61,7 @@ var fsCmd = &cli.Command{ apat = time.Hour * 24 * 365 * 3 } - root := nostrfs.NewNostrRoot( + root := NewFSRoot( context.WithValue( context.WithValue( ctx, @@ -73,7 +72,7 @@ var fsCmd = &cli.Command{ sys, kr, mountpoint, - nostrfs.Options{ + FSOptions{ AutoPublishNotesTimeout: apnt, AutoPublishArticlesTimeout: apat, }, @@ -82,37 +81,37 @@ var fsCmd = &cli.Command{ // create the server log("- mounting at %s... ", color.HiCyanString(mountpoint)) - // Create cgofuse host + // create cgofuse host host := fuse.NewFileSystemHost(root) host.SetCapReaddirPlus(true) host.SetUseIno(true) - // Mount the filesystem - Windows/WinFsp version - // Based on rclone cmount implementation + // mount the filesystem - Windows/WinFsp version + // based on rclone cmount implementation mountArgs := []string{ "-o", "uid=-1", "-o", "gid=-1", "--FileSystemName=nak", } - // Check if mountpoint is a drive letter or directory + // check if mountpoint is a drive letter or directory isDriveLetter := len(mountpoint) == 2 && mountpoint[1] == ':' if !isDriveLetter { - // WinFsp primarily supports drive letters on Windows - // Directory mounting may not work reliably + // winFsp primarily supports drive letters on Windows + // directory mounting may not work reliably log("WARNING: directory mounting may not work on Windows (WinFsp limitation)\n") log(" consider using a drive letter instead (e.g., 'nak fs Z:')\n") - // For directory mounts, follow rclone's approach: - // 1. Check that mountpoint doesn't already exist + // for directory mounts, follow rclone's approach: + // 1. check that mountpoint doesn't already exist if _, err := os.Stat(mountpoint); err == nil { return fmt.Errorf("mountpoint path already exists: %s (must not exist before mounting)", mountpoint) } else if !os.IsNotExist(err) { return fmt.Errorf("failed to check mountpoint: %w", err) } - // 2. Check that parent directory exists + // 2. check that parent directory exists parent := filepath.Join(mountpoint, "..") if _, err := os.Stat(parent); err != nil { if os.IsNotExist(err) { @@ -121,7 +120,7 @@ var fsCmd = &cli.Command{ return fmt.Errorf("failed to check parent directory: %w", err) } - // 3. Use network mode for directory mounts + // 3. use network mode for directory mounts mountArgs = append(mountArgs, "--VolumePrefix=\\nak\\"+filepath.Base(mountpoint)) } @@ -132,7 +131,6 @@ var fsCmd = &cli.Command{ log("ok.\n") - // Mount in main thread like hellofs if !host.Mount("", mountArgs) { return fmt.Errorf("failed to mount filesystem") }