diff options
author | Colin Cross <ccross@android.com> | 2018-09-28 15:16:48 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2018-09-28 16:14:52 -0700 |
commit | 4be8f9e2a3e857050f4d6d9b3d728492828445bf (patch) | |
tree | 02d5d87c95a304bfeb58f4f436d7fa4043f06763 /zip/zip.go | |
parent | 09f11056f876a9f705a53fd6f122aa7575e0b51b (diff) | |
download | build_soong-4be8f9e2a3e857050f4d6d9b3d728492828445bf.tar.gz build_soong-4be8f9e2a3e857050f4d6d9b3d728492828445bf.tar.bz2 build_soong-4be8f9e2a3e857050f4d6d9b3d728492828445bf.zip |
soong_zip: add --ignore_missing_files flag
soong_zip builds a list of files to zip early and then starts
zipping them all. If a directory being zipped is concurrently
modified, a file that existed when soong_zip started may not
still exist. Add a flag that continues when an expected file
does not exist. Print a warning, since this should be rare
in normal usages but is a sign of a problem if it happens
regularly.
Test: zip_test.go
Test: m checkbuild
Test: m platform
Change-Id: I78426fe66fded8528ddd436c0f71a7442183cfeb
Diffstat (limited to 'zip/zip.go')
-rw-r--r-- | zip/zip.go | 63 |
1 files changed, 46 insertions, 17 deletions
@@ -188,9 +188,11 @@ type ZipWriter struct { compressorPool sync.Pool compLevel int - followSymlinks pathtools.ShouldFollowSymlinks + followSymlinks pathtools.ShouldFollowSymlinks + ignoreMissingFiles bool - fs pathtools.FileSystem + stderr io.Writer + fs pathtools.FileSystem } type zipEntry struct { @@ -215,7 +217,9 @@ type ZipArgs struct { NonDeflatedFiles map[string]bool WriteIfChanged bool StoreSymlinks bool + IgnoreMissingFiles bool + Stderr io.Writer Filesystem pathtools.FileSystem } @@ -271,19 +275,25 @@ func ZipTo(args ZipArgs, w io.Writer) error { followSymlinks := pathtools.ShouldFollowSymlinks(!args.StoreSymlinks) z := &ZipWriter{ - time: jar.DefaultTime, - createdDirs: make(map[string]string), - createdFiles: make(map[string]string), - directories: args.AddDirectoryEntriesToZip, - compLevel: args.CompressionLevel, - followSymlinks: followSymlinks, - fs: args.Filesystem, + time: jar.DefaultTime, + createdDirs: make(map[string]string), + createdFiles: make(map[string]string), + directories: args.AddDirectoryEntriesToZip, + compLevel: args.CompressionLevel, + followSymlinks: followSymlinks, + ignoreMissingFiles: args.IgnoreMissingFiles, + stderr: args.Stderr, + fs: args.Filesystem, } if z.fs == nil { z.fs = pathtools.OsFs } + if z.stderr == nil { + z.stderr = os.Stderr + } + pathMappings := []pathMapping{} noCompression := args.CompressionLevel == 0 @@ -301,29 +311,44 @@ func ZipTo(args ZipArgs, w io.Writer) error { return err } if len(globbed) == 0 { - return &os.PathError{ - Op: "stat", + err := &os.PathError{ + Op: "lstat", Path: s, Err: os.ErrNotExist, } + if args.IgnoreMissingFiles { + fmt.Fprintln(args.Stderr, "warning:", err) + } else { + return err + } } srcs = append(srcs, globbed...) } if fa.GlobDir != "" { if exists, isDir, err := z.fs.Exists(fa.GlobDir); err != nil { return err - } else if !exists { - return &os.PathError{ - Op: "stat", + } else if !exists && !args.IgnoreMissingFiles { + err := &os.PathError{ + Op: "lstat", Path: fa.GlobDir, Err: os.ErrNotExist, } - } else if !isDir { - return &os.PathError{ - Op: "stat", + if args.IgnoreMissingFiles { + fmt.Fprintln(args.Stderr, "warning:", err) + } else { + return err + } + } else if !isDir && !args.IgnoreMissingFiles { + err := &os.PathError{ + Op: "lstat", Path: fa.GlobDir, Err: syscall.ENOTDIR, } + if args.IgnoreMissingFiles { + fmt.Fprintln(args.Stderr, "warning:", err) + } else { + return err + } } globbed, _, err := z.fs.Glob(filepath.Join(fa.GlobDir, "**/*"), nil, followSymlinks) if err != nil { @@ -576,6 +601,10 @@ func (z *ZipWriter) addFile(dest, src string, method uint16, emulateJar bool) er } if err != nil { + if os.IsNotExist(err) && z.ignoreMissingFiles { + fmt.Fprintln(z.stderr, "warning:", err) + return nil + } return err } else if s.IsDir() { if z.directories { |