X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/6844f8c992ec4e276a3a0d93b544de0127eebbd2..c781f79f3c8cb9a7577ee1574d196988da2719b3:/backup_archive.go?ds=inline diff --git a/backup_archive.go b/backup_archive.go index 9560cd1..3cd6013 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) { @@ -82,6 +101,7 @@ func backupArchive(ctx context.Context, root, path string) (size int64, err erro return nil }) + err = errors.Join(err, archive.Close(), compressed.Close()) if err != nil { return 0, fmt.Errorf("write archive: %w", err) @@ -131,6 +151,7 @@ func backupExtract(ctx context.Context, path, root string) (err error) { ctx: ctx, reader: compressed, }) + seen := make(map[string]bool) var directories []*tar.Header @@ -197,25 +218,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) { @@ -270,7 +272,7 @@ func backupExcluded(name string) bool { return true } - if filepath.Base(name) == "lock" { + if filepath.Base(name) == "lock" || (first == imageDirName && strings.HasPrefix(filepath.Base(name), ".image-")) || (first == voiceDirName && (strings.HasPrefix(filepath.Base(name), ".voice-") || strings.HasPrefix(filepath.Base(name), ".transcript-"))) { return true }