rename Copy => CopyAll, update docs

This commit is contained in:
AJ ONeal 2020-10-23 15:38:54 -06:00
parent 93990f5db8
commit 27eee51fbe
3 changed files with 37 additions and 9 deletions

View File

@ -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), [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, 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 ```go
httpfs := http.Dir("/tmp/public/") httpfs := http.Dir("/tmp/public/")
vfs := vfscopy.NewVFS(httpfs) 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) 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 ## Test
```bash ```bash

View File

@ -13,8 +13,8 @@ const (
tmpPermissionForDirectory = os.FileMode(0755) tmpPermissionForDirectory = os.FileMode(0755)
) )
// Copy copies src to dest, doesn't matter if src is a directory or a file. // CopyAll 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 { func CopyAll(vfs FileSystem, src, dest string, opt ...Options) error {
// FYI: os.Open does a proper lstat // FYI: os.Open does a proper lstat
f, err := vfs.Open(src) f, err := vfs.Open(src)
if err != nil { if err != nil {

View File

@ -26,7 +26,7 @@ func TestNativeRecursiveCopy(t *testing.T) {
_ = os.RemoveAll(tmpDir) _ = os.RemoveAll(tmpDir)
}() }()
if err := Copy(vfs, ".", tmpDir, opts); nil != err { if err := CopyAll(vfs, ".", tmpDir, opts); nil != err {
t.Errorf("error: %v", err) t.Errorf("error: %v", err)
return return
} }
@ -48,7 +48,7 @@ func TestVFSRecursiveCopy(t *testing.T) {
_ = os.RemoveAll(tmpDir) _ = 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) t.Errorf("copy error: %v", err)
return return
} }