addPendingUpload adds a new file to the pending queue of uploads
(destPath string, started bool)
| 765 | |
| 766 | // addPendingUpload adds a new file to the pending queue of uploads |
| 767 | func (b *Persistent) addPendingUpload(destPath string, started bool) error { |
| 768 | return b.db.Update(func(tx *bolt.Tx) error { |
| 769 | bucket, err := tx.CreateBucketIfNotExists([]byte(tempBucket)) |
| 770 | if err != nil { |
| 771 | return fmt.Errorf("couldn't bucket for %v", tempBucket) |
| 772 | } |
| 773 | tempObj := &tempUploadInfo{ |
| 774 | DestPath: destPath, |
| 775 | AddedOn: time.Now(), |
| 776 | Started: started, |
| 777 | } |
| 778 | |
| 779 | // cache Object Info |
| 780 | encoded, err := json.Marshal(tempObj) |
| 781 | if err != nil { |
| 782 | return fmt.Errorf("couldn't marshal object (%v) info: %v", destPath, err) |
| 783 | } |
| 784 | err = bucket.Put([]byte(destPath), encoded) |
| 785 | if err != nil { |
| 786 | return fmt.Errorf("couldn't cache object (%v) info: %v", destPath, err) |
| 787 | } |
| 788 | |
| 789 | return nil |
| 790 | }) |
| 791 | } |
| 792 | |
| 793 | // getPendingUpload returns the next file from the pending queue of uploads |
| 794 | func (b *Persistent) getPendingUpload(inRoot string, waitTime time.Duration) (destPath string, err error) { |