58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package nas
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// localConnector handles destinations that are already part of the host
|
|
// filesystem: a plain output directory, or — the normal arrangement on Linux —
|
|
// an SMB/NFS share mounted by fstab, autofs or systemd before the recorder
|
|
// starts. There is nothing to connect, but there is something to check.
|
|
type localConnector struct {
|
|
goos string
|
|
}
|
|
|
|
func (c *localConnector) Name() string { return "local" }
|
|
|
|
func (c *localConnector) Attach(_ context.Context, loc Location, _ NASConfig) (Attachment, error) {
|
|
if err := c.validate(loc.Raw); err != nil {
|
|
return Attachment{}, err
|
|
}
|
|
|
|
return Attachment{
|
|
BasePath: filepath.Clean(loc.Raw),
|
|
Notes: []string{"local or already-mounted path (no network authentication)"},
|
|
}, nil
|
|
}
|
|
|
|
func (c *localConnector) Detach(context.Context, Attachment) error { return nil }
|
|
|
|
// validate rejects a Windows-shaped path on a non-Windows host. This looks
|
|
// pedantic and is not: backslashes and colons are legal characters in Linux
|
|
// filenames, so a stray C:\data or \\server\share would be created verbatim as
|
|
// a local directory. Transfers would report success, cleanup would delete the
|
|
// local originals, and nothing would ever reach the NAS.
|
|
func (c *localConnector) validate(path string) error {
|
|
if c.goos == "windows" {
|
|
return nil
|
|
}
|
|
|
|
if driveLetter.MatchString(path) {
|
|
return fmt.Errorf(
|
|
"%q is a Windows drive path but this host is %s; set NAS_OUTPUT_PATH to a mount point such as /mnt/nas/streams",
|
|
path, c.goos)
|
|
}
|
|
|
|
if strings.Contains(path, `\`) {
|
|
return fmt.Errorf(
|
|
"%q contains backslashes but this host is %s, where they are ordinary filename characters rather than separators; "+
|
|
"set NAS_OUTPUT_PATH to a mount point such as /mnt/nas/streams, or to \\\\server\\share\\folder to have the share resolved automatically",
|
|
path, c.goos)
|
|
}
|
|
|
|
return nil
|
|
}
|