diff --git a/golang/pghoard_postgres_command_go.go b/golang/pghoard_postgres_command_go.go index 13a5fbd1..1a6a9eba 100644 --- a/golang/pghoard_postgres_command_go.go +++ b/golang/pghoard_postgres_command_go.go @@ -81,7 +81,7 @@ func run() (int, error) { retry_seconds := *riPtr for { attempt += 1 - rc, err := restore_command(url, *outputPtr) + rc, err := restore_command(url, *outputPtr, *xlogPtr) if rc != EXIT_RESTORE_FAIL { return rc, err } @@ -100,7 +100,7 @@ func archive_command(url string) (int, error) { return EXIT_ABORT, errors.New("archive_command not yet implemented") } -func restore_command(url string, output string) (int, error) { +func restore_command(url string, output string, xlog string) (int, error) { var output_path string var req *http.Request var err error @@ -120,6 +120,16 @@ func restore_command(url string, output string) (int, error) { } output_path = path.Join(cwd, output) } + // if file ".pghoard.prefetch" exists, just move it to destination + xlogPrefetchPath := path.Join(path.Dir(output_path), xlog+".pghoard.prefetch") + _, err = os.Stat(xlogPrefetchPath) + if err == nil { + err := os.Rename(xlogPrefetchPath, output_path) + if err != nil { + return EXIT_ABORT, err + } + return EXIT_OK, nil + } req, err = http.NewRequest("GET", url, nil) req.Header.Set("x-pghoard-target-path", output_path) }