fix nil pointer dereference

This commit is contained in:
Niko Storni 2018-10-09 15:57:07 -04:00
parent bdcc1c62d3
commit ea06ed54a6
No known key found for this signature in database
GPG key ID: F37FE63398800368
3 changed files with 10 additions and 9 deletions

View file

@ -36,7 +36,6 @@ type SyncManager struct {
singleRun bool singleRun bool
syncProperties *sdk.SyncProperties syncProperties *sdk.SyncProperties
apiConfig *sdk.APIConfig apiConfig *sdk.APIConfig
namer *namer.Namer
} }
func NewSyncManager(stopOnError bool, maxTries int, takeOverExistingChannel bool, refill int, limit int, 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, singleRun: singleRun,
syncProperties: syncProperties, syncProperties: syncProperties,
apiConfig: apiConfig, apiConfig: apiConfig,
namer: namer.NewNamer(),
} }
} }
@ -123,7 +121,7 @@ func (s *SyncManager) Start() error {
AwsS3Secret: s.awsS3Secret, AwsS3Secret: s.awsS3Secret,
AwsS3Region: s.awsS3Region, AwsS3Region: s.awsS3Region,
AwsS3Bucket: s.awsS3Bucket, AwsS3Bucket: s.awsS3Bucket,
namer: s.namer, namer: namer.NewNamer(),
} }
shouldInterruptLoop = true shouldInterruptLoop = true
} else { } else {
@ -156,6 +154,7 @@ func (s *SyncManager) Start() error {
AwsS3Secret: s.awsS3Secret, AwsS3Secret: s.awsS3Secret,
AwsS3Region: s.awsS3Region, AwsS3Region: s.awsS3Region,
AwsS3Bucket: s.awsS3Bucket, AwsS3Bucket: s.awsS3Bucket,
namer: namer.NewNamer(),
}) })
} }
} }

View file

@ -64,7 +64,7 @@ func (v *YoutubeVideo) PublishedAt() time.Time {
return v.publishedAt return v.publishedAt
} }
func (v *YoutubeVideo) getFilename() string { func (v *YoutubeVideo) getFullPath() string {
maxLen := 30 maxLen := 30
reg := regexp.MustCompile(`[^a-zA-Z0-9]+`) reg := regexp.MustCompile(`[^a-zA-Z0-9]+`)
@ -101,7 +101,7 @@ func (v *YoutubeVideo) getAbbrevDescription() string {
} }
func (v *YoutubeVideo) download() error { func (v *YoutubeVideo) download() error {
videoPath := v.getFilename() videoPath := v.getFullPath()
err := os.Mkdir(v.videoDir(), 0750) err := os.Mkdir(v.videoDir(), 0750)
if err != nil && !strings.Contains(err.Error(), "file exists") { if err != nil && !strings.Contains(err.Error(), "file exists") {
@ -159,7 +159,7 @@ func (v *YoutubeVideo) download() error {
_ = v.delete() _ = v.delete()
break break
} }
fi, err := os.Stat(v.getFilename()) fi, err := os.Stat(v.getFullPath())
if err != nil { if err != nil {
return err return err
} }
@ -182,7 +182,7 @@ func (v *YoutubeVideo) videoDir() string {
} }
func (v *YoutubeVideo) delete() error { func (v *YoutubeVideo) delete() error {
videoPath := v.getFilename() videoPath := v.getFullPath()
err := os.Remove(videoPath) err := os.Remove(videoPath)
if err != nil { if err != nil {
log.Errorln(errors.Prefix("delete error", err)) log.Errorln(errors.Prefix("delete error", err))
@ -251,7 +251,7 @@ func (v *YoutubeVideo) publish(daemon *jsonrpc.Client, claimAddress string, amou
ChannelID: &channelID, 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 { func (v *YoutubeVideo) Size() *int64 {

View file

@ -11,6 +11,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"runtime/debug"
"sort" "sort"
"strings" "strings"
"sync" "sync"
@ -228,7 +229,7 @@ func (s *Sync) setStatusSyncing() error {
} }
s.syncedVideosMux.Lock() s.syncedVideosMux.Lock()
s.syncedVideos = syncedVideos s.syncedVideos = syncedVideos
s.Manager.namer.SetNames(claimNames) s.namer.SetNames(claimNames)
s.syncedVideosMux.Unlock() s.syncedVideosMux.Unlock()
return nil return nil
} }
@ -735,6 +736,7 @@ Enqueue:
func (s *Sync) processVideo(v video) (err error) { func (s *Sync) processVideo(v video) (err error) {
defer func() { defer func() {
if p := recover(); p != nil { if p := recover(); p != nil {
log.Printf("stack: %s", debug.Stack())
var ok bool var ok bool
err, ok = p.(error) err, ok = p.(error)
if !ok { if !ok {