Continue export during decryption failure
This commit is contained in:
parent
28ddb06e2b
commit
de19f450a8
6 changed files with 16 additions and 6 deletions
|
@ -10,7 +10,7 @@ var exportCmd = &cobra.Command{
|
|||
Short: "Starts the export process",
|
||||
Long: ``,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctrl.StartSync()
|
||||
ctrl.Export()
|
||||
},
|
||||
}
|
||||
|
||||
|
|
1
main.go
1
main.go
|
@ -30,5 +30,4 @@ func main() {
|
|||
}
|
||||
}()
|
||||
cmd.Execute(&ctrl)
|
||||
//ctrl.StartSync()
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ func (c *ClICtrl) downloadAndDecrypt(
|
|||
decryptedPath := fmt.Sprintf("%s/%d.decrypted", dir, file.ID)
|
||||
err = crypto.DecryptFile(downloadPath, decryptedPath, file.Key.MustDecrypt(deviceKey), encoding.DecodeBase64(file.FileNonce))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decrypting file %d: %w", file.ID, err)
|
||||
log.Printf("Error decrypting file %d: %s", file.ID, err)
|
||||
return nil, model.ErrDecryption
|
||||
}
|
||||
return &decryptedPath, nil
|
||||
}
|
||||
|
|
5
pkg/model/errors.go
Normal file
5
pkg/model/errors.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package model
|
||||
|
||||
import "errors"
|
||||
|
||||
var ErrDecryption = errors.New("error while decrypting the file")
|
|
@ -7,6 +7,7 @@ import (
|
|||
"cli-go/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -67,7 +68,11 @@ func (c *ClICtrl) syncFiles(ctx context.Context, account model.Account) error {
|
|||
log.Printf("[%d/%d] Sync %s for album %s", i, len(entries), existingEntry.GetTitle(), albumInfo.AlbumName)
|
||||
err = c.downloadEntry(ctx, albumDiskInfo, *existingEntry, entry)
|
||||
if err != nil {
|
||||
return err
|
||||
if errors.Is(err, model.ErrDecryption) {
|
||||
continue
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Fatalf("remoteFile %d not found in remoteFiles", entry.FileID)
|
||||
|
|
|
@ -11,13 +11,13 @@ import (
|
|||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
func (c *ClICtrl) StartSync() error {
|
||||
func (c *ClICtrl) Export() error {
|
||||
accounts, err := c.GetAccounts(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(accounts) == 0 {
|
||||
fmt.Printf("No accounts to sync\n")
|
||||
fmt.Printf("No accounts to sync\n Add account using `account add` cmd\n")
|
||||
return nil
|
||||
}
|
||||
for _, account := range accounts {
|
||||
|
|
Loading…
Add table
Reference in a new issue