cmdmount

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &command.C{
	Name: "mount",
	Usage: `<root-key>[/path] <mount-path> [--exec cmd args...]
@<file-key>[/path] <mount-path> [--exec cmd args...]`,

	Help: `Mount a file tree as a FUSE filesystem.

Mount a FUSE filesystem at the specified <mount-path> hosting the contents
of the specified FFS file. By default, the mounted filesystem is writable.
With --read-only, the filesystem is instead mounted as read-only.

If the file is based on a root key, then changes made while the filesystem
is mounted are flushed back to that root upon exit. If the --auto-flush flag
is set, changes are additionally flushed at the specified interval.

By default, the filesystem runs until the program is terminated by a signal
or the filesystem is unmounted (e.g., by calling umount).  With --exec, the
specified command and arguments are run as a subprocess with their initial
working directory set to the root of the mounted filesystem. In this mode,
the filesystem is automatically unmounted when the subprocess exits.
`,

	SetFlags: func(env *command.Env, fs *flag.FlagSet) {
		fs.BoolVar(&svc.ReadOnly, "read-only", false, "Mount the filesystem as read-only")
		fs.BoolVar(&svc.DebugLog, "debug-fuse", false, "PRIVATE:Enable FUSE debug logging (warning: prolific)")
		fs.DurationVar(&svc.AutoFlush, "auto-flush", 0, "Automatically flush the root at this interval")
		fs.BoolVar(&svc.Verbose, "v", false, "Enable verbose logging")
		fs.BoolVar(&svc.Exec, "exec", false, "Execute a command, then unmount and exit")
	},

	Run: command.Adapt(func(env *command.Env, rootKey, mountPath string, cmdArgs ...string) error {
		if !svc.Exec && len(cmdArgs) != 0 {
			return env.Usagef("extra arguments after command: %q", cmdArgs)
		}
		cfg := env.Config.(*config.Settings)
		return cfg.WithStore(env.Context(), func(s config.CAS) error {
			svc.MountPath = mountPath
			svc.RootKey = rootKey
			svc.Store = s
			svc.ExecArgs = cmdArgs
			ctx := env.Context()
			if err := svc.Init(ctx); err != nil {
				return err
			}

			if svc.ReadOnly {
				return svc.Run(ctx)
			}

			if err := svc.Run(ctx); err != nil {
				if key, err := svc.Path.Base.Flush(context.Background()); err == nil {
					fmt.Printf("state: %s\n", config.FormatKey(key))
				} else {
					log.Printf("WARNING: Flushing file state failed: %v", err)
				}
				return fmt.Errorf("filesystem failed: %w", err)
			}

			rk, err := svc.Path.Flush(context.Background())
			if err != nil {
				return fmt.Errorf("flush file data: %w", err)
			}
			fmt.Printf("flush: %s\n", config.FormatKey(rk))
			return nil
		})
	}),
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL