Merge master

This commit is contained in:
Marius 2015-12-08 22:08:54 +01:00
parent 608795b322
commit ad5e486ba0
2 changed files with 21 additions and 4 deletions

View File

@ -55,3 +55,9 @@ type DataStore interface {
// and writing, must return os.ErrNotExist or similar.
Terminate(id string) error
}
type FinisherDataStore interface {
DataStore
FinishUpload(id string) error
}

View File

@ -369,10 +369,21 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
newOffset := offset + bytesWritten
w.Header().Set("Upload-Offset", strconv.FormatInt(newOffset, 10))
// If the upload is completed, send the info out to the channel
if handler.config.NotifyCompleteUploads && newOffset == info.Size {
info.Size = newOffset
handler.CompleteUploads <- info
// If the upload is completed, ...
if newOffset == info.Size {
// ... allow custom mechanism to finish and cleanup the upload
if store, ok := handler.dataStore.(FinisherDataStore); ok {
if err := store.FinishUpload(id); err != nil {
handler.sendError(w, r, err)
return
}
}
// ... send the info out to the channel
if handler.config.NotifyCompleteUploads {
info.Size = newOffset
handler.CompleteUploads <- info
}
}
w.WriteHeader(http.StatusNoContent)