2020-10-23 21:38:54 +00:00
|
|
|
# [vfscopy](https://git.rootprojects.org/root/vfscopy)
|
2020-10-23 20:29:09 +00:00
|
|
|
|
2020-10-23 21:38:54 +00:00
|
|
|
Recursively copy a Virtual FileSystem, such as
|
2020-10-23 20:29:09 +00:00
|
|
|
[http.FileSystem](https://golang.org/pkg/net/http/#FileSystem),
|
2020-10-23 21:38:54 +00:00
|
|
|
to a native file system destination.
|
2020-10-23 20:29:09 +00:00
|
|
|
|
2020-10-23 21:30:03 +00:00
|
|
|
Works with any file system that implements http.FileSystem,
|
2020-10-23 21:38:54 +00:00
|
|
|
including `vfsgen`, `fileb0x`, `gobindata` and most others.
|
|
|
|
|
|
|
|
## Example: native file system (os)
|
2020-10-23 21:30:03 +00:00
|
|
|
|
2020-10-23 20:29:09 +00:00
|
|
|
```go
|
|
|
|
httpfs := http.Dir("/tmp/public/")
|
|
|
|
vfs := vfscopy.NewVFS(httpfs)
|
|
|
|
|
2020-10-23 21:38:54 +00:00
|
|
|
if err := vfscopy.CopyAll(vfs, ".", "/tmp/dst/"); nil != err {
|
2020-10-23 20:29:09 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "couldn't copy vfs: %v\n", err)
|
|
|
|
}
|
|
|
|
```
|
2020-10-23 21:21:19 +00:00
|
|
|
|
2020-10-23 21:38:54 +00:00
|
|
|
## 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.")
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-10-23 21:21:19 +00:00
|
|
|
## Test
|
|
|
|
|
|
|
|
```bash
|
2020-10-23 21:30:03 +00:00
|
|
|
# Generate the test virtual file system
|
2020-10-23 21:21:19 +00:00
|
|
|
go generate ./...
|
2020-10-23 21:30:03 +00:00
|
|
|
|
|
|
|
# Run the tests
|
2020-10-23 21:21:19 +00:00
|
|
|
go test ./...
|
|
|
|
```
|
2020-10-23 21:30:03 +00:00
|
|
|
|
|
|
|
# License
|
|
|
|
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
|
|
|
We used the recursive native file system copy implementation at
|
|
|
|
https://github.com/otiai10/copy as a starting point and added
|
|
|
|
virtual file system support.
|