cmd/torrent: Fix logging when progress bar and stderr are the same file
This commit is contained in:
parent
ddd1e90d45
commit
358c6c8649
|
@ -23,8 +23,10 @@ import (
|
||||||
"github.com/anacrolix/torrent/storage"
|
"github.com/anacrolix/torrent/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var progress = uiprogress.New()
|
||||||
|
|
||||||
func torrentBar(t *torrent.Torrent) {
|
func torrentBar(t *torrent.Torrent) {
|
||||||
bar := uiprogress.AddBar(1)
|
bar := progress.AddBar(1)
|
||||||
bar.AppendCompleted()
|
bar.AppendCompleted()
|
||||||
bar.AppendFunc(func(*uiprogress.Bar) (ret string) {
|
bar.AppendFunc(func(*uiprogress.Bar) (ret string) {
|
||||||
select {
|
select {
|
||||||
|
@ -133,6 +135,12 @@ var flags = struct {
|
||||||
DownloadRate: -1,
|
DownloadRate: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stdoutAndStderrAreSameFile() bool {
|
||||||
|
fi1, _ := os.Stdout.Stat()
|
||||||
|
fi2, _ := os.Stderr.Stat()
|
||||||
|
return os.SameFile(fi1, fi2)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
tagflag.Parse(&flags)
|
tagflag.Parse(&flags)
|
||||||
|
@ -167,7 +175,10 @@ func main() {
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||||
client.WriteStatus(w)
|
client.WriteStatus(w)
|
||||||
})
|
})
|
||||||
uiprogress.Start()
|
if stdoutAndStderrAreSameFile() {
|
||||||
|
log.SetOutput(progress.Bypass())
|
||||||
|
}
|
||||||
|
progress.Start()
|
||||||
addTorrents(client)
|
addTorrents(client)
|
||||||
if client.WaitAll() {
|
if client.WaitAll() {
|
||||||
log.Print("downloaded ALL the torrents")
|
log.Print("downloaded ALL the torrents")
|
||||||
|
|
Loading…
Reference in New Issue