From e803427b09282c3ad9f75dc03d7ae77c2a98903c Mon Sep 17 00:00:00 2001 From: vie-serendipity <2733147505@qq.com> Date: Tue, 8 Oct 2024 17:54:19 +0800 Subject: [PATCH 1/4] fix: create abspath dir in case that contents is empty --- pkg/yurthub/storage/disk/storage.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/yurthub/storage/disk/storage.go b/pkg/yurthub/storage/disk/storage.go index c4373ea465c..8220b05c022 100644 --- a/pkg/yurthub/storage/disk/storage.go +++ b/pkg/yurthub/storage/disk/storage.go @@ -383,6 +383,10 @@ func (ds *diskStorage) ReplaceComponentList(component string, gvr schema.GroupVe // 2. create new file with contents // TODO: if error happens, we may need retry mechanism, or add some mechanism to do consistency check. + // create abspath dir in case that contents is empty + if err := ds.fsOperator.CreateDir(absPath); err != nil { + klog.Errorf("could not create dir at %s, %v", absPath, err) + } for key, data := range contents { path := filepath.Join(ds.baseDir, key.Key()) if err := ds.fsOperator.CreateDir(filepath.Dir(path)); err != nil && err != fs.ErrExists { From 15a3c476d717795a15a4e373625da49cd37495d5 Mon Sep 17 00:00:00 2001 From: vie-serendipity <2733147505@qq.com> Date: Fri, 18 Oct 2024 14:35:50 +0800 Subject: [PATCH 2/4] feat: return err directly when creating dir failed --- pkg/yurthub/storage/disk/storage.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/yurthub/storage/disk/storage.go b/pkg/yurthub/storage/disk/storage.go index 8220b05c022..888acad8233 100644 --- a/pkg/yurthub/storage/disk/storage.go +++ b/pkg/yurthub/storage/disk/storage.go @@ -386,6 +386,7 @@ func (ds *diskStorage) ReplaceComponentList(component string, gvr schema.GroupVe // create abspath dir in case that contents is empty if err := ds.fsOperator.CreateDir(absPath); err != nil { klog.Errorf("could not create dir at %s, %v", absPath, err) + return err } for key, data := range contents { path := filepath.Join(ds.baseDir, key.Key()) From 2c6380e2453dbf37e0a07377af43d408aa71580a Mon Sep 17 00:00:00 2001 From: vie-serendipity <2733147505@qq.com> Date: Fri, 18 Oct 2024 14:43:18 +0800 Subject: [PATCH 3/4] feat: check len of content equal to 0 --- pkg/yurthub/storage/disk/storage.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/yurthub/storage/disk/storage.go b/pkg/yurthub/storage/disk/storage.go index 888acad8233..7dbeaec0b53 100644 --- a/pkg/yurthub/storage/disk/storage.go +++ b/pkg/yurthub/storage/disk/storage.go @@ -384,9 +384,11 @@ func (ds *diskStorage) ReplaceComponentList(component string, gvr schema.GroupVe // 2. create new file with contents // TODO: if error happens, we may need retry mechanism, or add some mechanism to do consistency check. // create abspath dir in case that contents is empty - if err := ds.fsOperator.CreateDir(absPath); err != nil { - klog.Errorf("could not create dir at %s, %v", absPath, err) - return err + if len(contents) == 0 { + if err := ds.fsOperator.CreateDir(absPath); err != nil { + klog.Errorf("could not create dir at %s, %v", absPath, err) + return err + } } for key, data := range contents { path := filepath.Join(ds.baseDir, key.Key()) From 516384825a55c886dab7f8b0647b75c21411b64f Mon Sep 17 00:00:00 2001 From: vie-serendipity <2733147505@qq.com> Date: Fri, 18 Oct 2024 14:48:23 +0800 Subject: [PATCH 4/4] feat: cancel to check len of content equal to 0 --- pkg/yurthub/storage/disk/storage.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/yurthub/storage/disk/storage.go b/pkg/yurthub/storage/disk/storage.go index 7dbeaec0b53..888acad8233 100644 --- a/pkg/yurthub/storage/disk/storage.go +++ b/pkg/yurthub/storage/disk/storage.go @@ -384,11 +384,9 @@ func (ds *diskStorage) ReplaceComponentList(component string, gvr schema.GroupVe // 2. create new file with contents // TODO: if error happens, we may need retry mechanism, or add some mechanism to do consistency check. // create abspath dir in case that contents is empty - if len(contents) == 0 { - if err := ds.fsOperator.CreateDir(absPath); err != nil { - klog.Errorf("could not create dir at %s, %v", absPath, err) - return err - } + if err := ds.fsOperator.CreateDir(absPath); err != nil { + klog.Errorf("could not create dir at %s, %v", absPath, err) + return err } for key, data := range contents { path := filepath.Join(ds.baseDir, key.Key())