From b9d70225e825153620c80df8266f90c3dec3ef12 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Wed, 24 Apr 2024 11:37:33 +0200 Subject: [PATCH] feat(decomposedfs): add scandata to uploadsessions Signed-off-by: jkoberg --- changelog/unreleased/upload-scandata.md | 5 +++++ pkg/storage/uploads.go | 3 +++ .../utils/decomposedfs/decomposedfs.go | 5 +++++ .../utils/decomposedfs/upload/session.go | 19 ++++++++++++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/upload-scandata.md diff --git a/changelog/unreleased/upload-scandata.md b/changelog/unreleased/upload-scandata.md new file mode 100644 index 0000000000..4a3b0a1c7e --- /dev/null +++ b/changelog/unreleased/upload-scandata.md @@ -0,0 +1,5 @@ +Enhancement: Add ScanData to Uploadsession + +Adds virus scan results to the upload session. + +https://github.com/cs3org/reva/pull/4657 diff --git a/pkg/storage/uploads.go b/pkg/storage/uploads.go index 87d26115bf..f6ef9ad2d7 100644 --- a/pkg/storage/uploads.go +++ b/pkg/storage/uploads.go @@ -76,6 +76,9 @@ type UploadSession interface { // Purge allows completely removing an upload. Should emit a PostprocessingFinished event with a Delete outcome Purge(ctx context.Context) error + + // ScanData returns the scan data for the UploadSession + ScanData() (string, time.Time) } // UploadSessionFilter can be used to filter upload sessions diff --git a/pkg/storage/utils/decomposedfs/decomposedfs.go b/pkg/storage/utils/decomposedfs/decomposedfs.go index 9af86b4c43..19e5f06301 100644 --- a/pkg/storage/utils/decomposedfs/decomposedfs.go +++ b/pkg/storage/utils/decomposedfs/decomposedfs.go @@ -496,6 +496,11 @@ func (fs *Decomposedfs) Postprocessing(ch <-chan events.Event) { continue } sublog = log.With().Str("spaceid", session.SpaceID()).Str("nodeid", session.NodeID()).Logger() + + session.SetScanData(res.Description, res.Scandate) + if err := session.Persist(ctx); err != nil { + sublog.Error().Err(err).Msg("Failed to persist scan results") + } } if err := n.SetScanData(ctx, res.Description, res.Scandate); err != nil { diff --git a/pkg/storage/utils/decomposedfs/upload/session.go b/pkg/storage/utils/decomposedfs/upload/session.go index b7ba2b6004..c008c274dd 100644 --- a/pkg/storage/utils/decomposedfs/upload/session.go +++ b/pkg/storage/utils/decomposedfs/upload/session.go @@ -298,7 +298,8 @@ func (s *OcisSession) MTime() time.Time { // IsProcessing returns true if all bytes have been received. The session then has entered postprocessing state. func (s *OcisSession) IsProcessing() bool { - return s.info.Size == s.info.Offset + // We might need a more sophisticated way to determine processing status soon + return s.info.Size == s.info.Offset && s.info.MetaData["scanResult"] == "" } // binPath returns the path to the file storing the binary data. @@ -311,6 +312,22 @@ func (s *OcisSession) InitiatorID() string { return s.info.MetaData["initiatorid"] } +// SetScanData sets virus scan data to the upload session +func (s *OcisSession) SetScanData(result string, date time.Time) { + s.info.MetaData["scanResult"] = result + s.info.MetaData["scanDate"] = date.Format(time.RFC3339) +} + +// ScanData returns the virus scan data +func (s *OcisSession) ScanData() (string, time.Time) { + date := s.info.MetaData["scanDate"] + if date == "" { + return "", time.Time{} + } + d, _ := time.Parse(time.RFC3339, date) + return s.info.MetaData["scanResult"], d +} + // sessionPath returns the path to the .info file storing the file's info. func sessionPath(root, id string) string { return filepath.Join(root, "uploads", id+".info")