Skip to content

Commit 04aaf32

Browse files
committed
chore: amend docs
1 parent ecc773a commit 04aaf32

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

docs/zed.md

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/cmd/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func registerBackupCmd(rootCmd *cobra.Command) {
6666

6767
backupCreateCmd := &cobra.Command{
6868
Use: "create <filename-or-dash>",
69-
Short: "Backup a permission system to a file or to stdout (denoted by a dash)",
69+
Short: "Back up a permission system to a file, or to stdout by passing \"-\"",
7070
Args: commands.ValidationWrapper(cobra.MaximumNArgs(1)),
7171
RunE: withErrorHandling(backupCreateCmdFunc),
7272
}

pkg/backupformat/encoder.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,22 @@ func (e *OcfEncoder) Close() error {
193193
// format, while also persisting it to a file and maintaining a lockfile that
194194
// tracks the progress so that it can be resumed if stopped.
195195
type OcfFileEncoder struct {
196-
file *os.File
197-
lastSyncedCursor string
198-
completed bool
199-
// isStream is true when the underlying file is a stream (e.g. os.Stdout)
196+
// file is the destination the encoder writes to. For regular backups this
197+
// is a file on disk; when streaming it is os.Stdout.
198+
file *os.File
199+
// fileIsStream is true when the underlying file is a stream (e.g. os.Stdout)
200200
// for which lockfile-based progress tracking and Sync/Close are not
201201
// applicable.
202-
isStream bool
202+
fileIsStream bool
203+
// lastSyncedCursor is the most recent cursor value written to the lockfile.
204+
// It is used to avoid redundant lockfile writes when the cursor has not
205+
// advanced since the previous Append call.
206+
lastSyncedCursor string
207+
// completed indicates that the backup finished successfully. When true,
208+
// Close removes the lockfile because no resume is needed.
209+
completed bool
210+
// OcfEncoder is the embedded AVRO OCF encoder that performs the actual
211+
// serialization of relationships into the file.
203212
*OcfEncoder
204213
}
205214

@@ -208,7 +217,7 @@ func (fe *OcfFileEncoder) lockFileName() string {
208217
}
209218

210219
func (fe *OcfFileEncoder) Cursor() (string, error) {
211-
if fe.isStream {
220+
if fe.fileIsStream {
212221
return "", errors.New("resume is not supported when streaming to stdout")
213222
}
214223
cursorBytes, err := os.ReadFile(fe.lockFileName())
@@ -236,16 +245,16 @@ func NewFileEncoder(filename string) (e *OcfFileEncoder, existed bool, err error
236245
}
237246
}
238247

239-
return &OcfFileEncoder{file: f, isStream: isStream, OcfEncoder: &OcfEncoder{w: f}}, backupExisted, nil
248+
return &OcfFileEncoder{file: f, fileIsStream: isStream, OcfEncoder: &OcfEncoder{w: f}}, backupExisted, nil
240249
}
241250

242251
func (fe *OcfFileEncoder) Append(r *v1.Relationship, cursor string) error {
243252
if err := fe.OcfEncoder.Append(r, cursor); err != nil {
244253
return fmt.Errorf("error storing relationship: %w", err)
245254
}
246255

247-
// Streamed destinations (e.g. stdout) cannot be checkpointed.
248-
if fe.isStream {
256+
// Streaming destinations (e.g. stdout) can't be resumed, so skip writing the cursor lockfile.
257+
if fe.fileIsStream {
249258
return nil
250259
}
251260

@@ -270,14 +279,14 @@ func (fe *OcfFileEncoder) Close() error {
270279
fe.OcfEncoder.Close()
271280
// Stdout is owned by the process; Sync would fail with
272281
// "inappropriate ioctl for device" and we must not close it.
273-
if fe.isStream {
282+
if fe.fileIsStream {
274283
return nil
275284
}
276285
return errors.Join(fe.file.Sync(), fe.file.Close())
277286
}
278287

279288
removeCompleted := func() error {
280-
if fe.isStream {
289+
if fe.fileIsStream {
281290
return nil
282291
}
283292
if fe.completed {

0 commit comments

Comments
 (0)