From a11342d6e7b475488f6d71d13542dcad20b76ba3 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Sat, 8 Mar 2014 16:35:20 -0500 Subject: [PATCH] Handle potential error from os.Readlink --- revel/util.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/revel/util.go b/revel/util.go index 248eadf..4240565 100644 --- a/revel/util.go +++ b/revel/util.go @@ -66,19 +66,22 @@ func mustChmod(filename string, mode os.FileMode) { // Additionally, the trailing ".template" is stripped from the file name. // Also, dot files and dot directories are skipped. func mustCopyDir(destDir, srcDir string, data map[string]interface{}) error { - var realSrcDir string - // handle symlinked source-direcories + var fullSrcDir string + // Handle symlinked directories. f, err := os.Lstat(srcDir) if err == nil && f.Mode()&os.ModeSymlink == os.ModeSymlink { - realSrcDir, _ = os.Readlink(srcDir) + fullSrcDir, err = os.Readlink(srcDir) + if err != nil { + panic(err) + } } else { - realSrcDir = srcDir + fullSrcDir = srcDir } - return filepath.Walk(realSrcDir, func(srcPath string, info os.FileInfo, err error) error { + return filepath.Walk(fullSrcDir, func(srcPath string, info os.FileInfo, err error) error { // Get the relative path from the source base, and the corresponding path in // the dest directory. - relSrcPath := strings.TrimLeft(srcPath[len(realSrcDir):], string(os.PathSeparator)) + relSrcPath := strings.TrimLeft(srcPath[len(fullSrcDir):], string(os.PathSeparator)) destPath := path.Join(destDir, relSrcPath) // Skip dot files and dot directories.