Skip to content

Commit

Permalink
warn when there are no files to decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
orgrim committed Dec 23, 2021
1 parent ec92e82 commit 299eb31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func parseCli(args []string) (options, []string, error) {
NoEncrypt := pflag.Bool("no-encrypt", false, "do not encrypt the dumps")
pflag.BoolVar(&opts.EncryptKeepSrc, "encrypt-keep-src", false, "keep original files when encrypting")
NoEncryptKeepSrc := pflag.Bool("no-encrypt-keep-src", false, "do not keep original files when encrypting")
pflag.BoolVar(&opts.Decrypt, "decrypt", false, "decrypt files in the backup directory")
pflag.BoolVar(&opts.Decrypt, "decrypt", false, "decrypt files in the backup directory instead of dumping. DBNAMEs become\nglobs to select files")
pflag.StringVar(&opts.CipherPassphrase, "cipher-pass", "", "cipher passphrase for encryption and decryption\n")

pflag.StringVar(&opts.Upload, "upload", "none", "upload produced files to target (s3, gcs,..) use \"none\" to override\nconfiguration file and disable upload")
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ func decryptDirectory(dir string, password string, workers int, globs []string)
// return an error
ret := make(chan bool, workers)

// Start workers than listen for filenames to decrypt until the queue
// Start workers that listen for filenames to decrypt until the queue
// is closed
for i := 0; i < workers; i++ {
wg.Add(1)
Expand Down Expand Up @@ -938,6 +938,7 @@ func decryptDirectory(dir string, password string, workers int, globs []string)
return fmt.Errorf("unable to read directory %s: %w", dir, err)
}

var c int
for _, path := range entries {
keep := true
if len(globs) > 0 {
Expand Down Expand Up @@ -976,6 +977,7 @@ func decryptDirectory(dir string, password string, workers int, globs []string)

file := filepath.Join(subdir, subpath.Name())
if strings.HasSuffix(file, ".age") {
c++
fq <- file
}
}
Expand All @@ -984,10 +986,16 @@ func decryptDirectory(dir string, password string, workers int, globs []string)

file := filepath.Join(dir, path.Name())
if strings.HasSuffix(file, ".age") {
c++
fq <- file
}
}

// Print a warning when no candidate files are found with a hint that the dbname is a glob
if c == 0 {
l.Warnln("no candidate file found for decryption. Maybe add a wildcard (*) to the patterns?")
}

// Closing the channel will make the workers stop as soon as it is
// empty
close(fq)
Expand Down

0 comments on commit 299eb31

Please sign in to comment.