From 19884ade9981efafbe73fec3a46ed309a87104af Mon Sep 17 00:00:00 2001 From: Lode Hoste Date: Thu, 5 Mar 2015 22:14:00 +0100 Subject: [PATCH] Exit and error if the target is not a directory --- internal/osutil/osutil.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/osutil/osutil.go b/internal/osutil/osutil.go index 5ce2704a..9f6b7b57 100644 --- a/internal/osutil/osutil.go +++ b/internal/osutil/osutil.go @@ -69,7 +69,14 @@ func Copy(from, to string) (err error) { // containing `path` is writable for the duration of the call. func InWritableDir(fn func(string) error, path string) error { dir := filepath.Dir(path) - if info, err := os.Stat(dir); err == nil && info.IsDir() && info.Mode()&0200 == 0 { + info, err := os.Stat(dir) + if err != nil { + return err + } + if !info.IsDir() { + return errors.New("Not a directory: " + path) + } + if info.Mode()&0200 == 0 { // A non-writeable directory (for this user; we assume that's the // relevant part). Temporarily change the mode so we can delete the // file or directory inside it.