Use colors.
This commit is contained in:
parent
ae5736f21b
commit
054906472f
1 changed files with 13 additions and 10 deletions
|
@ -33,7 +33,7 @@ func NewRuspa(inode *INode, collect chan StatusReport) *Ruspa {
|
||||||
|
|
||||||
// Scava starts a worker on the given INode.
|
// Scava starts a worker on the given INode.
|
||||||
func (w *Ruspa) Scava(done chan StatusReport) {
|
func (w *Ruspa) Scava(done chan StatusReport) {
|
||||||
Console.Debugln("Scava: ", w.INode.Path)
|
Console.Debugln(Gray("Scava: ", w.INode.Path))
|
||||||
children, err := ls(w.INode.Path)
|
children, err := ls(w.INode.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Send <- StatusReport{path: w.INode.Path, err: err}
|
w.Send <- StatusReport{path: w.INode.Path, err: err}
|
||||||
|
@ -47,10 +47,10 @@ func (w *Ruspa) Scava(done chan StatusReport) {
|
||||||
w.INode.Children.Append(childINode)
|
w.INode.Children.Append(childINode)
|
||||||
switch {
|
switch {
|
||||||
case kind == FileType:
|
case kind == FileType:
|
||||||
Console.Debugln("[file]", w.INode.Path, " ~> ", childINode.Path)
|
Console.Debugln(Gray("[file]", w.INode.Path, " ~> ", childINode.Path))
|
||||||
w.Send <- StatusReport{path: childPath, size: size}
|
w.Send <- StatusReport{path: childPath, size: size}
|
||||||
case kind == DirType:
|
case kind == DirType:
|
||||||
Console.Debugln("[dir]", w.INode.Path, " ~> ", childINode.Path)
|
Console.Debugln(Gray("[dir]", w.INode.Path, " ~> ", childINode.Path))
|
||||||
cw := NewRuspa(childINode, w.Recv)
|
cw := NewRuspa(childINode, w.Recv)
|
||||||
w.Opened[childPath] = cw
|
w.Opened[childPath] = cw
|
||||||
go cw.Scava(w.Done)
|
go cw.Scava(w.Done)
|
||||||
|
@ -71,17 +71,17 @@ func (w *Ruspa) Ammucchia(done chan StatusReport) {
|
||||||
select {
|
select {
|
||||||
case report := <-w.Recv:
|
case report := <-w.Recv:
|
||||||
if report.err != nil {
|
if report.err != nil {
|
||||||
Console.Debugln(Red(report.err))
|
Console.Debugln(Gray(Red(report.err)))
|
||||||
}
|
}
|
||||||
if report.err == nil {
|
if report.err == nil {
|
||||||
w.INode.Size += report.size
|
w.INode.Size += report.size
|
||||||
}
|
}
|
||||||
case leaf := <-w.Done:
|
case leaf := <-w.Done:
|
||||||
Console.Debugln("Done:", leaf.path)
|
Console.Debugln(Gray("Done:", leaf.path))
|
||||||
delete(w.Opened, leaf.path)
|
delete(w.Opened, leaf.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Console.Debugln(w.INode.Path, ": Completed. Exiting...")
|
Console.Debugln(Gray(w.INode.Path, ": Completed. Exiting..."))
|
||||||
done <- StatusReport{path: w.INode.Path, size: w.INode.Size}
|
done <- StatusReport{path: w.INode.Path, size: w.INode.Size}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,22 +98,25 @@ func (i *INode) Pesa(done chan StatusReport) chan StatusReport {
|
||||||
// NastroConvogliatore starts a Pesa on a given path and displays
|
// NastroConvogliatore starts a Pesa on a given path and displays
|
||||||
// the current value of the size.
|
// the current value of the size.
|
||||||
func NastroConvogliatore(path string) {
|
func NastroConvogliatore(path string) {
|
||||||
|
var size int64
|
||||||
pathINode, err := INodeFromPath(path)
|
pathINode, err := INodeFromPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Console.Fatalln("Failed creating inode:", err)
|
Console.Fatalln("Failed creating inode:", err)
|
||||||
}
|
}
|
||||||
Console.Debugln("Starting Pesa on path:", path)
|
Console.Debugln(Gray("Starting Pesa on path:", path))
|
||||||
done := make(chan StatusReport)
|
done := make(chan StatusReport)
|
||||||
result := pathINode.Pesa(done)
|
result := pathINode.Pesa(done)
|
||||||
writer := uilive.New()
|
writer := uilive.New()
|
||||||
writer.Start()
|
writer.Start()
|
||||||
fmt.Fprintf(writer, "%s\n", Green("Starting..."))
|
fmt.Fprintf(writer, "%s\n", Green("Starting..."))
|
||||||
|
size = 0
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case res := <-result:
|
case res := <-result:
|
||||||
fmt.Fprintf(writer, "%s: %d\n", res.path, res.size)
|
size += res.size
|
||||||
case res := <-done:
|
fmt.Fprintf(writer, "%s: %d\n%s: %d\n", res.path, res.size, path, size)
|
||||||
fmt.Fprintf(writer, "%s: %d\n", res.path, res.size)
|
case <-done:
|
||||||
|
fmt.Fprintf(writer, "%s: %d\n", path, pathINode.Size)
|
||||||
writer.Stop()
|
writer.Stop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue