Skip to content

Commit 410cae6

Browse files
authored
Merge pull request #4664 from kobergj/BackVirusscanData
Backport ScanData feature
2 parents 0f4d9a7 + 8f08898 commit 410cae6

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enhancement: Add ScanData to Uploadsession
2+
3+
Adds virus scan results to the upload session.
4+
5+
https://github.com/cs3org/reva/pull/4664
6+
https://github.com/cs3org/reva/pull/4657

pkg/storage/uploads.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ type UploadSession interface {
7676

7777
// Purge allows completely removing an upload. Should emit a PostprocessingFinished event with a Delete outcome
7878
Purge(ctx context.Context) error
79+
80+
// ScanData returns the scan data for the UploadSession
81+
ScanData() (string, time.Time)
7982
}
8083

8184
// UploadSessionFilter can be used to filter upload sessions

pkg/storage/utils/decomposedfs/decomposedfs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,12 @@ func (fs *Decomposedfs) Postprocessing(ch <-chan events.Event) {
493493
log.Error().Err(err).Interface("uploadID", ev.UploadID).Msg("Failed to get node after scan")
494494
continue
495495
}
496+
sublog := log.With().Str("spaceid", session.SpaceID()).Str("nodeid", session.NodeID()).Logger()
497+
498+
session.SetScanData(res.Description, res.Scandate)
499+
if err := session.Persist(ctx); err != nil {
500+
sublog.Error().Err(err).Msg("Failed to persist scan results")
501+
}
496502
}
497503

498504
if err := n.SetScanData(ctx, res.Description, res.Scandate); err != nil {

pkg/storage/utils/decomposedfs/upload/session.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,36 @@ func (s *OcisSession) MTime() time.Time {
297297

298298
// IsProcessing returns true if all bytes have been received. The session then has entered postprocessing state.
299299
func (s *OcisSession) IsProcessing() bool {
300-
return s.info.Size == s.info.Offset
300+
// We might need a more sophisticated way to determine processing status soon
301+
return s.info.Size == s.info.Offset && s.info.MetaData["scanResult"] == ""
301302
}
302303

303304
// binPath returns the path to the file storing the binary data.
304305
func (s *OcisSession) binPath() string {
305306
return filepath.Join(s.store.root, "uploads", s.info.ID)
306307
}
307308

309+
// InitiatorID returns the id of the initiating client
310+
func (s *OcisSession) InitiatorID() string {
311+
return s.info.MetaData["initiatorid"]
312+
}
313+
314+
// SetScanData sets virus scan data to the upload session
315+
func (s *OcisSession) SetScanData(result string, date time.Time) {
316+
s.info.MetaData["scanResult"] = result
317+
s.info.MetaData["scanDate"] = date.Format(time.RFC3339)
318+
}
319+
320+
// ScanData returns the virus scan data
321+
func (s *OcisSession) ScanData() (string, time.Time) {
322+
date := s.info.MetaData["scanDate"]
323+
if date == "" {
324+
return "", time.Time{}
325+
}
326+
d, _ := time.Parse(time.RFC3339, date)
327+
return s.info.MetaData["scanResult"], d
328+
}
329+
308330
// sessionPath returns the path to the .info file storing the file's info.
309331
func sessionPath(root, id string) string {
310332
return filepath.Join(root, "uploads", id+".info")

0 commit comments

Comments
 (0)