fs

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 9 Imported by: 0

Documentation

Overview

Package fs implements cross-platform file system capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseNameWithoutExt

func BaseNameWithoutExt(filename string) string

BaseNameWithoutExt return basename without extension of `filename`, in which `filename` may contains directory.

func Copy

func Copy(src, dest string) error

Copy copies src to dest, doesn't matter if src is a directory or a file

func LocateFile

func LocateFile(protofile string, protodirs []string) (string, error)

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

func Move(src, dst string) error

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

func PrepareOutputdir(outputdir string) (err error)

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

func Rename(src, dst string) error

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).

see: https://groups.google.com/g/golang-dev/c/5w7Jmg_iCJQ

func UniqFilePath

func UniqFilePath(dirs []string) []string

UniqFilePath is used to deduplicate file paths in a slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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