aboutsummaryrefslogtreecommitdiffstats
path: root/zip
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-09-21 15:12:39 -0700
committerColin Cross <ccross@android.com>2018-09-21 16:08:16 -0700
commitd59dab94c4897f504ca7a3a2b227ca6b000bfaa4 (patch)
tree82ff63ac48d1de169cdbe5bf35a45dd53a8a4088 /zip
parent08e28abc4ecd10a0e0ab2dcb683560f9c6331e1b (diff)
downloadbuild_soong-d59dab94c4897f504ca7a3a2b227ca6b000bfaa4.tar.gz
build_soong-d59dab94c4897f504ca7a3a2b227ca6b000bfaa4.tar.bz2
build_soong-d59dab94c4897f504ca7a3a2b227ca6b000bfaa4.zip
Add a --symlinks argument to soong_zip
Add a --symlinks argument that defaults to true to soong_zip. Passing --symlinks=false will cause it to follow symlinks instead of storing them in the zip file. Bug: 112843624 Test: glob_test.go Test: m checkbuild Change-Id: I4deb98daa9d4ba9f94e3d7670c117fe00381d2ba
Diffstat (limited to 'zip')
-rw-r--r--zip/cmd/main.go5
-rw-r--r--zip/zip.go30
2 files changed, 26 insertions, 9 deletions
diff --git a/zip/cmd/main.go b/zip/cmd/main.go
index f49105a6..c4e1196d 100644
--- a/zip/cmd/main.go
+++ b/zip/cmd/main.go
@@ -186,6 +186,8 @@ func main() {
emulateJar := flags.Bool("jar", false, "modify the resultant .zip to emulate the output of 'jar'")
writeIfChanged := flags.Bool("write_if_changed", false, "only update resultant .zip if it has changed")
+ symlinks := flags.Bool("symlinks", true, "store symbolic links in zip instead of following them")
+
parallelJobs := flags.Int("parallel", runtime.NumCPU(), "number of parallel threads to use")
cpuProfile := flags.String("cpuprofile", "", "write cpu profile to file")
traceFile := flags.String("trace", "", "write trace to file")
@@ -216,9 +218,10 @@ func main() {
NumParallelJobs: *parallelJobs,
NonDeflatedFiles: nonDeflatedFiles,
WriteIfChanged: *writeIfChanged,
+ StoreSymlinks: *symlinks,
})
if err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
+ fmt.Fprintln(os.Stderr, "error:", err.Error())
os.Exit(1)
}
}
diff --git a/zip/zip.go b/zip/zip.go
index 4a02531e..d9645b84 100644
--- a/zip/zip.go
+++ b/zip/zip.go
@@ -107,6 +107,7 @@ type ZipWriter struct {
compressorPool sync.Pool
compLevel int
+ followSymlinks pathtools.ShouldFollowSymlinks
}
type zipEntry struct {
@@ -132,6 +133,7 @@ type ZipArgs struct {
NumParallelJobs int
NonDeflatedFiles map[string]bool
WriteIfChanged bool
+ StoreSymlinks bool
}
const NOQUOTE = '\x00'
@@ -212,12 +214,16 @@ func Run(args ZipArgs) (err error) {
args.AddDirectoryEntriesToZip = true
}
+ // Have Glob follow symlinks if they are not being stored as symlinks in the zip file.
+ followSymlinks := pathtools.ShouldFollowSymlinks(!args.StoreSymlinks)
+
w := &ZipWriter{
- time: jar.DefaultTime,
- createdDirs: make(map[string]string),
- createdFiles: make(map[string]string),
- directories: args.AddDirectoryEntriesToZip,
- compLevel: args.CompressionLevel,
+ time: jar.DefaultTime,
+ createdDirs: make(map[string]string),
+ createdFiles: make(map[string]string),
+ directories: args.AddDirectoryEntriesToZip,
+ compLevel: args.CompressionLevel,
+ followSymlinks: followSymlinks,
}
pathMappings := []pathMapping{}
@@ -226,14 +232,14 @@ func Run(args ZipArgs) (err error) {
for _, fa := range args.FileArgs {
var srcs []string
for _, s := range fa.SourceFiles {
- globbed, _, err := pathtools.Glob(s, nil, pathtools.DontFollowSymlinks)
+ globbed, _, err := pathtools.Glob(s, nil, followSymlinks)
if err != nil {
return err
}
srcs = append(srcs, globbed...)
}
if fa.GlobDir != "" {
- globbed, _, err := pathtools.Glob(filepath.Join(fa.GlobDir, "**/*"), nil, pathtools.DontFollowSymlinks)
+ globbed, _, err := pathtools.Glob(filepath.Join(fa.GlobDir, "**/*"), nil, followSymlinks)
if err != nil {
return err
}
@@ -472,7 +478,15 @@ func (z *ZipWriter) addFile(dest, src string, method uint16, emulateJar bool) er
var fileSize int64
var executable bool
- if s, err := os.Lstat(src); err != nil {
+ var s os.FileInfo
+ var err error
+ if z.followSymlinks {
+ s, err = os.Stat(src)
+ } else {
+ s, err = os.Lstat(src)
+ }
+
+ if err != nil {
return err
} else if s.IsDir() {
if z.directories {