mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-09-08 15:41:18 +02:00
check for isdir error before logging
This commit is contained in:
+11
-7
@@ -22,6 +22,8 @@ import (
|
||||
"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.
|
||||
//
|
||||
// If name is empty, it will be autogenerated.
|
||||
@@ -192,11 +194,14 @@ func createZip(be *BackupEvent, tempZipPath string) error {
|
||||
// copy to zip before delete
|
||||
err := copyFileToZip(zw, localPath, zipPath)
|
||||
if err != nil {
|
||||
be.App.Logger().Warn(
|
||||
logPrefix+"failed to copy file in backup zip before delete",
|
||||
slog.Any("error", err),
|
||||
slog.String("file", e.FileKey),
|
||||
)
|
||||
// it is ok to ignore directories
|
||||
if !errors.Is(err, errIsDir) {
|
||||
be.App.Logger().Warn(
|
||||
logPrefix+"failed to copy file in backup zip before delete",
|
||||
slog.Any("error", err),
|
||||
slog.String("file", e.FileKey),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// mark that it was already copied
|
||||
excluded.Set(normalizePathExclude(zipPath), struct{}{})
|
||||
@@ -301,7 +306,6 @@ func normalizePathExclude(filePath string) string {
|
||||
return path.Clean(filePath) + "/"
|
||||
}
|
||||
|
||||
// note: directories are ignored
|
||||
func copyFileToZip(w *zip.Writer, localPath string, zipPath string) error {
|
||||
info, err := os.Stat(localPath)
|
||||
if err != nil {
|
||||
@@ -309,7 +313,7 @@ func copyFileToZip(w *zip.Writer, localPath string, zipPath string) error {
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
return errIsDir
|
||||
}
|
||||
|
||||
h, err := zip.FileInfoHeader(info)
|
||||
|
||||
Reference in New Issue
Block a user