From 7ebecef0ee20520733d6f689e6215db325f2d838 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 3 Apr 2015 10:57:36 +0900 Subject: [PATCH] Improved error handling --- link.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/link.go b/link.go index cf863c1..e9f6089 100644 --- a/link.go +++ b/link.go @@ -40,12 +40,16 @@ func cleanPath(loc string, flags int) error { if err := os.Remove(loc); err != nil { return err } - } else if flags&optClobber == optClobber { - if verbose { - log.Print("Clobbering path: '%s'", loc) - } - if err := os.RemoveAll(loc); err != nil { - return err + } else { + if flags&optClobber == optClobber { + if verbose { + log.Print("Clobbering path: '%s'", loc) + } + if err := os.RemoveAll(loc); err != nil { + return err + } + } else { + return fmt.Errorf("Cannot create link; target already exists: '%s'", loc) } } } @@ -107,7 +111,7 @@ func (this *link) install(srcDir, dstDir string, flags int) error { } if flags&optVerbose == optVerbose { - log.Printf("Linking: '%s' => '%s'", srcPath, dstPath) + log.Printf("Linking: '%s' to '%s'", srcPath, dstPath) } return os.Symlink(srcPath, dstPath)