Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed zombie objects creation in Batch API #91

Merged
merged 1 commit into from
Mar 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,21 @@ func (a *App) BatchHandler(w http.ResponseWriter, r *http.Request) {
}

// Object is not found
meta, err = a.metaStore.Put(object)
if err == nil {
responseObjects = append(responseObjects, a.Represent(object, meta, meta.Existing, true, useTus))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To annotate this for future readers, what's going on here is that if the object is not found, we currently store a stub entry and return an upload response. However, if we're attempting to download, there's no reason to create a stub, since the user didn't request that, and so we should produce a 404 response for this object instead.

Because the Put method returns meta.Existing set to true here, we produce both a download and an upload.

if bv.Operation == "upload" {
meta, err = a.metaStore.Put(object)
if err == nil {
responseObjects = append(responseObjects, a.Represent(object, meta, false, true, useTus))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, we don't use meta.Existing because we know that either (a) the database entry did not previously exist or (b) it did, but the file didn't exist on disk and all we had was a stub in the database. In neither case is the entry valid for download, since there's no data to back it.

}
} else {
rep := &Representation{
Oid: object.Oid,
Size: object.Size,
Error: &ObjectError{
Code: 404,
Message: "Not found",
},
}
responseObjects = append(responseObjects, rep)
}
}

Expand Down