Skip to content

Commit

Permalink
Upload - Add timezone to each zip file before uploading (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
Or-Geva authored Jul 31, 2023
1 parent 1d6985b commit cbcde35
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions artifactory/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ func (us *UploadService) addFileToZip(artifact *clientutils.Artifact, progressPr
header.Name = artifact.TargetPathInArchive
}
header.Method = zip.Deflate
header.Modified = info.ModTime()

// If this is a directory, add it to the writer with a trailing slash.
if info.IsDir() {
Expand Down
41 changes: 41 additions & 0 deletions tests/artifactoryupload_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package tests

import (
"archive/zip"
"fmt"
"net/http"
"os"
"path"
"path/filepath"
"strconv"
"testing"
"time"

"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
"github.com/jfrog/jfrog-client-go/utils/io/content"
Expand All @@ -31,6 +34,7 @@ func TestArtifactoryUpload(t *testing.T) {
t.Run("explode", explodeUpload)
t.Run("props", propsUpload)
t.Run("summary", summaryUpload)
t.Run("archive", archiveUpload)
}

func flatUpload(t *testing.T) {
Expand Down Expand Up @@ -338,6 +342,43 @@ func summaryUpload(t *testing.T) {
artifactoryCleanup(t)
}

func archiveUpload(t *testing.T) {
// Upload zip
uploadPattern := filepath.Join("testdata", "a", "a.in")
downloadPattern := path.Join(getRtTargetRepo(), "test.zip")
targetProps, err := utils.ParseProperties("key1=val1")
assert.NoError(t, err)
up := services.NewUploadParams()
up.CommonParams = &utils.CommonParams{Pattern: uploadPattern, Target: downloadPattern, TargetProps: targetProps}
up.Archive = "zip"
up.Flat = true
_, err = testsUploadService.UploadFiles(up)
assert.NoError(t, err)

// Download zip
workingDir, err := os.MkdirTemp("", "downloadTests")
if err != nil {
t.Error(err)
}
defer testutils.RemoveAllAndAssert(t, workingDir)
downloadTarget := workingDir + string(filepath.Separator)
_, err = testsDownloadService.DownloadFiles(services.DownloadParams{CommonParams: &utils.CommonParams{Pattern: downloadPattern, Recursive: true, Target: downloadTarget}})
if err != nil {
t.Error(err)
}

// Check for timezone offset for each file in the zip
r, err := zip.OpenReader(downloadTarget+"test.zip")
assert.NoError(t, err)
defer func() { assert.NoError(t, r.Close()) }()
_, sysTimezoneOffset := time.Now().Zone()
for _, file := range r.File {
_, fileTimezoneOffset := file.Modified.Zone()
assert.Equal(t, sysTimezoneOffset, fileTimezoneOffset)
}
artifactoryCleanup(t)
}

func createWorkingDir(t *testing.T) (string, string) {
workingDir, relativePath, err := tests.CreateFileWithContent("a.in", "/out/")
if err != nil {
Expand Down

0 comments on commit cbcde35

Please sign in to comment.