Extract files

This commit is contained in:
Quentin 2021-04-26 14:04:18 +02:00
parent aca98e2d2a
commit a25e9930f5
Signed by: quentin
GPG key ID: A98E9B769E4FF428

View file

@ -4,6 +4,7 @@ import(
"log" "log"
"os" "os"
"io" "io"
"path/filepath"
) )
func cmdHead(config *configCollect) { func cmdHead(config *configCollect) {
@ -53,6 +54,7 @@ func cmdCpFile(config *configCollect) {
file, err := os.Create(config.Dest) file, err := os.Create(config.Dest)
if err != nil { log.Fatal(err) } if err != nil { log.Fatal(err) }
defer file.Close()
written, err := io.Copy(file, en) written, err := io.Copy(file, en)
if err != nil { log.Fatal(err) } if err != nil { log.Fatal(err) }
if uint64(written) != en.Elem.FileSize { 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))
} }