From 2bc73b555cd93433b93f7ce02718000df7c57db0 Mon Sep 17 00:00:00 2001 From: wayblink Date: Tue, 20 Aug 2024 11:39:24 +0800 Subject: [PATCH] Fix: mkdir before copying file for local chunk manager (#401) Signed-off-by: jason.jin Co-authored-by: jason.jin --- core/storage/local_chunk_manager.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/storage/local_chunk_manager.go b/core/storage/local_chunk_manager.go index 815cb863..833d038a 100644 --- a/core/storage/local_chunk_manager.go +++ b/core/storage/local_chunk_manager.go @@ -238,6 +238,20 @@ func CopyDir(source string, dest string) (err error) { } func CopyFile(source string, dest string) (err error) { + + // get properties of source parent dir + sourceParentDir := filepath.Dir(source) + sourceParentDirInfo, err := os.Stat(sourceParentDir) + if err != nil { + return err + } + // create dest parent dir + destParentDir := filepath.Dir(dest) + err = os.MkdirAll(destParentDir, sourceParentDirInfo.Mode()) + if err != nil { + return err + } + sourcefile, err := os.Open(source) if err != nil { return err