Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions services/postprocessing/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ func (pps *PostprocessingService) processEvent(e raw.Event) error {
})
case events.UploadReady:
pps.log.Debug().Str("UploadID", e.ID).Str("filename", ev.Filename).Msg("processing UploadReady")
if ev.UploadID == "" {
// no upload session, the posix driver assimilated a file that was written to disk directly
return nil
}
// the upload failed - let's keep it around for a while - but mark it as finished
pp, err = pps.getPP(pps.store, ev.UploadID)
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions services/postprocessing/pkg/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ var _ = Describe("PostprocessingService", func() {
}
}

uploadReady := func(uploadID string, failed bool) raw.Event {
ev := events.UploadReady{
UploadID: uploadID,
Failed: failed,
Filename: "test.txt",
}
return raw.Event{
Event: events.Event{
ID: uuid.New().String(),
Type: reflect.TypeOf(ev).String(),
Event: ev,
},
}
}

BeforeEach(func() {
cfg = config.Postprocessing{
Steps: []string{"virusscan"},
Expand Down Expand Up @@ -197,4 +212,25 @@ var _ = Describe("PostprocessingService", func() {
Expect(errors.Is(err, ErrFatal)).To(BeFalse())
})
})

Describe("handling UploadReady", func() {
It("marks a failed upload as finished", func() {
pps = newService()
started := bytesReceived()
uploadID := started.Event.Event.(events.BytesReceived).UploadID
Expect(pps.processEvent(started)).To(Succeed())

Expect(pps.processEvent(uploadReady(uploadID, true))).To(Succeed())

pp, err := pps.getPP(pps.store, uploadID)
Expect(err).ToNot(HaveOccurred())
Expect(pp.Finished).To(BeTrue())
})

It("ignores a file that the storage assimilated without an upload", func() {
pps = newService()

Expect(pps.processEvent(uploadReady("", false))).To(Succeed())
})
})
})