Skip to content

Commit bf0e7ff

Browse files
committed
review comments
Signed-off-by: Pravin Pushkar <[email protected]>
1 parent 2007ed5 commit bf0e7ff

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

pkg/standalone/common.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,35 @@ func DefaultConfigFilePath() string {
7070

7171
// emptyAndCopyFiles copies files from src to dest. It deletes the existing files in dest before copying from src.
7272
// TODO: Remove this function when `--components-path` flag is removed.
73-
func moveFilesFromComponentsToResourcesDir(componentsDirPath, resourcesDirPath string) error {
74-
if _, err := os.Stat(componentsDirPath); err == nil {
75-
files, err := os.ReadDir(resourcesDirPath)
73+
func emptyAndCopyFiles(src, dest string) error {
74+
if _, err := os.Stat(src); err != nil {
75+
return err
76+
}
77+
files, err := os.ReadDir(dest)
78+
if err != nil {
79+
return err
80+
}
81+
for _, file := range files {
82+
err = os.Remove(dest + "/" + file.Name())
7683
if err != nil {
7784
return err
7885
}
86+
}
87+
files, err = os.ReadDir(src)
88+
if err != nil {
89+
return err
90+
}
91+
if len(files) > 0 {
92+
print.InfoStatusEvent(os.Stdout, "Moving files from %q to %q", src, dest)
7993
for _, file := range files {
80-
err = os.Remove(resourcesDirPath + "/" + file.Name())
94+
content, err := os.ReadFile(src + "/" + file.Name())
8195
if err != nil {
8296
return err
8397
}
84-
}
85-
files, err = os.ReadDir(componentsDirPath)
86-
if err != nil {
87-
return err
88-
}
89-
if len(files) > 0 {
90-
print.InfoStatusEvent(os.Stdout, "Moving files from %q to %q", componentsDirPath, resourcesDirPath)
91-
for _, file := range files {
92-
content, err := os.ReadFile(componentsDirPath + "/" + file.Name())
93-
if err != nil {
94-
return err
95-
}
96-
// #nosec G306
97-
err = os.WriteFile(resourcesDirPath+"/"+file.Name(), content, 0o644)
98-
if err != nil {
99-
return err
100-
}
98+
// #nosec G306
99+
err = os.WriteFile(dest+"/"+file.Name(), content, 0o644)
100+
if err != nil {
101+
return err
101102
}
102103
}
103104
}

pkg/standalone/standalone.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
295295
if isAirGapInit {
296296
dockerContainerNames = []string{DaprPlacementContainerName}
297297
}
298+
var ok bool
298299
for _, container := range dockerContainerNames {
299300
containerName := utils.CreateContainerName(container, dockerNetwork)
300-
var ok bool
301301
ok, err = confirmContainerIsRunningOrExists(containerName, true, runtimeCmd)
302302
if err != nil {
303303
return err
@@ -309,7 +309,7 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
309309
print.InfoStatusEvent(os.Stdout, "Use `%s ps` to check running containers.", runtimeCmd)
310310
}
311311
// TODO: remove below method when components-path flag is removed.
312-
err = moveFilesFromComponentsToResourcesDir(DefaultComponentsDirPath(), DefaultResourcesDirPath())
312+
err = emptyAndCopyFiles(DefaultComponentsDirPath(), DefaultResourcesDirPath())
313313
if err != nil {
314314
return err
315315
}
@@ -707,7 +707,7 @@ func makeDefaultResourcesDir() error {
707707
if os.IsNotExist(err) {
708708
errDir := os.MkdirAll(resourcesDir, 0o755)
709709
if errDir != nil {
710-
return fmt.Errorf("error creating default components folder: %w", errDir)
710+
return fmt.Errorf("error creating default resources folder: %w", errDir)
711711
}
712712
}
713713

tests/e2e/standalone/componentsDir_to_resourcesDir_mig_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// TODO: Remove the test when `--components-path` flag is removed.
1718
package standalone_test
1819

1920
import (

0 commit comments

Comments
 (0)