Have soong_zip add entries for ancestor directories

Bug: 64536066

Test: When I run:

$ mkdir -p a/b/c
$ touch a/b/c/d
$ soong_zip -o test.zip -d -C . -f a/b/c/d
$ zipinfo -1 test.zip
a/b/c/
a/b/c/d

I should get:
a/
a/b/
a/b/c/
a/b/c/d

Change-Id: I779bb48062dfaf88a70fab08d8d98d1e366087b3
This commit is contained in:
Jeff Gaston 2017-08-15 18:05:56 -07:00
parent a622de8498
commit 2d174132c4
1 changed files with 15 additions and 8 deletions

View File

@ -646,15 +646,24 @@ func (z *zipWriter) compressWholeFile(ze *zipEntry, r *os.File, exec Execution,
}
func (z *zipWriter) writeDirectory(dir string) error {
if dir != "" && !strings.HasSuffix(dir, "/") {
dir = dir + "/"
// clean the input
cleanDir := filepath.Clean(dir)
// discover any uncreated directories in the path
zipDirs := []string{}
for cleanDir != "" && cleanDir != "." && !z.createdDirs[cleanDir] {
z.createdDirs[cleanDir] = true
// parent directories precede their children
zipDirs = append([]string{cleanDir}, zipDirs...)
cleanDir = filepath.Dir(cleanDir)
}
for dir != "" && dir != "./" && !z.createdDirs[dir] {
z.createdDirs[dir] = true
// make a directory entry for each uncreated directory
for _, cleanDir := range zipDirs {
dirHeader := &zip.FileHeader{
Name: dir,
Name: cleanDir + "/",
}
dirHeader.SetMode(0700 | os.ModeDir)
dirHeader.SetModTime(z.time)
@ -665,8 +674,6 @@ func (z *zipWriter) writeDirectory(dir string) error {
}
close(ze)
z.writeOps <- ze
dir, _ = filepath.Split(dir)
}
return nil