check folder

This commit is contained in:
cupcakearmy 2021-04-24 12:40:33 +02:00
parent 6efcce07b7
commit 1c436369f0
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
3 changed files with 24 additions and 4 deletions

View File

@ -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/), 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). 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 ## [1.0.4] - 2021-04-23
### Added ### Added

View File

@ -12,7 +12,7 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
const VERSION = "1.0.4" const VERSION = "1.0.5"
var CI bool = false var CI bool = false
var VERBOSE bool = false var VERBOSE bool = false

View File

@ -49,6 +49,18 @@ func (l Location) validate(c *Config) error {
if l.From == "" { if l.From == "" {
return fmt.Errorf(`Location "%s" is missing "from" key`, l.name) 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 { if len(l.To) == 0 {
return fmt.Errorf(`Location "%s" has no "to" targets`, l.name) 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 { for _, command := range commands {
colors.Body.Println("> " + command) colors.Body.Println("> " + command)
out, err := ExecuteCommand(options, "-c", command) out, err := ExecuteCommand(options, "-c", command)
if err != nil {
colors.Error.Println(out)
return err
}
if VERBOSE { if VERBOSE {
colors.Faint.Println(out) colors.Faint.Println(out)
} }
if err != nil {
return err
}
} }
colors.Body.Println("") colors.Body.Println("")
return nil return nil