diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2016-07-18 21:50:27 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2016-07-18 21:50:27 -0600 |
commit | 38c246341691b3f7177e0f42556141975db8f066 (patch) | |
tree | e9eae7422218f94299911c15b6d63fdc7d0629ed | |
parent | df018ea64a1c66927d3046102ddc85816e77efb3 (diff) |
Fix ACME asset migration when renaming folders
-rw-r--r-- | caddy/caddymain/run.go | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/caddy/caddymain/run.go b/caddy/caddymain/run.go index 281f7d5e..e83ecc17 100644 --- a/caddy/caddymain/run.go +++ b/caddy/caddymain/run.go @@ -188,18 +188,25 @@ func moveStorage() { log.Fatalf("[ERROR] Unable to migrate certificate storage: %v\n\nPlease follow instructions at:\nhttps://github.com/mholt/caddy/issues/902#issuecomment-228876011", err) } // convert mixed case folder and file names to lowercase - filepath.Walk(string(newPath), func(path string, info os.FileInfo, err error) error { - // must be careful to only lowercase the base of the path, not the whole thing!! - base := filepath.Base(path) - if lowerBase := strings.ToLower(base); base != lowerBase { - lowerPath := filepath.Join(filepath.Dir(path), lowerBase) - err = os.Rename(path, lowerPath) - if err != nil { - log.Fatalf("[ERROR] Unable to lower-case: %v\n\nPlease follow instructions at:\nhttps://github.com/mholt/caddy/issues/902#issuecomment-228876011", err) + var done bool // walking is recursive and preloads the file names, so we must restart walk after a change until no changes + for !done { + done = true + filepath.Walk(string(newPath), func(path string, info os.FileInfo, err error) error { + // must be careful to only lowercase the base of the path, not the whole thing!! + base := filepath.Base(path) + if lowerBase := strings.ToLower(base); base != lowerBase { + lowerPath := filepath.Join(filepath.Dir(path), lowerBase) + err = os.Rename(path, lowerPath) + if err != nil { + log.Fatalf("[ERROR] Unable to lower-case: %v\n\nPlease follow instructions at:\nhttps://github.com/mholt/caddy/issues/902#issuecomment-228876011", err) + } + // terminate traversal and restart since Walk needs the updated file list with new file names + done = false + return errors.New("start over") } - } - return nil - }) + return nil + }) + } } // setVersion figures out the version information |