fspath

package
v0.0.0-...-1dc401f Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package fspath contains routines for fspath manipulation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckConfigName

func CheckConfigName(configName string) error

CheckConfigName returns an error if configName is invalid

func JoinRootPath

func JoinRootPath(remote, filePath string) string

JoinRootPath joins filePath onto remote

If the remote has a leading "//" this is preserved to allow Windows network paths to be used as remotes.

If filePath is empty then remote will be returned.

If the path contains \ these will be converted to / on Windows.

func MakeConfigName

func MakeConfigName(name string) string

MakeConfigName makes an input into something legal to be used as a config name. Returns a string where any sequences of illegal characters are replaced with a single underscore. If the input is already valid as a config name, it is returned unchanged. If the input is an empty string, a single underscore is returned.

func Split

func Split(remote string) (parent string, leaf string, err error)

Split splits a remote into a parent and a leaf

if it returns leaf as an empty string then remote is a directory

if it returns parent as an empty string then that means the current directory

The returned values have the property that parent + leaf == remote (except under Windows where \ will be translated into /)

func SplitFs

func SplitFs(remote string) (remoteName string, remotePath string, err error)

SplitFs splits a remote a remoteName and an remotePath.

SplitFs("remote:path/to/file") -> ("remote:", "path/to/file") SplitFs("/to/file") -> ("", "/to/file")

If it returns remoteName as "" then remotePath is a local path

The returned values have the property that remoteName + remotePath == remote (except under Windows where \ will be translated into /)

Types

type Parsed

type Parsed struct {
	Name         string           // Just the name of the config: "remote" or ":backend"
	ConfigString string           // The whole config string: "remote:" or ":backend,value=6:"
	Path         string           // The file system path, may be empty
	Config       configmap.Simple // key/value config parsed out of ConfigString may be nil
}

Parsed is returned from Parse with the results of the connection string decomposition

If Name is "" then it is a local path in Path

Note that ConfigString + ":" + Path is equal to the input of Parse except that Path may have had \ converted to /

func Parse

func Parse(path string) (parsed Parsed, err error)

Parse deconstructs a path into a Parsed structure

If the path is a local path then parsed.Name will be returned as "".

So "remote:path/to/dir" will return Parsed{Name:"remote", Path:"path/to/dir"}, and "/path/to/local" will return Parsed{Name:"", Path:"/path/to/local"}

Note that this will turn \ into / in the fsPath on Windows

An error may be returned if the remote name has invalid characters or the parameters are invalid or the path is empty.

Jump to

Keyboard shortcuts

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