Skip to content

Improve pg_restore errors; auto-detect archives; gzip/ZIP input support#70

Merged
ababic merged 9 commits into
mainfrom
cursor/pg-restore-detect-bad8d
May 5, 2026
Merged

Improve pg_restore errors; auto-detect archives; gzip/ZIP input support#70
ababic merged 9 commits into
mainfrom
cursor/pg-restore-detect-bad8d

Conversation

@ababic

@ababic ababic commented May 4, 2026

Copy link
Copy Markdown
Owner

Summary

Expands input handling for Dumpling’s default --input path:

gzip / ZIP auto-handling

  • gzip (0x1f 0x8b): decompress to a temp file (streaming decompress via flate2), then continue — supports e.g. .sql.gz, gzipped PGDMP custom-format archives before pg_restore.
  • ZIP (PK\x03\x04): extract one member — either the only file in the archive, or the only .sql when multiple files exist. Inner extension preserved (.dump, .sql, …).

Combinations gzip → ZIP → inner file work (e.g. .zip.gz).

Safety / ergonomics

  • --in-place: rejected when gzip or ZIP wrappers were applied (must use --output/stdout; avoids ambiguous overwrite of the compressed path vs temp decoded content).
  • pg_restore archive deletion: only removes the original archive path when appropriate; skips removal when the archive lived under system temp (already cleaned by CompressionCleanup).
  • process::exit: temp cleanup runs (drop(compression_cleanup)) before exit codes 1–3.

Earlier PR behavior (still included)

  • Postgres custom (PGDMP) / directory (toc.dat) auto-detect, MSSQL binary/ZIP UTF-16 hints, friendlier pg_restore errors.

Dependencies

  • flate2, zip (deflate only).

Tests / CI

  • cargo fmt, cargo clippy --all-targets --all-features, cargo test --all-targets --all-features

Changelog

  • [Unreleased] entry for gzip/ZIP.

Slack Thread

Open in Web Open in Cursor 

@cursor cursor Bot changed the title Improve --dump-decode errors when pg_restore is missing or fails Improve pg_restore errors; auto-detect archives; gzip/ZIP input support May 4, 2026
cursoragent and others added 5 commits May 5, 2026 07:54
- Add pg_restore_decode module: preflight when --pg-restore-path is a
  concrete path, improved spawn/exit errors with install hint, capture
  pg_restore stderr (tee to stderr) and include on non-zero exit
- Reap pg_restore in scaffold-config when discovery fails; only remove
  archive after full success
- Remove unused Context import from main

Co-authored-by: Andy Babic <ababic@users.noreply.github.com>
- Add compressed_input: sniff gzip (1f 8b) and ZIP (PK), decompress/extract
  to temp files with Drop cleanup; combined gzip-then-ZIP supported
- ZIP: single member wins; else exactly one .sql file among multiple files
- Fail --in-place when input used gzip/ZIP wrappers (unsafe path semantics)
- pg_restore archive removal skips paths under temp dir (avoid double-delete)
- Dependencies: flate2, zip (deflate only)
- scaffold-config mirrors main pipeline; changelog [Unreleased]

Co-authored-by: Andy Babic <ababic@users.noreply.github.com>
--keep-original combined with --in-place now fails fast with a clear error,
matching gzip/ZIP and pg_restore archive restrictions. Updated scaffold path,
ResolvedConfig test helpers, and changelog for unified keep-original/pg_restore
settings.

Co-authored-by: Andy Babic <ababic@users.noreply.github.com>
Gzip-wrapped plain SQL is decompressed with flate2 and fed into the pipeline
without a temp file. PGDMP, nested gzip->ZIP, and ZIP extraction still use
temp paths registered on CompressionCleanup. --in-place now rejects only
inputs that required a materialized temp file from compression handling.

Refactors MSSQL classification with classify_mssql_prefix for sniff buffers.

Co-authored-by: Andy Babic <ababic@users.noreply.github.com>
…ginal

Replace deprecated --dump-decode guidance with auto-detection, streaming gzip,
temp ZIP/PGDMP behavior, [pg_restore] TOML, --keep-original vs --in-place, and
--check with archives. Update README and mdBook configuration/getting-started/index.

Co-authored-by: Andy Babic <ababic@users.noreply.github.com>
@ababic ababic force-pushed the cursor/pg-restore-detect-bad8d branch from 39e94cd to f31d6de Compare May 5, 2026 06:54
cursoragent and others added 3 commits May 5, 2026 07:00
Co-authored-by: Andy Babic <ababic@users.noreply.github.com>
Co-authored-by: Andy Babic <ababic@users.noreply.github.com>
Extract resolve_dump_input_from_path into dump_input_resolve.rs so scaffold-config
uses the same gzip/ZIP, MSSQL classification, pg_restore, and archive-removal
logic as run_anonymize. Document new modules in AGENTS.md.

Co-authored-by: Andy Babic <ababic@users.noreply.github.com>
Comment thread src/dump_input_resolve.rs Fixed
Comment thread src/dump_input_resolve.rs Fixed
Add log_sanitize::path_basename_for_log and use it for pg_restore progress lines,
gzip/ZIP notices, archive removal, scaffold write/remove messages, and plaintext
salt warnings — avoids emitting full filesystem paths that may contain sensitive
directory names. Context/full paths remain in anyhow messages where appropriate.

Co-authored-by: Andy Babic <ababic@users.noreply.github.com>
@ababic ababic marked this pull request as ready for review May 5, 2026 08:05
@ababic ababic merged commit fe1927f into main May 5, 2026
10 checks passed
@ababic ababic deleted the cursor/pg-restore-detect-bad8d branch May 5, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants