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

Upload - Add timezones to each zip file before uploading #802

Merged
merged 2 commits into from
Jul 31, 2023
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
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