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
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(),
})
}
}

View file

@ -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 {

View file

@ -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 {