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. // and writing, must return os.ErrNotExist or similar.
Terminate(id string) error Terminate(id string) error
} }
type FinisherDataStore interface {
DataStore
FinishUpload(id string) error
}

View File

@ -369,11 +369,22 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
newOffset := offset + bytesWritten newOffset := offset + bytesWritten
w.Header().Set("Upload-Offset", strconv.FormatInt(newOffset, 10)) w.Header().Set("Upload-Offset", strconv.FormatInt(newOffset, 10))
// If the upload is completed, send the info out to the channel // If the upload is completed, ...
if handler.config.NotifyCompleteUploads && newOffset == info.Size { 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 info.Size = newOffset
handler.CompleteUploads <- info handler.CompleteUploads <- info
} }
}
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
} }