fspath

package
v1.56.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 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 added in v1.6.1

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 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 added in v1.55.0

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 added in v1.55.0

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