From f00dfff4c0667c83b3ad598a3c42240e00e13d09 Mon Sep 17 00:00:00 2001 From: Gai Lazar Date: Wed, 13 Oct 2021 10:24:19 +0300 Subject: [PATCH] Bugfix: unzip an archive uploaded with "Archive" and "IncludeDirs" parameters doesn't work (#440) --- artifactory/services/upload.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/artifactory/services/upload.go b/artifactory/services/upload.go index c815ac414..1696f70b7 100644 --- a/artifactory/services/upload.go +++ b/artifactory/services/upload.go @@ -765,6 +765,13 @@ func (us *UploadService) addFileToZip(artifact *clientutils.Artifact, progressPr header.Name = clientutils.TrimPath(localPath) } header.Method = zip.Deflate + + // If this is a directory, add it to the writer with a trailing slash. + if info.IsDir() { + header.Name += "/" + _, e = zipWriter.CreateHeader(header) + return + } writer, e := zipWriter.CreateHeader(header) if errorutils.CheckError(e) != nil { return @@ -775,12 +782,6 @@ func (us *UploadService) addFileToZip(artifact *clientutils.Artifact, progressPr _, e = writer.Write([]byte(filepath.ToSlash(artifact.SymlinkTargetPath))) return } - // If this is a directory, add it to the writer with a trailing slash. - if info.IsDir() { - _, e = writer.Write([]byte(filepath.ToSlash(localPath + fileutils.GetFileSeparator()))) - return - } - file, e := os.Open(localPath) if e != nil { return e