Valid and use exportDir during sync
This commit is contained in:
parent
dca3c4e2c4
commit
6285220c1b
4 changed files with 16 additions and 29 deletions
16
pkg/disk.go
16
pkg/disk.go
|
@ -3,7 +3,6 @@ package pkg
|
|||
import (
|
||||
"cli-go/pkg/model"
|
||||
"cli-go/pkg/model/export"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -99,21 +98,6 @@ func readJSONFromFile(filePath string, data interface{}) error {
|
|||
return decoder.Decode(data)
|
||||
}
|
||||
|
||||
func exportHome(ctx context.Context) (string, error) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
path := fmt.Sprintf("%s/%s", homeDir, "photos")
|
||||
if _, err = os.Stat(path); os.IsNotExist(err) {
|
||||
err = os.Mkdir(path, 0755)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
||||
func validateExportDirectory(dir string) (bool, error) {
|
||||
// Check if the path exists
|
||||
fileInfo, err := os.Stat(dir)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package pkg
|
||||
|
||||
import (
|
||||
"cli-go/pkg/model"
|
||||
"cli-go/pkg/model/export"
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
@ -12,12 +13,8 @@ import (
|
|||
"path/filepath"
|
||||
)
|
||||
|
||||
func (c *ClICtrl) createLocalFolderForRemoteAlbums(ctx context.Context) error {
|
||||
path, pathErr := exportHome(ctx)
|
||||
if pathErr != nil {
|
||||
return pathErr
|
||||
}
|
||||
|
||||
func (c *ClICtrl) createLocalFolderForRemoteAlbums(ctx context.Context, account model.Account) error {
|
||||
path := account.ExportDir
|
||||
albums, err := c.getRemoteAlbums(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -15,12 +15,9 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func (c *ClICtrl) syncFiles(ctx context.Context) error {
|
||||
func (c *ClICtrl) syncFiles(ctx context.Context, account model.Account) error {
|
||||
log.Printf("Starting sync files")
|
||||
exportRoot, err := exportHome(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exportRoot := account.ExportDir
|
||||
_, albumIDToMetaMap, err := readFolderMetadata(exportRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
13
pkg/sync.go
13
pkg/sync.go
|
@ -21,6 +21,15 @@ func (c *ClICtrl) StartSync() error {
|
|||
}
|
||||
for _, account := range accounts {
|
||||
log.SetPrefix(fmt.Sprintf("[%s-%s] ", account.App, account.Email))
|
||||
if account.ExportDir == "" {
|
||||
log.Printf("Skip account %s: no export directory configured", account.Email)
|
||||
continue
|
||||
}
|
||||
_, err = validateExportDirectory(account.ExportDir)
|
||||
if err != nil {
|
||||
log.Printf("Skip export, error: %v while validing exportDir %s\n", err, account.ExportDir)
|
||||
continue
|
||||
}
|
||||
log.Println("start sync")
|
||||
err = c.SyncAccount(account)
|
||||
if err != nil {
|
||||
|
@ -53,12 +62,12 @@ func (c *ClICtrl) SyncAccount(account model.Account) error {
|
|||
if err != nil {
|
||||
log.Printf("Error fetching files: %s", err)
|
||||
}
|
||||
err = c.createLocalFolderForRemoteAlbums(ctx)
|
||||
err = c.createLocalFolderForRemoteAlbums(ctx, account)
|
||||
if err != nil {
|
||||
log.Printf("Error creating local folders: %s", err)
|
||||
return err
|
||||
}
|
||||
err = c.syncFiles(ctx)
|
||||
err = c.syncFiles(ctx, account)
|
||||
if err != nil {
|
||||
log.Printf("Error syncing files: %s", err)
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue