diff --git a/client/client.go b/client/client.go index 56af50d..30f29e2 100644 --- a/client/client.go +++ b/client/client.go @@ -206,8 +206,8 @@ func (c *Client) doPull(ctx context.Context, g *garden.Garden) (int, error) { serverManifest := server.ProtoToManifest(pullResp.GetManifest()) localManifest := g.GetManifest() - // If local is newer or equal, nothing to do. - if !serverManifest.Updated.After(localManifest.Updated) { + // If local has files and is newer or equal, nothing to do. + if len(localManifest.Files) > 0 && !serverManifest.Updated.After(localManifest.Updated) { return 0, nil } diff --git a/cmd/sgard/list.go b/cmd/sgard/list.go index 0326e65..83f59bb 100644 --- a/cmd/sgard/list.go +++ b/cmd/sgard/list.go @@ -9,14 +9,13 @@ import ( "github.com/spf13/cobra" ) -var listRemoteFlag bool - var listCmd = &cobra.Command{ Use: "list", Short: "List all tracked files", Long: "List all tracked files locally, or on the remote server with -r.", RunE: func(cmd *cobra.Command, args []string) error { - if listRemoteFlag { + addr, _, _, _ := resolveRemoteConfig() + if addr != "" { return listRemote() } return listLocal() @@ -69,6 +68,5 @@ func printEntries(entries []manifest.Entry) { } func init() { - listCmd.Flags().BoolVarP(&listRemoteFlag, "use-remote", "r", false, "list files on the remote server") rootCmd.AddCommand(listCmd) } diff --git a/cmd/sgard/main.go b/cmd/sgard/main.go index e207e01..57a5456 100644 --- a/cmd/sgard/main.go +++ b/cmd/sgard/main.go @@ -133,7 +133,7 @@ func dialRemote(ctx context.Context) (*client.Client, func(), error) { func main() { rootCmd.PersistentFlags().StringVar(&repoFlag, "repo", defaultRepo(), "path to sgard repository") - rootCmd.PersistentFlags().StringVar(&remoteFlag, "remote", "", "gRPC server address (host:port)") + rootCmd.PersistentFlags().StringVarP(&remoteFlag, "remote", "r", "", "gRPC server address (host:port)") rootCmd.PersistentFlags().StringVar(&sshKeyFlag, "ssh-key", "", "path to SSH private key") rootCmd.PersistentFlags().BoolVar(&tlsFlag, "tls", false, "use TLS for remote connection") rootCmd.PersistentFlags().StringVar(&tlsCAFlag, "tls-ca", "", "path to CA certificate for TLS verification") diff --git a/cmd/sgard/pull.go b/cmd/sgard/pull.go index 9e135d2..a0d9650 100644 --- a/cmd/sgard/pull.go +++ b/cmd/sgard/pull.go @@ -10,13 +10,17 @@ import ( var pullCmd = &cobra.Command{ Use: "pull", - Short: "Pull checkpoint from remote server", + Short: "Pull checkpoint from remote server and restore files", RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() g, err := garden.Open(repoFlag) if err != nil { - return err + // Repo doesn't exist yet — init it so pull can populate it. + g, err = garden.Init(repoFlag) + if err != nil { + return fmt.Errorf("init repo for pull: %w", err) + } } c, cleanup, err := dialRemote(ctx) @@ -32,9 +36,22 @@ var pullCmd = &cobra.Command{ if pulled == 0 { fmt.Println("Already up to date.") - } else { - fmt.Printf("Pulled %d blob(s).\n", pulled) + return nil } + + fmt.Printf("Pulled %d blob(s).\n", pulled) + + if g.HasEncryption() && g.NeedsDEK(g.List()) { + if err := unlockDEK(g); err != nil { + return err + } + } + + if err := g.Restore(nil, true, nil); err != nil { + return fmt.Errorf("restore after pull: %w", err) + } + + fmt.Println("Restore complete.") return nil }, }