rscp

git clone https://orangeshoelaces.net/git/rscp.git

95bfaf5fb01d5078c5d32b5f79a04f3148011378

Author: Vasily Kolobkov on 06/19/2017

Committer: Vasily Kolobkov on 06/19/2017

Don't tread on fatal errors

Stats

main.go | 41 ++++----
1 file changed, 21 insertions(+), 20 deletions(-)

Patch

diff --git a/main.go b/main.go
index 8593816..a479a7a 100644
--- a/main.go
+++ b/main.go
@@ -30,10 +30,16 @@ func main() {
 		usage()
 	}
 
+	var err error
+
 	if *iamSource {
-		source(args)
+		err = source(args)
 	} else {
-		sink(args[0])
+		err = sink(args[0])
+	}
+
+	if err != nil {
+		os.Exit(1)
 	}
 }
 
@@ -42,32 +48,24 @@ func source(paths []string) error {
 		return err
 	}
 
-	var errors []error
+	var sendErrs []error
 	for _, path := range paths {
 		if err := send(path); err != nil {
-			newErrs := []error{}
-			if accErrs, ok := err.(AccError); ok {
-				newErrs = accErrs.Errors
-				errors = append(errors, newErrs...)
-			} else {
-				newErrs = append(newErrs, err)
-				errors = append(errors, err)
-			}
-			for _, newErr := range newErrs {
-				if _, ok := newErr.(FatalError); ok {
-					break
-				}
+			if _, ok := err.(FatalError); ok {
+				return err
 			}
+			sendErrs = append(sendErrs, err)
 		}
 	}
 
-	if len(errors) > 0 {
-		return AccError{errors}
+	if len(sendErrs) > 0 {
+		return AccError{sendErrs}
 	}
 	return nil
 }
 
-func sink(arg string) {
+func sink(arg string) error {
+	return nil
 }
 
 func send(path string) error {
@@ -138,9 +136,12 @@ func sendDir(dir *os.File, st os.FileInfo) error {
 		return err
 	}
 
-	sendErrs := []error{}
+	var sendErrs []error
 	for _, entry := range content {
 		if err := send(path.Join(dir.Name(), entry)); err != nil {
+			if _, ok := err.(FatalError); ok {
+				return err
+			}
 			sendErrs = append(sendErrs, err)
 		}
 	}
@@ -169,7 +170,7 @@ func sendAttr(st os.FileInfo) error {
 func ack() error {
 	kind := []byte{0}
 	if _, err := os.Stdin.Read(kind); err != nil {
-		return err
+		return FatalError(err.Error())
 	}
 	if kind[0] == 0 {
 		return nil