Skip to content

Commit e2cc1a8

Browse files
committed
archive/zip: add trailing slash to directory names for Writer.AddFS
This takes over CL 642375. Fixes #71235. Change-Id: Ic88654da5ae80911bc28329e008de1396c97856e
1 parent 608acff commit e2cc1a8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/archive/zip/writer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ func (w *Writer) AddFS(fsys fs.FS) error {
520520
return err
521521
}
522522
h.Name = name
523+
if d.IsDir() {
524+
// See issue 71235.
525+
h.Name += "/"
526+
}
523527
h.Method = Deflate
524528
fw, err := w.CreateHeader(h)
525529
if err != nil {

src/archive/zip/writer_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ func TestWriterAddFS(t *testing.T) {
633633
t.Fatal(err)
634634
}
635635

636-
// Add subfolder into fsys to match what we'll read from the tar.
636+
// Add subfolder into fsys to match what we'll read from the zip.
637637
tests = append(tests[:2:2], WriteTest{Name: "subfolder", Mode: 0o555 | os.ModeDir}, tests[2])
638638

639639
// read it back
@@ -642,6 +642,10 @@ func TestWriterAddFS(t *testing.T) {
642642
t.Fatal(err)
643643
}
644644
for i, wt := range tests {
645+
if wt.Mode.IsDir() {
646+
// See issue 71235.
647+
wt.Name += "/"
648+
}
645649
testReadFile(t, r.File[i], &wt)
646650
}
647651
}

0 commit comments

Comments
 (0)