mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-20 05:26:30 +02:00
Fix indexing progress bar, improve question
This commit is contained in:
parent
7880488bf1
commit
f0516b8600
@ -158,15 +158,41 @@ func (in *Index) Refresh() error {
|
|||||||
// TODO: If needed, multithreaded hashing
|
// TODO: If needed, multithreaded hashing
|
||||||
// for i := 0; i < runtime.NumCPU(); i++ {}
|
// for i := 0; i < runtime.NumCPU(); i++ {}
|
||||||
|
|
||||||
// Get fileinfos of pack.toml and index to compare them
|
// Is case-sensitivity a problem?
|
||||||
// Case-sensitivity?
|
|
||||||
pathPF, _ := filepath.Abs(in.flags.PackFile)
|
pathPF, _ := filepath.Abs(in.flags.PackFile)
|
||||||
pathIndex, _ := filepath.Abs(in.indexFile)
|
pathIndex, _ := filepath.Abs(in.indexFile)
|
||||||
|
|
||||||
progressLength := len(in.Files)
|
|
||||||
progressCurrent := 0
|
|
||||||
progressContainer := mpb.New()
|
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(
|
mpb.PrependDecorators(
|
||||||
// simple name decorator
|
// simple name decorator
|
||||||
decor.Name("Refreshing index..."),
|
decor.Name("Refreshing index..."),
|
||||||
@ -182,42 +208,16 @@ func (in *Index) Refresh() error {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: A method of specifying pack root directory?
|
for _, v := range fileList {
|
||||||
// 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
|
|
||||||
}
|
|
||||||
start := time.Now()
|
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
|
err := in.updateFile(v)
|
||||||
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)
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.SetTotal(int64(progressLength), true)
|
progress.Increment(time.Since(start))
|
||||||
|
}
|
||||||
|
|
||||||
// Check all the files exist, remove them if they don't
|
// Check all the files exist, remove them if they don't
|
||||||
i := 0
|
i := 0
|
||||||
|
2
main.go
2
main.go
@ -207,7 +207,7 @@ func cmdUpdate(flags core.Flags, mod string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Do you want to update? [Y/n]: ")
|
fmt.Print("Do you want to update? [Y/n]: ")
|
||||||
var answer string
|
var answer string
|
||||||
_, err := fmt.Scanln(&answer)
|
_, err := fmt.Scanln(&answer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user