diff --git a/commands/command_sync.go b/commands/command_sync.go index c6ac4d64..1e55decf 100644 --- a/commands/command_sync.go +++ b/commands/command_sync.go @@ -3,9 +3,6 @@ package gitmedia import ( ".." "../client" - "fmt" - "os" - "path/filepath" ) type SyncCommand struct { @@ -16,22 +13,14 @@ func (c *SyncCommand) Setup() { } func (c *SyncCommand) Run() { - filepath.Walk(gitmedia.LocalMediaDir, func(path string, info os.FileInfo, err error) error { - if info.IsDir() { - return nil - } - - if ext := filepath.Ext(path); len(ext) > 0 { - return nil - } - - if err := gitmediaclient.Send(path); err != nil { - fmt.Println("Error uploading:", path) - panic(err) - } - - return nil + err := gitmedia.UploadQueue().Walk(func(id string, sha []byte) error { + path := gitmedia.LocalMediaPath(string(sha)) + return gitmediaclient.Send(path) }) + + if err != nil { + gitmedia.Panic(err, "error uploading file") + } } func init() { diff --git a/queues.go b/queues.go index 40cc6c04..36fd5ab3 100644 --- a/queues.go +++ b/queues.go @@ -6,7 +6,7 @@ import ( ) func QueueUpload(sha string) { - _, err := getUploadQueue().AddString(sha) + _, err := UploadQueue().AddString(sha) if err != nil { Panic(err, "Unable to add %s to queue", sha) } @@ -23,7 +23,7 @@ func WalkQueues(cb func(name string, queue *queuedir.Queue) error) error { return err } -func getUploadQueue() *queuedir.Queue { +func UploadQueue() *queuedir.Queue { if uploadQueue == nil { q, err := queueDir.Queue("upload") if err != nil { @@ -41,7 +41,7 @@ func setupQueueDir() *queuedir.QueueDir { var ( queues = map[string]func() *queuedir.Queue{ - "upload": getUploadQueue, + "upload": UploadQueue, } queueDir *queuedir.QueueDir uploadQueue *queuedir.Queue