diff --git a/manager.go b/manager.go index 7f3198c..b09f26e 100644 --- a/manager.go +++ b/manager.go @@ -12,6 +12,8 @@ import ( "time" + "syscall" + "github.com/lbryio/lbry.go/errors" "github.com/lbryio/lbry.go/null" "github.com/lbryio/lbry.go/util" @@ -214,7 +216,7 @@ func (s SyncManager) Start() error { "NotEnoughFunds", "no space left on device", } - if util.InSliceContains(err.Error(), fatalErrors) { + if util.ContainedInSlice(err.Error(), fatalErrors) { return errors.Prefix("@Nikooo777 this requires manual intervention! Exiting...", err) } util.SendInfoToSlack("A non fatal error was reported by the sync process. %s\nContinuing...", err.Error()) @@ -243,7 +245,7 @@ func (s SyncManager) checkUsedSpace() error { if err != nil { return err } - usedPctile, err := util.GetUsedSpace(usr.HomeDir + "/.lbrynet/blobfiles/") + usedPctile, err := GetUsedSpace(usr.HomeDir + "/.lbrynet/blobfiles/") if err != nil { return err } @@ -253,3 +255,18 @@ func (s SyncManager) checkUsedSpace() error { util.SendInfoToSlack("disk usage: %.1f%%", usedPctile*100) return nil } + +// GetUsedSpace returns a value between 0 and 1, with 0 being completely empty and 1 being full, for the disk that holds the provided path +func GetUsedSpace(path string) (float32, error) { + var stat syscall.Statfs_t + err := syscall.Statfs(path, &stat) + if err != nil { + return 0, err + } + // Available blocks * size per block = available space in bytes + all := stat.Blocks * uint64(stat.Bsize) + free := stat.Bfree * uint64(stat.Bsize) + used := all - free + + return float32(used) / float32(all), nil +} diff --git a/sources/youtubeVideo.go b/sources/youtubeVideo.go index 66788c6..9cac0e1 100644 --- a/sources/youtubeVideo.go +++ b/sources/youtubeVideo.go @@ -131,7 +131,7 @@ func (v YoutubeVideo) delete() error { videoPath := v.getFilename() err := os.Remove(videoPath) if err != nil { - log.Debugln(errors.Prefix("delete error", err)) + log.Errorln(errors.Prefix("delete error", err)) return err } log.Debugln(v.id + " deleted from disk (" + videoPath + ")") diff --git a/ytsync.go b/ytsync.go index c8d6fee..dde07f2 100644 --- a/ytsync.go +++ b/ytsync.go @@ -100,7 +100,7 @@ func (s *Sync) FullCycle() (e error) { noFailConditions := []string{ "this youtube channel is being managed by another server", } - if util.InSliceContains(e.Error(), noFailConditions) { + if util.ContainedInSlice(e.Error(), noFailConditions) { return } err := s.Manager.setChannelSyncStatus(s.YoutubeChannelID, StatusFailed) @@ -219,7 +219,7 @@ func (s *Sync) doSync() error { err = s.walletSetup() if err != nil { - return errors.Err("Initial wallet setup failed! Manual Intervention is required. Reason: %v", err) + return errors.Prefix("Initial wallet setup failed! Manual Intervention is required.", err) } if s.StopOnError { @@ -281,7 +281,7 @@ func (s *Sync) startWorker(workerNum int) { "NotEnoughFunds", "Cannot publish using channel", } - if util.InSliceContains(err.Error(), fatalErrors) || s.StopOnError { + if util.ContainedInSlice(err.Error(), fatalErrors) || s.StopOnError { s.grp.Stop() } else if s.MaxTries > 1 { errorsNoRetry := []string{ @@ -296,7 +296,7 @@ func (s *Sync) startWorker(workerNum int) { "Client.Timeout exceeded while awaiting headers)", "video is bigger than 2GB, skipping for now", } - if util.InSliceContains(err.Error(), errorsNoRetry) { + if util.ContainedInSlice(err.Error(), errorsNoRetry) { log.Println("This error should not be retried at all") } else if tryCount < s.MaxTries { if strings.Contains(err.Error(), "txn-mempool-conflict") || @@ -369,9 +369,6 @@ func (s *Sync) enqueueYoutubeVideos() error { } for _, item := range playlistResponse.Items { - // todo: there's thumbnail info here. why did we need lambda??? - // because when videos are taken down from youtube, the thumb is gone too - // normally we'd send the video into the channel here, but youtube api doesn't have sorting // so we have to get ALL the videos, then sort them, then send them in videos = append(videos, sources.NewYoutubeVideo(s.videoDirectory, item.Snippet)) diff --git a/ytsync_test.go b/ytsync_test.go deleted file mode 100644 index b1346f0..0000000 --- a/ytsync_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package ytsync - -import ( - "testing" -) - -func TestWaitForDaemonProcess(t *testing.T) { - /* - err := startDaemonViaSystemd() - if err != nil { - t.Fail() - } - log.Infoln("Waiting 5 seconds for the daemon to start...") - time.Sleep(5 * time.Second) - err = stopDaemonViaSystemd() - if err != nil { - t.Fail() - } - */ - //start lbrynet before running this test - // stop lbrynet while running this test - err := waitForDaemonProcess(100) - if err != nil { - t.Fail() - } -}