From ea06ed54a6a6e4521664f902493d2d68cd0428d2 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Tue, 9 Oct 2018 15:57:07 -0400 Subject: [PATCH] fix nil pointer dereference --- manager.go | 5 ++--- sources/youtubeVideo.go | 10 +++++----- ytsync.go | 4 +++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manager.go b/manager.go index 53d8b59..73b3b5a 100644 --- a/manager.go +++ b/manager.go @@ -36,7 +36,6 @@ type SyncManager struct { singleRun bool syncProperties *sdk.SyncProperties apiConfig *sdk.APIConfig - namer *namer.Namer } func NewSyncManager(stopOnError bool, maxTries int, takeOverExistingChannel bool, refill int, limit int, @@ -65,7 +64,6 @@ func NewSyncManager(stopOnError bool, maxTries int, takeOverExistingChannel bool singleRun: singleRun, syncProperties: syncProperties, apiConfig: apiConfig, - namer: namer.NewNamer(), } } @@ -123,7 +121,7 @@ func (s *SyncManager) Start() error { AwsS3Secret: s.awsS3Secret, AwsS3Region: s.awsS3Region, AwsS3Bucket: s.awsS3Bucket, - namer: s.namer, + namer: namer.NewNamer(), } shouldInterruptLoop = true } else { @@ -156,6 +154,7 @@ func (s *SyncManager) Start() error { AwsS3Secret: s.awsS3Secret, AwsS3Region: s.awsS3Region, AwsS3Bucket: s.awsS3Bucket, + namer: namer.NewNamer(), }) } } diff --git a/sources/youtubeVideo.go b/sources/youtubeVideo.go index a27ccc6..278c729 100644 --- a/sources/youtubeVideo.go +++ b/sources/youtubeVideo.go @@ -64,7 +64,7 @@ func (v *YoutubeVideo) PublishedAt() time.Time { return v.publishedAt } -func (v *YoutubeVideo) getFilename() string { +func (v *YoutubeVideo) getFullPath() string { maxLen := 30 reg := regexp.MustCompile(`[^a-zA-Z0-9]+`) @@ -101,7 +101,7 @@ func (v *YoutubeVideo) getAbbrevDescription() string { } func (v *YoutubeVideo) download() error { - videoPath := v.getFilename() + videoPath := v.getFullPath() err := os.Mkdir(v.videoDir(), 0750) if err != nil && !strings.Contains(err.Error(), "file exists") { @@ -159,7 +159,7 @@ func (v *YoutubeVideo) download() error { _ = v.delete() break } - fi, err := os.Stat(v.getFilename()) + fi, err := os.Stat(v.getFullPath()) if err != nil { return err } @@ -182,7 +182,7 @@ func (v *YoutubeVideo) videoDir() string { } func (v *YoutubeVideo) delete() error { - videoPath := v.getFilename() + videoPath := v.getFullPath() err := os.Remove(videoPath) if err != nil { log.Errorln(errors.Prefix("delete error", err)) @@ -251,7 +251,7 @@ func (v *YoutubeVideo) publish(daemon *jsonrpc.Client, claimAddress string, amou ChannelID: &channelID, } - return publishAndRetryExistingNames(daemon, v.title, v.getFilename(), amount, options, namer) + return publishAndRetryExistingNames(daemon, v.title, v.getFullPath(), amount, options, namer) } func (v *YoutubeVideo) Size() *int64 { diff --git a/ytsync.go b/ytsync.go index 8a2ed90..462b467 100644 --- a/ytsync.go +++ b/ytsync.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "os/signal" + "runtime/debug" "sort" "strings" "sync" @@ -228,7 +229,7 @@ func (s *Sync) setStatusSyncing() error { } s.syncedVideosMux.Lock() s.syncedVideos = syncedVideos - s.Manager.namer.SetNames(claimNames) + s.namer.SetNames(claimNames) s.syncedVideosMux.Unlock() return nil } @@ -735,6 +736,7 @@ Enqueue: func (s *Sync) processVideo(v video) (err error) { defer func() { if p := recover(); p != nil { + log.Printf("stack: %s", debug.Stack()) var ok bool err, ok = p.(error) if !ok {