From dc48afd3c5f7267e9720f0b80919962c9977c6e6 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 18 Nov 2020 15:52:07 +0900 Subject: [PATCH] zipsync handles symlink This change fixes a bug that zipsync didn't handle symlink correctly; symlink was extracted as a regular file whose content is the target path. Fixing the problem by correctly creating the symlink using os.Symlink. Bug: N/A Test: manual Change-Id: Ib6685c14e1950d1057d89672883cdd9e4879069a --- cmd/zipsync/zipsync.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/zipsync/zipsync.go b/cmd/zipsync/zipsync.go index 294e5ef0a..aecdc3de4 100644 --- a/cmd/zipsync/zipsync.go +++ b/cmd/zipsync/zipsync.go @@ -53,6 +53,16 @@ func writeFile(filename string, in io.Reader, perm os.FileMode) error { return out.Close() } +func writeSymlink(filename string, in io.Reader) error { + b, err := ioutil.ReadAll(in) + if err != nil { + return err + } + dest := string(b) + err = os.Symlink(dest, filename) + return err +} + func main() { flag.Usage = func() { fmt.Fprintln(os.Stderr, "usage: zipsync -d [-l ] [-f ] [zip]...") @@ -122,7 +132,11 @@ func main() { if err != nil { log.Fatal(err) } - must(writeFile(filename, in, f.FileInfo().Mode())) + if f.FileInfo().Mode()&os.ModeSymlink != 0 { + must(writeSymlink(filename, in)) + } else { + must(writeFile(filename, in, f.FileInfo().Mode())) + } in.Close() files = append(files, filename) }