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

Add Scandata to upload session #4657

Merged
merged 1 commit into from
Apr 25, 2024
Merged
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
5 changes: 5 additions & 0 deletions changelog/unreleased/upload-scandata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add ScanData to Uploadsession

Adds virus scan results to the upload session.

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
5 changes: 5 additions & 0 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion pkg/storage/utils/decomposedfs/upload/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"] == ""
Copy link
Contributor

Choose a reason for hiding this comment

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

when bytes are ready this will also return true because the scanResult has not been written yet. We should populate it when all bytes have been received. Maybe with "processing"?

Copy link
Contributor Author

@kobergj kobergj Apr 24, 2024

Choose a reason for hiding this comment

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

when bytes are ready this will also return true because the scanResult has not been written yet.

This is what it is supposed to do. It should only return false when a virus was detected. But you are right, there is small time gap in which either

  • virusscan data was written but postprocessing is not yet finished
  • postprocessing is finished but virusscan data is not yet written

I'd consider that "eventual consistent", as this time frame should be very small.

Maybe with "processing"

I don't see how this would change the outcome? Instead of checking for "" we would check for "processing". Nothing else changes.

In general I would consider an item "processing" from the moment all bytes are received until either the upload session gets the deleted (success case) or a virus occurs (error case)

Copy link
Contributor

Choose a reason for hiding this comment

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

got it, I had the logic flipped in my head.

}

// binPath returns the path to the file storing the binary data.
Expand All @@ -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")
Expand Down
Loading