]> git.giacomolli.uk - onechat/blobdiff - backup_archive.go
Select notification targets by stable ID
[onechat] / backup_archive.go
index 3cd6013db9613b2b2ada9874ea2f0374e7043357..f68cb703932f64f55e061dd0e794fb6a67220c45 100644 (file)
@@ -125,6 +125,29 @@ func backupArchive(ctx context.Context, root, path string) (size int64, err erro
        return info.Size(), nil
 }
 
        return info.Size(), 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) {
+       file, err := os.Open(path)
+       if err != nil {
+               return fmt.Errorf("open backup file: %w", err)
+       }
+
+       defer func() {
+               err = errors.Join(err, file.Close())
+       }()
+
+       _, err = io.CopyN(out, BackupReader{
+               ctx:    ctx,
+               reader: file,
+       }, size)
+       if err != nil {
+               return fmt.Errorf("copy backup file: %w", err)
+       }
+
+       return nil
+}
+
 // backupExtract restores regular files and directories in an empty staging
 // directory. Links, duplicate entries, unsafe names, and special modes fail.
 // Directory modes apply last so a read-only directory can hold files.
 // backupExtract restores regular files and directories in an empty staging
 // directory. Links, duplicate entries, unsafe names, and special modes fail.
 // Directory modes apply last so a read-only directory can hold files.
@@ -218,27 +241,19 @@ func backupExtract(ctx context.Context, path, root string) (err error) {
        return nil
 }
 
        return 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) {
-       file, err := os.Open(path)
-       if err != nil {
-               return fmt.Errorf("open backup file: %w", err)
+// backupExcluded keeps runtime locks, sockets, probe files, and import copies
+// out of the snapshot.
+func backupExcluded(name string) bool {
+       first, _, _ := strings.Cut(filepath.ToSlash(name), "/")
+       if first == socketFileName || first == tokenLockFileName || first == "probe" || strings.HasPrefix(first, "agent-backup-") {
+               return true
        }
 
        }
 
-       defer func() {
-               err = errors.Join(err, file.Close())
-       }()
-
-       _, err = io.CopyN(out, BackupReader{
-               ctx:    ctx,
-               reader: file,
-       }, size)
-       if err != nil {
-               return fmt.Errorf("copy backup file: %w", err)
+       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
        }
 
        }
 
-       return nil
+       return false
 }
 
 func backupExtractFile(in io.Reader, path string, mode os.FileMode) (err error) {
 }
 
 func backupExtractFile(in io.Reader, path string, mode os.FileMode) (err error) {
@@ -263,18 +278,3 @@ func backupExtractFile(in io.Reader, path string, mode os.FileMode) (err error)
 
        return nil
 }
 
        return nil
 }
-
-// backupExcluded keeps runtime locks, sockets, probe files, and import copies
-// out of the snapshot.
-func backupExcluded(name string) bool {
-       first, _, _ := strings.Cut(filepath.ToSlash(name), "/")
-       if first == socketFileName || first == tokenLockFileName || first == "probe" || strings.HasPrefix(first, "agent-backup-") {
-               return true
-       }
-
-       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
-       }
-
-       return false
-}