I'm writing a small wrapper for some rclone
commands, and I'm trying to get the progress of the commands, but can't seem to get anything from accounting.Stats
.
I've looked at the copy
and copyto
commands for inspiration - here's the code I'm running:
package main
import (
"wrapper"
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fs/accounting"
"github.com/ncw/rclone/fs/config"
)
func main() {
// Load the config
config.ConfigPath = "/path/to/rclone.conf"
config.LoadConfig()
// Output stats on one line
fs.Config.StatsOneLine = true
fs.Config.Progress = true
// Create a channel to log progress
logChannel := make(chan bool)
go func() {
for {
select {
case <-logChannel:
return
default:
// Log rclone transfer progress
// FIXME: this is broken? just logs zeroes...
fmt.Print(fmt.Sprintf("\r %s", strings.TrimSpace(accounting.Stats.String())))
}
time.Sleep(time.Second / 4)
}
}()
filePath := "b2:bucket/path/to/file"
wrapper.CopyObject(filePath, "./foo")
// Close stats channel
logChannel <- true
}
And the wrapper
package is defined as follows:
package wrapper
import (
"github.com/ncw/rclone/cmd"
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fs/operations"
"github.com/ncw/rclone/fs/sync"
)
func CopyObject(src, dst string) error {
fsrc, srcFileName, fdst := cmd.NewFsSrcFileDst([]string{src, dst})
if srcFileName == "" {
createEmptySrcDirs := false
return sync.CopyDir(fdst, fsrc, createEmptySrcDirs)
}
return operations.CopyFile(fdst, fsrc, srcFileName, srcFileName)
}
The only output I get from this is:
0 / 0 Bytes, -, 0 Bytes/s, ETA -
I can't seem to get output at all from calling accounting.Stats.String()
, and as far as I can tell from looking through the source code I'm doing the same thing that the command rclone copyto src dst --progress --stats-one-line
is doing.
I'm probably missing something obvious, or doing something incorrectly.
Does anyone know how I can get the progress of active transfers?
Bonus Points: if someone could tell me how to get the progress of a specific transfer that would be even better.