From 07b9e75523afc1597061c214c5c8988d8268c649 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Tue, 8 Nov 2022 20:20:53 +0600 Subject: [PATCH] Publish the s3 objects to `omegaup-submissions` too (#96) This is a migration commit that helps publish objects to both the `omegaup-backup` and the `omegaup-submissions` buckets. --- grader/artifacts.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/grader/artifacts.go b/grader/artifacts.go index aec6f78..21bc6e4 100644 --- a/grader/artifacts.go +++ b/grader/artifacts.go @@ -1,6 +1,7 @@ package grader import ( + "bytes" "errors" "fmt" "io" @@ -260,18 +261,37 @@ func (a *SubmissionsArtifacts) GetSource(ctx *common.Context, guid string) (stri // PutSource writes the source of the submission to the filesystem (and maybe to S3). func (a *SubmissionsArtifacts) PutSource(ctx *common.Context, guid string, r io.Reader) error { - submissionKey := path.Join( + var buf bytes.Buffer + _, err := io.Copy(&buf, r) + if err != nil { + return fmt.Errorf("read: %w", err) + } + + backupSubmissionKey := path.Join( "submissions", guid[:2], guid[2:], ) - return putArtifact( + err = putArtifact( ctx, a.s3c, "omegaup-backup", - path.Join("omegaup", submissionKey), - path.Join(ctx.Config.Grader.V1.RuntimePath, submissionKey), - r, + path.Join("omegaup", backupSubmissionKey), + path.Join(ctx.Config.Grader.V1.RuntimePath, backupSubmissionKey), + bytes.NewReader(buf.Bytes()), + ) + if err != nil { + return fmt.Errorf("put omegaup-backup: %w", err) + } + + // TODO: leave just this version once the migration is done. + return putArtifact( + ctx, + a.s3c, + "omegaup-submissions", + guid, + path.Join(ctx.Config.Grader.V1.RuntimePath, backupSubmissionKey), + bytes.NewReader(buf.Bytes()), ) }