From 1c436369f04c4b89506c6a73dbb41af0fe79dc6d Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sat, 24 Apr 2021 12:40:33 +0200 Subject: [PATCH] check folder --- CHANGELOG.md | 7 +++++++ internal/config.go | 2 +- internal/location.go | 19 ++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a6033..3cbd97a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.5] - 2021-04-24 + +### Fixed + +- Correct exit code on backup failure and better logging/output/feedback. +- Check if `from` key is an actual directory. + ## [1.0.4] - 2021-04-23 ### Added diff --git a/internal/config.go b/internal/config.go index d528a43..4b18a7f 100644 --- a/internal/config.go +++ b/internal/config.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/viper" ) -const VERSION = "1.0.4" +const VERSION = "1.0.5" var CI bool = false var VERBOSE bool = false diff --git a/internal/location.go b/internal/location.go index 3c0b7e4..e4a9a60 100644 --- a/internal/location.go +++ b/internal/location.go @@ -49,6 +49,18 @@ func (l Location) validate(c *Config) error { if l.From == "" { return fmt.Errorf(`Location "%s" is missing "from" key`, l.name) } + if from, err := GetPathRelativeToConfig(l.From); err != nil { + return err + } else { + if stat, err := os.Stat(from); err != nil { + return err + } else { + if !stat.IsDir() { + return fmt.Errorf("\"%s\" is not valid directory for location \"%s\"", from, l.name) + } + } + } + if len(l.To) == 0 { return fmt.Errorf(`Location "%s" has no "to" targets`, l.name) } @@ -81,12 +93,13 @@ func ExecuteHooks(commands []string, options ExecuteOptions) error { for _, command := range commands { colors.Body.Println("> " + command) out, err := ExecuteCommand(options, "-c", command) + if err != nil { + colors.Error.Println(out) + return err + } if VERBOSE { colors.Faint.Println(out) } - if err != nil { - return err - } } colors.Body.Println("") return nil