From 27eee51fbe09d36989129ce1b15e458f451d0e5f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 23 Oct 2020 15:38:54 -0600 Subject: [PATCH] rename Copy => CopyAll, update docs --- README.md | 38 +++++++++++++++++++++++++++++++++----- copy.go | 4 ++-- copy_test.go | 4 ++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index eed1b62..1525fdd 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,49 @@ -# vfscopy +# [vfscopy](https://git.rootprojects.org/root/vfscopy) -Copy a Virtual FileSystem, such as +Recursively copy a Virtual FileSystem, such as [http.FileSystem](https://golang.org/pkg/net/http/#FileSystem), -recursively to a native file system destination. +to a native file system destination. Works with any file system that implements http.FileSystem, -such as `vfsgen`, `fileb0x`, `gobindata`. +including `vfsgen`, `fileb0x`, `gobindata` and most others. + +## Example: native file system (os) ```go httpfs := http.Dir("/tmp/public/") vfs := vfscopy.NewVFS(httpfs) -if err := Copy(vfs, ".", "/tmp/dst/"); nil != err { +if err := vfscopy.CopyAll(vfs, ".", "/tmp/dst/"); nil != err { fmt.Fprintf(os.Stderr, "couldn't copy vfs: %v\n", err) } ``` +## Example: vfsgen + +**Note**: `vfsgen` does not support symlinks or file permissions. + +```go +package main + +import ( + "fmt" + + "git.rootprojects.org/root/vfscopy" + + // vfsgen-generated file system + "git.example.com/org/project/assets" +) + +func main() { + vfs := vfscopy.NewVFS(assets.Assets) + + if err := vfscopy.CopyAll(vfs, ".", "/tmp/dst/"); nil != err { + fmt.Fprintf(os.Stderr, "couldn't copy vfs: %v\n", err) + } + fmt.Println("Done.") +} +``` + ## Test ```bash diff --git a/copy.go b/copy.go index dab677e..d40dc7f 100644 --- a/copy.go +++ b/copy.go @@ -13,8 +13,8 @@ const ( tmpPermissionForDirectory = os.FileMode(0755) ) -// Copy copies src to dest, doesn't matter if src is a directory or a file. -func Copy(vfs FileSystem, src, dest string, opt ...Options) error { +// CopyAll copies src to dest, doesn't matter if src is a directory or a file. +func CopyAll(vfs FileSystem, src, dest string, opt ...Options) error { // FYI: os.Open does a proper lstat f, err := vfs.Open(src) if err != nil { diff --git a/copy_test.go b/copy_test.go index ff89909..99e60ce 100644 --- a/copy_test.go +++ b/copy_test.go @@ -26,7 +26,7 @@ func TestNativeRecursiveCopy(t *testing.T) { _ = os.RemoveAll(tmpDir) }() - if err := Copy(vfs, ".", tmpDir, opts); nil != err { + if err := CopyAll(vfs, ".", tmpDir, opts); nil != err { t.Errorf("error: %v", err) return } @@ -48,7 +48,7 @@ func TestVFSRecursiveCopy(t *testing.T) { _ = os.RemoveAll(tmpDir) }() - if err := Copy(vfs, ".", tmpDir, opts); nil != err { + if err := CopyAll(vfs, ".", tmpDir, opts); nil != err { t.Errorf("copy error: %v", err) return }