fs: move everything to the top-level directory.

This commit is contained in:
fiatjaf
2026-01-16 12:34:09 -03:00
parent 6dfbed4413
commit e838de9b72
4 changed files with 20 additions and 23 deletions

9
fs.go
View File

@@ -13,7 +13,6 @@ import (
"fiatjaf.com/nostr" "fiatjaf.com/nostr"
"fiatjaf.com/nostr/keyer" "fiatjaf.com/nostr/keyer"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/fiatjaf/nak/nostrfs"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
"github.com/winfsp/cgofuse/fuse" "github.com/winfsp/cgofuse/fuse"
) )
@@ -63,7 +62,7 @@ var fsCmd = &cli.Command{
apat = time.Hour * 24 * 365 * 3 apat = time.Hour * 24 * 365 * 3
} }
root := nostrfs.NewNostrRoot( root := NewFSRoot(
context.WithValue( context.WithValue(
context.WithValue( context.WithValue(
ctx, ctx,
@@ -74,7 +73,7 @@ var fsCmd = &cli.Command{
sys, sys,
kr, kr,
mountpoint, mountpoint,
nostrfs.Options{ FSOptions{
AutoPublishNotesTimeout: apnt, AutoPublishNotesTimeout: apnt,
AutoPublishArticlesTimeout: apat, AutoPublishArticlesTimeout: apat,
}, },
@@ -83,12 +82,12 @@ var fsCmd = &cli.Command{
// create the server // create the server
log("- mounting at %s... ", color.HiCyanString(mountpoint)) log("- mounting at %s... ", color.HiCyanString(mountpoint))
// Create cgofuse host // create cgofuse host
host := fuse.NewFileSystemHost(root) host := fuse.NewFileSystemHost(root)
host.SetCapReaddirPlus(true) host.SetCapReaddirPlus(true)
host.SetUseIno(true) host.SetUseIno(true)
// Mount the filesystem // mount the filesystem
mountArgs := []string{"-s", mountpoint} mountArgs := []string{"-s", mountpoint}
if isVerbose { if isVerbose {
mountArgs = append([]string{"-d"}, mountArgs...) mountArgs = append([]string{"-d"}, mountArgs...)

View File

@@ -15,6 +15,6 @@ var fsCmd = &cli.Command{
Description: `doesn't work on Windows and OpenBSD.`, Description: `doesn't work on Windows and OpenBSD.`,
DisableSliceFlagSeparator: true, DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { 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.")
}, },
} }

View File

@@ -1,8 +1,8 @@
package nostrfs package main
import ( import (
"context" "context"
"encoding/json" stdjson "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"path/filepath" "path/filepath"
@@ -718,7 +718,7 @@ func (r *FSRoot) createEventDirLocked(name string, pointer nostr.EventPointer) b
dirNode.children["content."+ext] = contentNode dirNode.children["content."+ext] = contentNode
// add event.json // add event.json
eventJSON, _ := json.MarshalIndent(evt, "", " ") eventJSON, _ := stdjson.MarshalIndent(evt, "", " ")
eventJSONPath := dirPath + "/event.json" eventJSONPath := dirPath + "/event.json"
eventJSONNode := &FSNode{ eventJSONNode := &FSNode{
ino: r.nextIno, ino: r.nextIno,

View File

@@ -12,7 +12,6 @@ import (
"fiatjaf.com/nostr" "fiatjaf.com/nostr"
"fiatjaf.com/nostr/keyer" "fiatjaf.com/nostr/keyer"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/fiatjaf/nak/nostrfs"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
"github.com/winfsp/cgofuse/fuse" "github.com/winfsp/cgofuse/fuse"
) )
@@ -62,7 +61,7 @@ var fsCmd = &cli.Command{
apat = time.Hour * 24 * 365 * 3 apat = time.Hour * 24 * 365 * 3
} }
root := nostrfs.NewNostrRoot( root := NewFSRoot(
context.WithValue( context.WithValue(
context.WithValue( context.WithValue(
ctx, ctx,
@@ -73,7 +72,7 @@ var fsCmd = &cli.Command{
sys, sys,
kr, kr,
mountpoint, mountpoint,
nostrfs.Options{ FSOptions{
AutoPublishNotesTimeout: apnt, AutoPublishNotesTimeout: apnt,
AutoPublishArticlesTimeout: apat, AutoPublishArticlesTimeout: apat,
}, },
@@ -82,37 +81,37 @@ var fsCmd = &cli.Command{
// create the server // create the server
log("- mounting at %s... ", color.HiCyanString(mountpoint)) log("- mounting at %s... ", color.HiCyanString(mountpoint))
// Create cgofuse host // create cgofuse host
host := fuse.NewFileSystemHost(root) host := fuse.NewFileSystemHost(root)
host.SetCapReaddirPlus(true) host.SetCapReaddirPlus(true)
host.SetUseIno(true) host.SetUseIno(true)
// Mount the filesystem - Windows/WinFsp version // mount the filesystem - Windows/WinFsp version
// Based on rclone cmount implementation // based on rclone cmount implementation
mountArgs := []string{ mountArgs := []string{
"-o", "uid=-1", "-o", "uid=-1",
"-o", "gid=-1", "-o", "gid=-1",
"--FileSystemName=nak", "--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] == ':' isDriveLetter := len(mountpoint) == 2 && mountpoint[1] == ':'
if !isDriveLetter { if !isDriveLetter {
// WinFsp primarily supports drive letters on Windows // winFsp primarily supports drive letters on Windows
// Directory mounting may not work reliably // directory mounting may not work reliably
log("WARNING: directory mounting may not work on Windows (WinFsp limitation)\n") 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") log(" consider using a drive letter instead (e.g., 'nak fs Z:')\n")
// For directory mounts, follow rclone's approach: // for directory mounts, follow rclone's approach:
// 1. Check that mountpoint doesn't already exist // 1. check that mountpoint doesn't already exist
if _, err := os.Stat(mountpoint); err == nil { if _, err := os.Stat(mountpoint); err == nil {
return fmt.Errorf("mountpoint path already exists: %s (must not exist before mounting)", mountpoint) return fmt.Errorf("mountpoint path already exists: %s (must not exist before mounting)", mountpoint)
} else if !os.IsNotExist(err) { } else if !os.IsNotExist(err) {
return fmt.Errorf("failed to check mountpoint: %w", 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, "..") parent := filepath.Join(mountpoint, "..")
if _, err := os.Stat(parent); err != nil { if _, err := os.Stat(parent); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
@@ -121,7 +120,7 @@ var fsCmd = &cli.Command{
return fmt.Errorf("failed to check parent directory: %w", err) 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)) mountArgs = append(mountArgs, "--VolumePrefix=\\nak\\"+filepath.Base(mountpoint))
} }
@@ -132,7 +131,6 @@ var fsCmd = &cli.Command{
log("ok.\n") log("ok.\n")
// Mount in main thread like hellofs
if !host.Mount("", mountArgs) { if !host.Mount("", mountArgs) {
return fmt.Errorf("failed to mount filesystem") return fmt.Errorf("failed to mount filesystem")
} }