fixed order of the progress bars

This commit is contained in:
Daniel Sommer 2023-09-22 15:54:02 +02:00
parent 7bdce49c72
commit 0804fadbb5
2 changed files with 9 additions and 8 deletions

4
.vscode/launch.json vendored
View file

@ -30,7 +30,9 @@
"--password", "--password",
"$Velvet90", "$Velvet90",
"--concurrency", "--concurrency",
"4", "12",
"--delay",
"250",
"--verbose", "--verbose",
], ],
"console": "integratedTerminal" "console": "integratedTerminal"

View file

@ -43,24 +43,23 @@ func Transfer() {
if concurrency == 0 { if concurrency == 0 {
concurrency = sourcefilesCount concurrency = sourcefilesCount
} }
first := true index := 0
channel := make(chan struct{}, concurrency) channel := make(chan struct{}, concurrency)
for file, size := range sourcefiles { for file, size := range sourcefiles {
channel <- struct{}{} channel <- struct{}{}
if !first { if index > 0 {
time.Sleep(settings.Delay) time.Sleep(settings.Delay)
} else {
first = false
} }
go func(file string, size int64) { go func(file string, size int64, index int) {
defer waitgroup.Done() defer waitgroup.Done()
bar := createProgressBar(barcontainer, filepath.Base(file), size, int64(100), counter, false) bar := createProgressBar(barcontainer, filepath.Base(file), size, int64(100), index, false)
if transferFile(bar, file) { if transferFile(bar, file) {
counter++ counter++
} }
totalbar.Increment() totalbar.Increment()
<-channel <-channel
}(file, size) }(file, size, index)
index++
} }
barcontainer.Wait() barcontainer.Wait()
timeDifference := time.Since(timestamp) timeDifference := time.Since(timestamp)