Skip to content

Commit 8e53eb0

Browse files
authored
Fix creation of zip packages in Windows (#1490)
Package Registry was using the OS-native relative paths directly when building zip packages. So on windows this was using back slashes, but names in zip headers are expected to use forward slashes. Tests were passing only because they only check the headers, and the names there were converted to the expected format when reading the zip.
1 parent 4e41cdf commit 8e53eb0

2 files changed

Lines changed: 2 additions & 5 deletions

File tree

archiver/archive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func buildArchiveHeader(info os.FileInfo, relativePath string) (*zip.FileHeader,
9393
}
9494

9595
header.Method = zip.Deflate
96-
header.Name = relativePath
96+
header.Name = filepath.ToSlash(relativePath)
9797
if info.IsDir() && !strings.HasSuffix(header.Name, "/") {
9898
header.Name = header.Name + "/"
9999
}

main_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,7 @@ func listArchivedFiles(t *testing.T, body []byte) []byte {
689689
var listing bytes.Buffer
690690

691691
for _, f := range zipReader.File {
692-
// f.Name is populated from the zip file directly and is not validated for correctness.
693-
// Using filepath.ToSlash(f.Name) ensures that the file name has the expected format
694-
// regardless of the OS.
695-
listing.WriteString(fmt.Sprintf("%d %s\n", f.UncompressedSize64, filepath.ToSlash(f.Name)))
692+
listing.WriteString(fmt.Sprintf("%d %s\n", f.UncompressedSize64, f.Name))
696693
}
697694
return listing.Bytes()
698695
}

0 commit comments

Comments
 (0)