mirror of
https://github.com/sbrow/envr.git
synced 2025-12-29 15:47:38 -05:00
feat(sync): envr can now detect if directories have moved.
This commit is contained in:
@@ -31,7 +31,7 @@ var backupCmd = &cobra.Command{
|
||||
record := app.NewEnvFile(path)
|
||||
|
||||
if err := db.Insert(record); err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("Saved %s into the database", path)
|
||||
return nil
|
||||
|
||||
19
cmd/sync.go
19
cmd/sync.go
@@ -15,6 +15,7 @@ var syncCmd = &cobra.Command{
|
||||
Short: "Update or restore your env backups",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
db, err := app.Open()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
@@ -32,7 +33,8 @@ var syncCmd = &cobra.Command{
|
||||
|
||||
for _, file := range files {
|
||||
// Syncronize the filesystem with the database.
|
||||
changed, err := file.Sync()
|
||||
oldPath := file.Path
|
||||
changed, err := db.Sync(&file)
|
||||
|
||||
var status string
|
||||
switch changed {
|
||||
@@ -42,6 +44,8 @@ var syncCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
case app.Restored:
|
||||
fallthrough
|
||||
case app.RestoredAndDirUpdated:
|
||||
status = "Restored"
|
||||
case app.Error:
|
||||
if err == nil {
|
||||
@@ -50,10 +54,23 @@ var syncCmd = &cobra.Command{
|
||||
status = err.Error()
|
||||
case app.Noop:
|
||||
status = "OK"
|
||||
case app.DirUpdated:
|
||||
status = "Moved"
|
||||
default:
|
||||
panic("Unknown result")
|
||||
}
|
||||
|
||||
if changed&app.DirUpdated == app.DirUpdated {
|
||||
if err := db.Delete(oldPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if db.UpdateRequired(changed) {
|
||||
if err := db.Insert(file); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
results = append(results, syncResult{
|
||||
Path: file.Path,
|
||||
Status: status,
|
||||
|
||||
Reference in New Issue
Block a user