Documentation
¶
Index ¶
- func Chroot(path string)
- func DirExists(filePath string) (bool, error)
- func FileExists(filePath string) (bool, error)
- func IsDir(path string) (bool, error)
- func RelativeToCurrentPath(path string) (string, error)
- func Root() fs.FS
- func SaveFile(src io.ReadCloser, dst string) error
- func SaveToDisk(fileTree fs.FS, root string) (err error)
- func Sha1(root fs.FS, path string) (string, error)
- func ShortenFileBase(baseDir, fullPath string) string
- func Tar(src fs.FS, dst string) error
- func Untar(src, dst string) (err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileExists ¶
func RelativeToCurrentPath ¶ added in v1.5.0
func SaveToDisk ¶ added in v1.4.0
SaveToDisk saves the file tree to disk with path root. file tree is a tree of files from disk, memory or any other places which implement fs.FS.
func ShortenFileBase ¶ added in v1.4.0
ShortenFileBase removes baseDir from fullPath (but keep the last element of baseDir). e.g. ShortenFileBase("a/b", "a/b/c.go") => "b/c.go"
Example ¶
package main
import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
"github.com/koderover/zadig/pkg/util/fs"
)
type testParams struct {
base, path, expectedPath string
}
var _ = Describe("Testing file", func() {
DescribeTable("Testing ShortenFileBase",
func(p testParams) {
path := fs.ShortenFileBase(p.base, p.path)
Expect(path).To(Equal(p.expectedPath))
},
Entry("short path", testParams{
base: "a",
path: "a/b/c.go",
expectedPath: "a/b/c.go",
}),
Entry("short path with '/'", testParams{
base: "a/",
path: "a/b/c.go",
expectedPath: "a/b/c.go",
}),
Entry("long path", testParams{
base: "a/b",
path: "a/b/c.go",
expectedPath: "b/c.go",
}),
Entry("long path with '/'", testParams{
base: "a/b/",
path: "a/b/c.go",
expectedPath: "b/c.go",
}),
Entry("longer path", testParams{
base: "a/d/b",
path: "a/d/b/c.go",
expectedPath: "b/c.go",
}),
Entry("empty path", testParams{
base: "",
path: "b/c.go",
expectedPath: "b/c.go",
}),
Entry("current path", testParams{
base: ".",
path: "b/c.go",
expectedPath: "b/c.go",
}),
Entry("root path", testParams{
base: "/",
path: "/b/c.go",
expectedPath: "b/c.go",
}),
)
})
func main() {
fmt.Println(fs.ShortenFileBase("a", "a/b/c.go"))
fmt.Println(fs.ShortenFileBase("a/", "a/b/c.go"))
fmt.Println(fs.ShortenFileBase("a/b", "a/b/c.go"))
fmt.Println(fs.ShortenFileBase("a/b/", "a/b/c.go"))
fmt.Println(fs.ShortenFileBase("a/d/b", "a/d/b/c.go"))
fmt.Println(fs.ShortenFileBase("", "b/c.go"))
fmt.Println(fs.ShortenFileBase(".", "b/c.go"))
fmt.Println(fs.ShortenFileBase("/", "/b/c.go"))
}
Output: a/b/c.go a/b/c.go b/c.go b/c.go b/c.go b/c.go b/c.go b/c.go
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.