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"
|
"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)
|
||||||
|
|||||||
Reference in New Issue
Block a user