Extract files
This commit is contained in:
parent
aca98e2d2a
commit
a25e9930f5
1 changed files with 23 additions and 2 deletions
25
command.go
25
command.go
|
@ -4,6 +4,7 @@ import(
|
|||
"log"
|
||||
"os"
|
||||
"io"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func cmdHead(config *configCollect) {
|
||||
|
@ -53,6 +54,7 @@ func cmdCpFile(config *configCollect) {
|
|||
|
||||
file, err := os.Create(config.Dest)
|
||||
if err != nil { log.Fatal(err) }
|
||||
defer file.Close()
|
||||
written, err := io.Copy(file, en)
|
||||
if err != nil { log.Fatal(err) }
|
||||
if uint64(written) != en.Elem.FileSize {
|
||||
|
@ -60,6 +62,25 @@ func cmdCpFile(config *configCollect) {
|
|||
}
|
||||
}
|
||||
|
||||
func cmdCpDir(config *configCollect) {
|
||||
|
||||
type CopyWalker struct { }
|
||||
func (cw* CopyWalker) onDir(dn *DirNode) {
|
||||
err := os.MkdirAll(filepath.Join(dn.Config.Dest, dn.AbsolutePath), os.ModePerm)
|
||||
if err != nil { log.Fatal(err) }
|
||||
log.Println(dn.String())
|
||||
}
|
||||
func (cw* CopyWalker) onFile(fn *FileNode) {
|
||||
fn.Parse()
|
||||
file, err := os.Create(filepath.Join(fn.Config.Dest, fn.AbsolutePath))
|
||||
if err != nil { log.Fatal(err) }
|
||||
defer file.Close()
|
||||
written, err := io.Copy(file, fn)
|
||||
if err != nil { log.Fatal(err) }
|
||||
if uint64(written) != fn.Elem.FileSize {
|
||||
log.Fatal(written, "bytes written,", fn.Elem.FileSize, "bytes expected")
|
||||
}
|
||||
log.Println(fn.String())
|
||||
}
|
||||
func cmdCpDir(config *configCollect) {
|
||||
en := NewEntryNode(config)
|
||||
en.Walk(new(CopyWalker))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue