Documentation
¶
Overview ¶
Package fs implements cross-platform file system capabilities.
Index ¶
- func BaseNameWithoutExt(filename string) string
- func Copy(src, dest string) error
- func LocateFile(protofile string, protodirs []string) (string, error)
- func Move(src, dst string) error
- func PrepareOutputdir(outputdir string) (err error)
- func Rename(src, dst string) error
- func UniqFilePath(dirs []string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BaseNameWithoutExt ¶
BaseNameWithoutExt return basename without extension of `filename`, in which `filename` may contains directory.
func LocateFile ¶
LocateFile returns the absolute path of proto file.
To ensure that protofile can be found, protodirs needs to provide the parent path of protofile and cannot be the parent path's parent path.
func Move ¶
Move move `src` to `dest`
the behavior of fs.Move is consistent with bash shell `mv` command:
when move a file, actions are following: ------------------------------------------------------------------------------------------------ | No. | src existed | src type | dst existed | dst type | behavior | ------------------------------------------------------------------------------------------------ | 1 | False | - | - | - | error: No such file or directory | ------------------------------------------------------------------------------------------------ | 2 | True | File | False | - | if dir(dst) existed: | | | | | | | - Yes, is dir, mv `src` to dir(dst) | | | | | | | - Yes, not dir, err: Not a directory | | | | | | | - No, err: No such file or directory | ------------------------------------------------------------------------------------------------ | 3 | True | File | True | Folder | if dst/basename(src) existed: | | | | | | | - Yes, mv `src` to dst/basename(src) | | | | | | | - No, mv `src` to dst/basename(src) | ------------------------------------------------------------------------------------------------ | 4 | True | File | True | File | mv `src` to dst | ------------------------------------------------------------------------------------------------
when move a directory, actions are following: ------------------------------------------------------------------------------------------------ | 5 | True | Folder | False | - | if dir(dst) existed: | | | | | | | - Yes, is dir, mv `src` to dir(dst) | | | | | | | - Yes, not dir, err: File Exists | | | | | | | - No, err: No such file or directory | ------------------------------------------------------------------------------------------------ | 6 | True | Folder | True | File | error: File Already Existed | ------------------------------------------------------------------------------------------------ | 7 | True | Folder | True | Folder | t = dst/basename(src), if t existed: | | | | | | | - Yes, t empty, mv src to t | | | | | | | - t notempty, err: t Not empty | | | | | | | - No, mv src to t | ------------------------------------------------------------------------------------------------
Why keep the behavior consistent? It makes the usage much more friendly when it behaves as users expected.
func PrepareOutputdir ¶
PrepareOutputdir create outputdir if it doesn't exist, return error if `outputdir` existed while it is not a directory, return error if any other error occurs.
func Rename ¶
Rename fs.Rename is just a wrapper of syscall rename, it may fail if renamimg across different devices, so we must provide a solution like: copy(src,dst)+rm(dst).
func UniqFilePath ¶
UniqFilePath is used to deduplicate file paths in a slice.
Types ¶
This section is empty.