fix(epf-dump): require database connection, remove auto-create empty base

Dump in an empty database irreversibly loses reference types (CatalogRef,
DocumentRef, etc.) — they get converted to xs:string. Instead of silently
creating an empty temp database, the script now exits with an error
explaining that a real database is required.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-03-07 18:34:32 +03:00
co-authored by Claude Opus 4.6
parent f01f9d6ae8
commit 3097811dde
4 changed files with 12 additions and 36 deletions
+4 -16
View File
@@ -94,20 +94,11 @@ if (-not (Test-Path $V8Path)) {
exit 1
}
# --- Auto-create empty database if no connection specified ---
$autoCreatedBase = $null
# --- Validate database connection ---
if (-not $InfoBasePath -and (-not $InfoBaseServer -or -not $InfoBaseRef)) {
$autoBasePath = Join-Path $env:TEMP "epf_dump_db_$(Get-Random)"
Write-Host "No database specified. Creating temporary empty database..."
Write-Host "WARNING: Reference types (CatalogRef, DocumentRef, etc.) will be lost - converted to strings. Use a real database to preserve types." -ForegroundColor Yellow
$createArgs = "CREATEINFOBASE File=`"$autoBasePath`" /DisableStartupDialogs"
$createProc = Start-Process -FilePath $V8Path -ArgumentList $createArgs -NoNewWindow -Wait -PassThru
if ($createProc.ExitCode -ne 0) {
Write-Host "Error: failed to create temporary database" -ForegroundColor Red
exit 1
}
$InfoBasePath = $autoBasePath
$autoCreatedBase = $autoBasePath
Write-Host "Error: database connection required. Specify -InfoBasePath or -InfoBaseServer/-InfoBaseRef" -ForegroundColor Red
Write-Host "Dump in an empty database loses reference types (CatalogRef, DocumentRef, etc.) irreversibly." -ForegroundColor Yellow
exit 1
}
# --- Validate input file ---
@@ -173,7 +164,4 @@ try {
if (Test-Path $tempDir) {
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
if ($autoCreatedBase -and (Test-Path $autoCreatedBase)) {
Remove-Item -Path $autoCreatedBase -Recurse -Force -ErrorAction SilentlyContinue
}
}
+4 -16
View File
@@ -58,21 +58,11 @@ def main():
# --- Resolve V8Path ---
v8path = resolve_v8path(args.V8Path)
# --- Auto-create empty database if no connection specified ---
auto_created_base = None
# --- Validate database connection ---
if not args.InfoBasePath and (not args.InfoBaseServer or not args.InfoBaseRef):
auto_base_path = os.path.join(tempfile.gettempdir(), f"epf_dump_db_{random.randint(0, 999999)}")
print("No database specified. Creating temporary empty database...")
print("WARNING: Reference types (CatalogRef, DocumentRef, etc.) will be lost - converted to strings. Use a real database to preserve types.")
result = subprocess.run(
[v8path, "CREATEINFOBASE", f'File={auto_base_path}', "/DisableStartupDialogs"],
capture_output=True, text=True,
)
if result.returncode != 0:
print("Error: failed to create temporary database", file=sys.stderr)
sys.exit(1)
args.InfoBasePath = auto_base_path
auto_created_base = auto_base_path
print("Error: database connection required. Specify -InfoBasePath or -InfoBaseServer/-InfoBaseRef", file=sys.stderr)
print("Dump in an empty database loses reference types (CatalogRef, DocumentRef, etc.) irreversibly.")
sys.exit(1)
# --- Validate input file ---
if not os.path.isfile(args.InputFile):
@@ -140,8 +130,6 @@ def main():
finally:
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir, ignore_errors=True)
if auto_created_base and os.path.exists(auto_created_base):
shutil.rmtree(auto_created_base, ignore_errors=True)
if __name__ == "__main__":