Skip to content

Commit d859e38

Browse files
gianniLeslcjinaws
authored andcommitted
Fix for artifact purging etag when s3 download falls back to http
cr: https://code.amazon.com/reviews/CR-117487456
1 parent 38b90ef commit d859e38

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

agent/fileutil/artifact/artifact.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ func s3Download(context context.T, amazonS3URL s3util.AmazonS3URL, destFile stri
282282
if err != nil {
283283
if req.HTTPResponse == nil || req.HTTPResponse.StatusCode != http.StatusNotModified {
284284
log.Debug("failed to download from s3, ", err)
285-
fileutil.DeleteFile(destFile)
286-
fileutil.DeleteFile(eTagFile)
287285
return
288286
}
289287

agent/fileutil/artifact/artifact_integ_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ package artifact
1818

1919
import (
2020
"fmt"
21-
"os"
22-
"path/filepath"
23-
"testing"
24-
2521
"github.com/aws/amazon-ssm-agent/agent/mocks/context"
2622
"github.com/aws/amazon-ssm-agent/agent/mocks/log"
2723
"github.com/stretchr/testify/assert"
24+
"os"
25+
"path/filepath"
26+
"testing"
2827
)
2928

3029
type DownloadTest struct {
@@ -234,15 +233,15 @@ func TestDownloads(t *testing.T) {
234233
}
235234

236235
func TestHttpHttpsDownloadArtifact(t *testing.T) {
237-
testFilePath := "https://www.ietf.org/rfc/rfc1350.txt"
236+
testFilePath := "https://amazon-ssm-us-east-1.s3.amazonaws.com/3.3.40.0/VERSION"
238237
downloadInput := DownloadInput{
239238
DestinationDirectory: ".",
240239
SourceURL: testFilePath,
241240
SourceChecksums: map[string]string{
242-
"sha256": "39c9534e5fa6fecd3ac083ffd6256c2cc9a58f9f1058cb2e472d1782040231f9",
241+
"sha256": "0c0f36c238e6c4c00f39d94dc6381930df2851db0ea2e2543d931474ddce1f8f",
243242
},
244243
}
245-
var expectedLocalPath = "dd5335f3e07903892245d100f4d7df03067e6402"
244+
var expectedLocalPath = "b9f961391ec1ae061db3afcbed5571b2463139c8"
246245
os.Remove(expectedLocalPath)
247246
os.Remove(expectedLocalPath + ".etag")
248247
expectedOutput := DownloadOutput{
@@ -253,6 +252,11 @@ func TestHttpHttpsDownloadArtifact(t *testing.T) {
253252
output, err := Download(mockContext, downloadInput)
254253
assert.NoError(t, err, "Failed to download %v", downloadInput)
255254
mockLog.Infof("Download Result is %v and err:%v", output, err)
255+
256+
defer func() {
257+
os.Remove(expectedLocalPath)
258+
os.Remove(expectedLocalPath + ".etag")
259+
}()
256260
assert.Equal(t, expectedOutput, output)
257261

258262
// now since we have downloaded the file, try to download again should result in cache hit!
@@ -264,9 +268,6 @@ func TestHttpHttpsDownloadArtifact(t *testing.T) {
264268
assert.NoError(t, err, "Failed to download %v", downloadInput)
265269
mockLog.Infof("Download Result is %v and err:%v", output, err)
266270
assert.Equal(t, expectedOutput, output)
267-
268-
os.Remove(expectedLocalPath)
269-
os.Remove(expectedLocalPath + ".etag")
270271
}
271272

272273
func ExampleMd5HashValue() {

0 commit comments

Comments
 (0)