From 5c894b765b945fc30bf54976ec7be0089f2ece33 Mon Sep 17 00:00:00 2001 From: Zach Loafman Date: Sat, 11 Jul 2015 08:07:26 -0700 Subject: [PATCH] Fix mungedocs for absolute paths chdir into the parent of the docs directory, then walk docs. Fixes #11111 --- cmd/mungedocs/mungedocs.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/mungedocs/mungedocs.go b/cmd/mungedocs/mungedocs.go index 98910d44d0f..b82d1d22f23 100644 --- a/cmd/mungedocs/mungedocs.go +++ b/cmd/mungedocs/mungedocs.go @@ -22,6 +22,7 @@ import ( "fmt" "io/ioutil" "os" + "path" "path/filepath" "strings" @@ -127,6 +128,15 @@ func main() { os.Exit(1) } + // Split the root dir of "foo/docs" into "foo" and "docs". We + // chdir into "foo" and walk "docs" so the walk is always at a + // relative path. + stem, leaf := path.Split(strings.TrimRight(*rootDir, "/")) + if err := os.Chdir(stem); err != nil { + fmt.Fprintf(os.Stderr, "ERROR: %v\n", err) + os.Exit(2) + } + fp := fileProcessor{ munges: allMunges, verifyOnly: *verify, @@ -140,7 +150,7 @@ func main() { // changes needed. var changesNeeded bool - err := filepath.Walk(*rootDir, newWalkFunc(&fp, &changesNeeded)) + err := filepath.Walk(leaf, newWalkFunc(&fp, &changesNeeded)) if err != nil { fmt.Fprintf(os.Stderr, "ERROR: %v\n", err) os.Exit(2)