Skip to content

fix: support backup create when streaming to stdout#691

Merged
miparnisari merged 3 commits intoauthzed:mainfrom
ivanauth:fix/backup-stdout-lockfile
May 5, 2026
Merged

fix: support backup create when streaming to stdout#691
miparnisari merged 3 commits intoauthzed:mainfrom
ivanauth:fix/backup-stdout-lockfile

Conversation

@ivanauth
Copy link
Copy Markdown
Contributor

@ivanauth ivanauth commented May 4, 2026

Summary

zed backup create - (write backup to stdout) currently fails with:

failed to store cursor in lockfile: cannot create temp file: open /dev/stdout.lock343325193: operation not permitted
sync /dev/stdout: inappropriate ioctl for device

OcfFileEncoder was attempting to write a cursor lockfile derived from fe.file.Name() (resolving to /dev/stdout.lock) and calling file.Sync() / file.Close() on os.Stdout during shutdown.

This was reported in the review of #688: #688 (review).

Closes #284.

OcfFileEncoder previously failed when the destination was "-" (stdout):
- Append wrote a cursor lockfile derived from fe.file.Name(), which
  resolved to /dev/stdout.lock and failed with "operation not permitted".
- Close called file.Sync() and file.Close() on os.Stdout, surfacing
  "inappropriate ioctl for device".

Track an isStream flag on the encoder; skip lockfile/sync/close when set
and surface a clear error from Cursor() since resume is not supported
on streams.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.72%. Comparing base (97d4943) to head (c0d2b3b).

Files with missing lines Patch % Lines
pkg/backupformat/encoder.go 87.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #691      +/-   ##
==========================================
+ Coverage   43.60%   43.72%   +0.12%     
==========================================
  Files          38       38              
  Lines        6178     6193      +15     
==========================================
+ Hits         2694     2708      +14     
+ Misses       3204     3203       -1     
- Partials      280      282       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@miparnisari miparnisari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind updating the help text of zed backup create? Currently it says

$ ./zed backup create --help
Backup a permission system to a file

Usage:
  zed backup create <filename> [flags]

let's make it "Backup a permission system to a file or to stdout (denoted by a dash)"

and zed backup create <filename-or-dash>

@ivanauth
Copy link
Copy Markdown
Contributor Author

ivanauth commented May 5, 2026

Updated in ecc773a.

@miparnisari miparnisari enabled auto-merge (squash) May 5, 2026 17:23
@miparnisari miparnisari force-pushed the fix/backup-stdout-lockfile branch from d51308e to 04aaf32 Compare May 5, 2026 17:24
@miparnisari miparnisari merged commit 37aca55 into authzed:main May 5, 2026
13 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zed backup to stdout or existing file

3 participants