X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/a5c83e92d7feea2e104b5515043a76c8c4c56c60..f5c601f1801aaa276f8c335fcb51c373edc0b50c:/backup_archive.go diff --git a/backup_archive.go b/backup_archive.go index 0c3544f..35a389c 100644 --- a/backup_archive.go +++ b/backup_archive.go @@ -13,6 +13,25 @@ import ( "strings" ) +// BackupReader checks cancellation between reads of an archive or file. +type BackupReader struct { + ctx context.Context + reader io.Reader +} + +func (r BackupReader) Read(data []byte) (int, error) { + if r.ctx.Err() != nil { + return 0, r.ctx.Err() + } + + count, err := r.reader.Read(data) + if err != nil { + return count, fmt.Errorf("read backup data: %w", err) + } + + return count, nil +} + // backupArchive writes the files in root to path through a private temporary // file and a rename. Only directories and regular files enter the archive. func backupArchive(ctx context.Context, root, path string) (size int64, err error) { @@ -197,25 +216,6 @@ func backupExtract(ctx context.Context, path, root string) (err error) { return nil } -// BackupReader checks cancellation between reads of an archive or file. -type BackupReader struct { - ctx context.Context - reader io.Reader -} - -func (r BackupReader) Read(data []byte) (int, error) { - if r.ctx.Err() != nil { - return 0, r.ctx.Err() - } - - count, err := r.reader.Read(data) - if err != nil { - return count, fmt.Errorf("read backup data: %w", err) - } - - return count, nil -} - // backupCopyFile copies the size fixed at the snapshot of path. Growth after // that point is not part of the copy, and a shorter file is an error. func backupCopyFile(ctx context.Context, out io.Writer, path string, size int64) (err error) {