Compute directory size
This commit is contained in:
parent
ca13aaf50b
commit
0b4b735e46
7 changed files with 35 additions and 6 deletions
10
command.go
10
command.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import(
|
||||
"log"
|
||||
"code.cloudfoundry.org/bytefmt"
|
||||
)
|
||||
|
||||
func cmdHead(config *configCollect) {
|
||||
|
@ -29,7 +30,9 @@ func cmdHead(config *configCollect) {
|
|||
|
||||
func cmdLs(config *configCollect) {
|
||||
en := NewEntryNode(config)
|
||||
en.Walk(new(LsWalker))
|
||||
lw := new(LsWalker)
|
||||
en.Walk(lw)
|
||||
log.Println("Total size:", bytefmt.ByteSize(lw.TotalSize))
|
||||
}
|
||||
|
||||
func cmdInfo(config *configCollect) {
|
||||
|
@ -59,3 +62,8 @@ func cmdS3File(config *configCollect) {
|
|||
sw := NewS3Walker(config)
|
||||
sw.onFile(en)
|
||||
}
|
||||
|
||||
func cmdS3Del(config *configCollect) {
|
||||
sw := NewS3Walker(config)
|
||||
sw.onDelete()
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ type configCollect struct {
|
|||
Info bool `docopt:"info"`
|
||||
Cp bool `docopt:"cp"`
|
||||
S3 bool `docopt:"s3"`
|
||||
S3Del bool `docopt:"s3del"`
|
||||
Storage string `docopt:"--storage"`
|
||||
DirId string `docopt:"--dir"`
|
||||
FileId string `docopt:"--file"`
|
||||
|
|
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ module git.deuxfleurs.fr/quentin/seafile_recovery
|
|||
go 1.15
|
||||
|
||||
require (
|
||||
code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48
|
||||
github.com/aws/aws-sdk-go v1.38.25
|
||||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
|
||||
github.com/minio/minio-go/v7 v7.0.10
|
||||
|
|
2
go.sum
2
go.sum
|
@ -1,3 +1,5 @@
|
|||
code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48 h1:/EMHruHCFXR9xClkGV/t0rmHrdhX4+trQUcBqjwc9xE=
|
||||
code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc=
|
||||
github.com/aws/aws-sdk-go v1.38.25 h1:aNjeh7+MON05cZPtZ6do+KxVT67jPOSQXANA46gOQao=
|
||||
github.com/aws/aws-sdk-go v1.38.25/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
|
|
@ -2,10 +2,13 @@ package main
|
|||
|
||||
import ("log")
|
||||
|
||||
type LsWalker struct { }
|
||||
type LsWalker struct {
|
||||
TotalSize uint64
|
||||
}
|
||||
func (lw* LsWalker) onDir(dn *DirNode) {
|
||||
log.Println(dn.String())
|
||||
}
|
||||
func (lw* LsWalker) onFile(fn *FileNode) {
|
||||
lw.TotalSize += uint64(fn.Ent.Size)
|
||||
log.Println(fn.String())
|
||||
}
|
||||
|
|
15
s3_walker.go
15
s3_walker.go
|
@ -65,9 +65,9 @@ func (sw* S3Walker) onDir(dn *DirNode) {
|
|||
}
|
||||
func (sw* S3Walker) onFile(fn *FileNode) {
|
||||
fn.Parse()
|
||||
path := filepath.Join(sw.pathPrefix, fn.AbsolutePath)
|
||||
contentType := mime.TypeByExtension(filepath.Ext(path))
|
||||
info, err := sw.mc.PutObject(sw.ctx, sw.bucket, path, fn, int64(fn.Elem.FileSize), minio.PutObjectOptions{ ContentType: contentType })
|
||||
p := filepath.Join(sw.pathPrefix, fn.AbsolutePath)[1:]
|
||||
contentType := mime.TypeByExtension(filepath.Ext(p))
|
||||
info, err := sw.mc.PutObject(sw.ctx, sw.bucket, p, fn, int64(fn.Elem.FileSize), minio.PutObjectOptions{ ContentType: contentType })
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
} else if info.Size != int64(fn.Elem.FileSize) {
|
||||
|
@ -75,3 +75,12 @@ func (sw* S3Walker) onFile(fn *FileNode) {
|
|||
}
|
||||
log.Println(fn.String())
|
||||
}
|
||||
|
||||
func (sw* S3Walker) onDelete() {
|
||||
opts := minio.RemoveObjectOptions {}
|
||||
err := sw.mc.RemoveObject(context.Background(), sw.bucket, sw.pathPrefix, opts)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println(sw.pathPrefix)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ Usage:
|
|||
seafile_recovery [--storage=<sto>] ls <repoid> (--dir=<dirid> | --file=<fileid>)
|
||||
seafile_recovery [--storage=<sto>] cp <repoid> (--dir=<dirid> | --file=<fileid>) <dest>
|
||||
seafile_recovery [--storage=<sto>] s3 <repoid> (--dir=<dirid> | --file=<pathid>) <dest>
|
||||
seafile_recovery s3del <dest>
|
||||
seafile_recovery (-h | --help)
|
||||
|
||||
Options:
|
||||
|
@ -27,7 +28,9 @@ Options:
|
|||
if err != nil { log.Fatal(err) }
|
||||
opts.Bind(config)
|
||||
|
||||
if !config.S3Del {
|
||||
checkRootFolder(config.Storage)
|
||||
}
|
||||
rexists := repoExistsIn(config.Storage, config.RepoId)
|
||||
|
||||
if config.Head {
|
||||
|
@ -59,6 +62,8 @@ Options:
|
|||
} else {
|
||||
cmdS3File(config)
|
||||
}
|
||||
} else if config.S3Del{
|
||||
cmdS3Del(config)
|
||||
} else {
|
||||
log.Fatal("This command is not implemented")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue