Skip to content

Commit

Permalink
feat(decomposedfs): add scandata to uploadsessions
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Apr 29, 2024
1 parent 3b6ef86 commit 8f08898
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/unreleased/upload-scandata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add ScanData to Uploadsession

Adds virus scan results to the upload session.

https://github.com/cs3org/reva/pull/4664
https://github.com/cs3org/reva/pull/4657
3 changes: 3 additions & 0 deletions pkg/storage/uploads.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,12 @@ func (fs *Decomposedfs) Postprocessing(ch <-chan events.Event) {
log.Error().Err(err).Interface("uploadID", ev.UploadID).Msg("Failed to get node after scan")
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 {
Expand Down
24 changes: 23 additions & 1 deletion pkg/storage/utils/decomposedfs/upload/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,36 @@ 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.
func (s *OcisSession) binPath() string {
return filepath.Join(s.store.root, "uploads", s.info.ID)
}

// InitiatorID returns the id of the initiating client
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")
Expand Down

0 comments on commit 8f08898

Please sign in to comment.