fix nil pointer dereference
This commit is contained in:
parent
bdcc1c62d3
commit
ea06ed54a6
3 changed files with 10 additions and 9 deletions
|
@ -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(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue