Fix indexing progress bar, improve question

This commit is contained in:
comp500 2019-06-16 20:59:45 +01:00
parent 7880488bf1
commit f0516b8600
No known key found for this signature in database
GPG Key ID: 214C822FFEC586B5
2 changed files with 37 additions and 37 deletions

View File

@ -158,15 +158,41 @@ func (in *Index) Refresh() error {
// TODO: If needed, multithreaded hashing
// for i := 0; i < runtime.NumCPU(); i++ {}
// Get fileinfos of pack.toml and index to compare them
// Case-sensitivity?
// Is case-sensitivity a problem?
pathPF, _ := filepath.Abs(in.flags.PackFile)
pathIndex, _ := filepath.Abs(in.indexFile)
progressLength := len(in.Files)
progressCurrent := 0
progressContainer := mpb.New()
progress := progressContainer.AddBar(int64(progressLength),
// TODO: A method of specifying pack root directory?
// TODO: A method of excluding files
packRoot := filepath.Dir(in.flags.PackFile)
var fileList []string
err := filepath.Walk(packRoot, func(path string, info os.FileInfo, err error) error {
if err != nil {
// TODO: Handle errors on individual files properly
return err
}
// Exit if the files are the same as the pack/index files
absPath, _ := filepath.Abs(path)
if absPath == pathPF || absPath == pathIndex {
return nil
}
// Exit if this is a directory
if info.IsDir() {
return nil
}
fileList = append(fileList, path)
return nil
})
if err != nil {
return err
}
progress := progressContainer.AddBar(int64(len(fileList)),
mpb.PrependDecorators(
// simple name decorator
decor.Name("Refreshing index..."),
@ -182,42 +208,16 @@ func (in *Index) Refresh() error {
),
)
// TODO: A method of specifying pack root directory?
// TODO: A method of excluding files
packRoot := filepath.Dir(in.flags.PackFile)
err := filepath.Walk(packRoot, func(path string, info os.FileInfo, err error) error {
if err != nil {
// TODO: Handle errors on individual files properly
return err
}
for _, v := range fileList {
start := time.Now()
defer func() {
// TODO: this is stupid, traverse the file tree first *then* read all the files
if progressCurrent >= progressLength {
progressLength++
progress.SetTotal(int64(progressLength), false)
}
progressCurrent++
progress.Increment(time.Since(start))
}()
// Exit if the files are the same as the pack/index files
absPath, _ := filepath.Abs(path)
if absPath == pathPF || absPath == pathIndex {
return nil
}
// Exit if this is a directory
if info.IsDir() {
return nil
}
return in.updateFile(path)
})
err := in.updateFile(v)
if err != nil {
return err
}
progress.SetTotal(int64(progressLength), true)
progress.Increment(time.Since(start))
}
// Check all the files exist, remove them if they don't
i := 0

View File

@ -207,7 +207,7 @@ func cmdUpdate(flags core.Flags, mod string) error {
return nil
}
fmt.Println("Do you want to update? [Y/n]: ")
fmt.Print("Do you want to update? [Y/n]: ")
var answer string
_, err := fmt.Scanln(&answer)
if err != nil {