-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP:Report found files & folders while scanning #39
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,9 @@ func TestGetSubTreeOnSimpleDir(t *testing.T) { | |
}}, | ||
}} | ||
ignoredFolders := map[string]struct{}{"g": struct{}{}} | ||
result := GetSubTree("b", nil, createReadDir(testStructure), ignoredFolders) | ||
progress := make(chan int, 0) | ||
go dummyProgressConsumer(progress) | ||
result := GetSubTree("b", nil, createReadDir(testStructure), ignoredFolders, progress) | ||
buildExpected := func() *File { | ||
b := &File{"b", nil, 180, true, []*File{}} | ||
c := &File{"c", b, 100, false, []*File{}} | ||
|
@@ -105,8 +107,15 @@ func TestGetSubTreeHandlesError(t *testing.T) { | |
failing := func(path string) ([]os.FileInfo, error) { | ||
return []os.FileInfo{}, errors.New("Not found") | ||
} | ||
result := GetSubTree("xyz", nil, failing, map[string]struct{}{}) | ||
progress := make(chan int, 0) | ||
go dummyProgressConsumer(progress) | ||
result := GetSubTree("xyz", nil, failing, map[string]struct{}{}, progress) | ||
if !reflect.DeepEqual(*result, File{}) { | ||
t.Error("GetSubTree didn't return emtpy file on ReadDir failure") | ||
} | ||
} | ||
|
||
func dummyProgressConsumer(progress <-chan int) { | ||
for range progress { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are actually not testing that the functionality you implemented works |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"log" | ||
"os" | ||
"sync" | ||
"time" | ||
|
||
"github.com/gdamore/tcell" | ||
"github.com/viktomas/godu/core" | ||
|
@@ -22,7 +23,9 @@ func main() { | |
root = args[0] | ||
} | ||
log.Printf("godu will walk through `%s` that might take up to few minutes\n", root) | ||
tree := core.GetSubTree(root, nil, ioutil.ReadDir, getIgnoredFolders()) | ||
progress := make(chan int, 0) | ||
go reportProgress(progress) | ||
tree := core.GetSubTree(root, nil, ioutil.ReadDir, getIgnoredFolders(), progress) | ||
err := core.PrepareTree(tree, *limit*core.MEGABYTE) | ||
if err != nil { | ||
log.Println(err.Error()) | ||
|
@@ -43,6 +46,23 @@ func main() { | |
printMarkedFiles(lastState) | ||
} | ||
|
||
func reportProgress(progress <-chan int) { | ||
objs := 0 | ||
ticker := time.NewTicker(time.Second * 2) | ||
go func() { | ||
for i := range progress { | ||
objs += i | ||
} | ||
ticker.Stop() | ||
log.Println("Scanning done") | ||
}() | ||
go func() { | ||
for range ticker.C { | ||
log.Printf("Scanning.. Already found %d objects\n", objs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. objects? Would "files" describe better what we found? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you consider 'folders' to also be 'files'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. We are now using folder/tree/file, often interchangeably. I think we should come up with naming convention going forward. I was thinking about calling everything |
||
} | ||
}() | ||
} | ||
|
||
func printMarkedFiles(lastState *core.State) { | ||
markedFiles := interactive.QuoteMarkedFiles(lastState.MarkedFiles) | ||
for _, quotedFile := range markedFiles { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the 0 here is default (channel not buffered), we might omit that