check for isdir error before logging

This commit is contained in:
Gani Georgiev
2026-08-22 19:27:03 +03:00
parent 18cb3dc62f
commit eade68d4a3
+11 -7
View File
@@ -22,6 +22,8 @@ import (
"github.com/pocketbase/pocketbase/tools/store" "github.com/pocketbase/pocketbase/tools/store"
) )
var errIsDir = errors.New("the specified path is a directory and not a regular file")
// CreateBackup creates a new backup of the current app pb_data directory. // CreateBackup creates a new backup of the current app pb_data directory.
// //
// If name is empty, it will be autogenerated. // If name is empty, it will be autogenerated.
@@ -192,11 +194,14 @@ func createZip(be *BackupEvent, tempZipPath string) error {
// copy to zip before delete // copy to zip before delete
err := copyFileToZip(zw, localPath, zipPath) err := copyFileToZip(zw, localPath, zipPath)
if err != nil { if err != nil {
be.App.Logger().Warn( // it is ok to ignore directories
logPrefix+"failed to copy file in backup zip before delete", if !errors.Is(err, errIsDir) {
slog.Any("error", err), be.App.Logger().Warn(
slog.String("file", e.FileKey), logPrefix+"failed to copy file in backup zip before delete",
) slog.Any("error", err),
slog.String("file", e.FileKey),
)
}
} else { } else {
// mark that it was already copied // mark that it was already copied
excluded.Set(normalizePathExclude(zipPath), struct{}{}) excluded.Set(normalizePathExclude(zipPath), struct{}{})
@@ -301,7 +306,6 @@ func normalizePathExclude(filePath string) string {
return path.Clean(filePath) + "/" return path.Clean(filePath) + "/"
} }
// note: directories are ignored
func copyFileToZip(w *zip.Writer, localPath string, zipPath string) error { func copyFileToZip(w *zip.Writer, localPath string, zipPath string) error {
info, err := os.Stat(localPath) info, err := os.Stat(localPath)
if err != nil { if err != nil {
@@ -309,7 +313,7 @@ func copyFileToZip(w *zip.Writer, localPath string, zipPath string) error {
} }
if info.IsDir() { if info.IsDir() {
return nil return errIsDir
} }
h, err := zip.FileInfoHeader(info) h, err := zip.FileInfoHeader(info)