@@ -155,7 +155,18 @@ func main() {
155
155
// When asked to decrypt the backups, do it here and exit, we have all
156
156
// required input (passphrase and backup directory)
157
157
if opts.Decrypt {
158
-
if err := decryptDirectory(opts.Directory, opts.CipherPassphrase, opts.Jobs); err != nil {
158
+
// Avoid getting wrong globs from the config file since we are
159
+
// using the remaining args from the command line that are
160
+
// usually as a list of databases to dump
161
+
globs := []string{}
162
+
for _, v := range cliOptList {
163
+
if v == "include-dbs" {
164
+
globs = opts.Dbnames
165
+
break
166
+
}
167
+
}
168
+
169
+
if err := decryptDirectory(opts.Directory, opts.CipherPassphrase, opts.Jobs, globs); err != nil {
159
170
l.Fatalln(err)
160
171
os.Exit(1)
161
172
}
@@ -809,7 +820,7 @@ func dumpConfigFiles(dir string, timeFormat string, db *pg, fc chan<- string) er
809
820
return nil
810
821
}
811
822
812
-
func decryptDirectory(dir string, password string, workers int) error {
823
+
func decryptDirectory(dir string, password string, workers int, globs []string) error {
813
824
814
825
// Run a pool of workers to decrypt concurrently
815
826
var wg sync.WaitGroup
@@ -850,13 +861,35 @@ func decryptDirectory(dir string, password string, workers int) error {
850
861
}(i)
851
862
}
852
863
853
-
// Read the directory
864
+
// Read the directory, filter the contents with the provided globs and
865
+
// send the path to the workers. When a directory is found, send its
866
+
// content, the first level only to the workers
854
867
entries, err := os.ReadDir(dir)
855
868
if err != nil {
856
869
return fmt.Errorf("unable to read directory %s: %w", dir, err)
857
870
}
858
871
859
872
for _, path := range entries {
873
+
keep := true
874
+
if len(globs) > 0 {
875
+
keep = false
876
+
for _, glob := range globs {
877
+
keep, err = filepath.Match(glob, path.Name())
878
+
if err != nil {
879
+
return fmt.Errorf("bad patern: %w", err)
880
+
}
881
+
882
+
if keep {
883
+
break
884
+
}
885
+
}
886
+
}
887
+
888
+
if !keep {
889
+
l.Verbosef("skipping: %s, patterns: %v\n", path.Name(), globs)
890
+
continue
891
+
}
892
+
860
893
if path.IsDir() {
861
894
l.Verboseln("dump is a directory, decrypting all files inside")
862
895
subdir := filepath.Join(dir, path.Name())
@@ -886,9 +919,15 @@ func decryptDirectory(dir string, password string, workers int) error {
886
919
}
887
920
}
888
921
922
+
// Closing the channel will make the workers stop as soon as it is
923
+
// empty
889
924
close(fq)
890
925
wg.Wait()
891
926
927
+
// Check the return channel to find if there was an error. There are
928
+
// maybe more than one but when creating the buffered channel we can't
929
+
// know the size of the buffer, so we limit to one error per worker to
930
+
// avoid being blocked by channel
892
931
select {
893
932
case _ = <-ret:
894
933
return fmt.Errorf("failure in decrypt, please examine logs")
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4