From 913c3a5740d89b6453a2e4bcace50e73709b4cc3 Mon Sep 17 00:00:00 2001 From: Volkov Date: Tue, 26 Feb 2019 20:58:59 +0200 Subject: [PATCH 1/3] added flag parallel to assemble command --- cmd/assembly.go | 16 ++++++++-- cmd/assembly_test.go | 4 +-- internal/archive/fsops.go | 41 +++++++++++++++++++++--- internal/archive/fsops_test.go | 44 +++++++++++++++++++++++--- internal/artifacts/module_arch.go | 32 +++++++++++-------- internal/artifacts/module_arch_test.go | 34 ++++++++++++-------- 6 files changed, 129 insertions(+), 42 deletions(-) diff --git a/cmd/assembly.go b/cmd/assembly.go index d4374365d..92242f48e 100644 --- a/cmd/assembly.go +++ b/cmd/assembly.go @@ -19,6 +19,7 @@ const ( var assembleCmdSrc string var assembleCmdTrg string var assembleCmdMtarName string +var assembleCmdParallel string func init() { assemblyCommand.Flags().StringVarP(&assembleCmdSrc, @@ -27,8 +28,12 @@ func init() { "target", "t", "", "the path to the MBT results folder; the current path is default") assemblyCommand.Flags().StringVarP(&assembleCmdMtarName, "mtar", "m", "", "the archive name") + assemblyCommand.Flags().StringVarP(&assembleCmdParallel, + "parallel", "p", "false", "if true content copying will run in parallel") + } + // Generate mtar from build artifacts var assemblyCommand = &cobra.Command{ Use: "assemble", @@ -37,7 +42,7 @@ var assemblyCommand = &cobra.Command{ ValidArgs: []string{"Deployment descriptor location"}, Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - err := assembly(assembleCmdSrc, assembleCmdTrg, defaultPlatform, mtarCmdMtarName, os.Getwd) + err := assembly(assembleCmdSrc, assembleCmdTrg, defaultPlatform, mtarCmdMtarName, assembleCmdParallel, os.Getwd) logError(err) return err }, @@ -45,10 +50,15 @@ var assemblyCommand = &cobra.Command{ SilenceErrors: true, } -func assembly(source, target, platform, mtarName string, getWd func() (string, error)) error { +func assembly(source, target, platform, mtarName, copyInParallel string, getWd func() (string, error)) error { logs.Logger.Info("assembling the MTA project...") + + parallelCopy, err := strconv.ParseBool(copyInParallel) + if err != nil { + parallelCopy = false + } // copy from source to target - err := artifacts.CopyMtaContent(source, target, dir.Dep, getWd) + err = artifacts.CopyMtaContent(source, target, dir.Dep, parallelCopy, getWd) if err != nil { return errors.Wrap(err, "assembly of the MTA project failed when copying the MTA content") } diff --git a/cmd/assembly_test.go b/cmd/assembly_test.go index ecba5e26a..9271b727a 100644 --- a/cmd/assembly_test.go +++ b/cmd/assembly_test.go @@ -16,14 +16,14 @@ var _ = Describe("Assembly", func() { }) It("Sanity", func() { err := assembly(getTestPath("assembly-sample"), - getTestPath("result"), "cf", "", os.Getwd) + getTestPath("result"), "cf", "", "?", os.Getwd) Ω(err).Should(Succeed()) Ω(getTestPath("result", "com.sap.xs2.samples.javahelloworld_0.1.0.mtar")).Should(BeAnExistingFile()) }) var _ = DescribeTable("Fails on location initialization", func(maxCalls int) { calls := 0 err := assembly("", - getTestPath("result"), "cf", "", func() (string, error) { + getTestPath("result"), "cf", "", "true", func() (string, error) { calls++ if calls >= maxCalls { return "", errors.New("error") diff --git a/internal/archive/fsops.go b/internal/archive/fsops.go index 420b02c4a..711b7d60b 100755 --- a/internal/archive/fsops.go +++ b/internal/archive/fsops.go @@ -136,7 +136,7 @@ func CreateFile(path string) (file *os.File, err error) { } // CopyDir - copy directory content -func CopyDir(src string, dst string, withParents bool) error { +func CopyDir(src string, dst string, withParents bool, copyDirEntries func(entries []os.FileInfo, src, dst string) error) error { src = filepath.Clean(src) dst = filepath.Clean(dst) @@ -158,7 +158,7 @@ func CopyDir(src string, dst string, withParents bool) error { if err != nil { return err } - return CopyEntries(entries, src, dst) + return copyDirEntries(entries, src, dst) } // CopyByPatterns - copy files/directories according to patterns @@ -231,7 +231,7 @@ func copyEntries(entries []string, source, target, pattern string) error { } targetEntry := filepath.Join(target, filepath.Base(entry)) if info.IsDir() { - err = CopyDir(entry, targetEntry, true) + err = CopyDir(entry, targetEntry, true, CopyEntries) } else { err = CopyFileWithMode(entry, targetEntry, info.Mode()) } @@ -245,7 +245,38 @@ func copyEntries(entries []string, source, target, pattern string) error { } // CopyEntries - copies entries (files and directories) from source to destination folder -func CopyEntries(entries []os.FileInfo, src, dst string) (rerr error) { +func CopyEntries(entries []os.FileInfo, src, dst string) error { + + if len(entries) == 0 { + return nil + } + for _, entry := range entries { + var err error + srcPath := filepath.Join(src, entry.Name()) + dstPath := filepath.Join(dst, entry.Name()) + + if entry.IsDir() { + // execute recursively + err = CopyDir(srcPath, dstPath, false, CopyEntries) + } else { + // Todo check posix compatibility + if entry.Mode()&os.ModeSymlink != 0 { + logs.Logger.Infof( + `copying of the entries from the "%v" folder to the "%v" folder skipped the "%v" entry because its mode is a symbolic link`, + src, dst, entry.Name()) + } else { + err = CopyFileWithMode(srcPath, dstPath, entry.Mode()) + } + } + if err != nil { + return err + } + } + return nil +} + +// CopyEntriesInParallel - copies entries (files and directories) from source to destination folder in parallel +func CopyEntriesInParallel(entries []os.FileInfo, src, dst string) (rerr error) { if len(entries) == 0 { return nil @@ -266,7 +297,7 @@ func CopyEntries(entries []os.FileInfo, src, dst string) (rerr error) { if e.IsDir() { // execute recursively - err = CopyDir(srcPath, dstPath, false) + err = CopyDir(srcPath, dstPath, false, CopyEntriesInParallel) } else { // Todo check posix compatibility if e.Mode()&os.ModeSymlink != 0 { diff --git a/internal/archive/fsops_test.go b/internal/archive/fsops_test.go index e2f73cbb5..a800330d3 100644 --- a/internal/archive/fsops_test.go +++ b/internal/archive/fsops_test.go @@ -109,21 +109,42 @@ var _ = Describe("FSOPS", func() { os.RemoveAll(targetPath) }) - It("Sanity", func() { + It("Sanity - parallel", func() { + sourcePath := getFullPath("testdata", "level2") + Ω(CopyDir(sourcePath, targetPath, true, CopyEntriesInParallel)).Should(Succeed()) + Ω(countFilesInDir(targetPath)).Should(Equal(countFilesInDir(sourcePath))) + }) + + It("Sanity - not parallel", func() { sourcePath := getFullPath("testdata", "level2") - Ω(CopyDir(sourcePath, targetPath, true)).Should(Succeed()) + Ω(CopyDir(sourcePath, targetPath, true, CopyEntries)).Should(Succeed()) Ω(countFilesInDir(targetPath)).Should(Equal(countFilesInDir(sourcePath))) }) It("TargetFileLocked", func() { f, _ := os.Create(targetPath) sourcePath := getFullPath("testdata", "level2") - Ω(CopyDir(sourcePath, targetPath, true)).Should(HaveOccurred()) + Ω(CopyDir(sourcePath, targetPath, true, CopyEntries )).Should(HaveOccurred()) + f.Close() + }) + + It("TargetFileLocked", func() { + f, _ := os.Create(targetPath) + sourcePath := getFullPath("testdata", "level2") + Ω(CopyDir(sourcePath, targetPath, true, CopyEntriesInParallel)).Should(HaveOccurred()) f.Close() }) var _ = DescribeTable("Invalid cases", func(source, target string) { - Ω(CopyDir(source, targetPath, true)).Should(HaveOccurred()) + Ω(CopyDir(source, targetPath, true, CopyEntries)).Should(HaveOccurred()) + }, + Entry("SourceDirectoryDoesNotExist", getFullPath("testdata", "level5"), targetPath), + Entry("SourceIsNotDirectory", getFullPath("testdata", "level2", "level2_one.txt"), targetPath), + Entry("DstDirectoryNotValid", getFullPath("level2"), ":"), + ) + + var _ = DescribeTable("Invalid cases - parallel", func(source, target string) { + Ω(CopyDir(source, targetPath, true, CopyEntriesInParallel)).Should(HaveOccurred()) }, Entry("SourceDirectoryDoesNotExist", getFullPath("testdata", "level5"), targetPath), Entry("SourceIsNotDirectory", getFullPath("testdata", "level2", "level2_one.txt"), targetPath), @@ -168,6 +189,21 @@ var _ = Describe("FSOPS", func() { Ω(countFilesInDir(sourcePath) - 1).Should(Equal(countFilesInDir(targetPath))) os.RemoveAll(targetPath) }) + It("Sanity - copy in parallel", func() { + sourcePath := getFullPath("testdata", "level2", "level3") + targetPath := getFullPath("testdata", "result") + os.MkdirAll(targetPath, os.ModePerm) + files, _ := ioutil.ReadDir(sourcePath) + // Files wrapped to overwrite their methods + var filesWrapped []os.FileInfo + Ω(CopyEntriesInParallel(filesWrapped, sourcePath, targetPath)).Should(Succeed()) + for _, file := range files { + filesWrapped = append(filesWrapped, testFile{file: file}) + } + Ω(CopyEntriesInParallel(filesWrapped, sourcePath, targetPath)).Should(Succeed()) + Ω(countFilesInDir(sourcePath) - 1).Should(Equal(countFilesInDir(targetPath))) + os.RemoveAll(targetPath) + }) }) var _ = Describe("Copy By Patterns", func() { diff --git a/internal/artifacts/module_arch.go b/internal/artifacts/module_arch.go index 3c6d4181f..360091918 100644 --- a/internal/artifacts/module_arch.go +++ b/internal/artifacts/module_arch.go @@ -155,7 +155,7 @@ func copyModuleArchive(ep dir.IModule, modulePath, moduleName string) error { // CopyMtaContent copies the content of all modules and resources which are presented in the deployment descriptor, // in the source directory, to the target directory -func CopyMtaContent(source, target, desc string, wdGetter func() (string, error)) error { +func CopyMtaContent(source, target, desc string, copyInParallel bool, wdGetter func() (string, error)) error { logs.Logger.Info("copying the MTA content...") loc, err := dir.Location(source, target, desc, wdGetter) @@ -167,29 +167,29 @@ func CopyMtaContent(source, target, desc string, wdGetter func() (string, error) if err != nil { return errors.Wrapf(err, `copying the MTA content failed when parsing the %s file`, loc.GetMtaYamlPath()) } - err = copyModuleContent(loc.GetSource(), loc.GetTargetTmpDir(), mta) + err = copyModuleContent(loc.GetSource(), loc.GetTargetTmpDir(), mta, copyInParallel) if err != nil { return err } - err = copyRequiredDependencyContent(loc.GetSource(), loc.GetTargetTmpDir(), mta) + err = copyRequiredDependencyContent(loc.GetSource(), loc.GetTargetTmpDir(), mta, copyInParallel) if err != nil { return err } - return copyResourceContent(loc.GetSource(), loc.GetTargetTmpDir(), mta) + return copyResourceContent(loc.GetSource(), loc.GetTargetTmpDir(), mta, copyInParallel) } -func copyModuleContent(source, target string, mta *mta.MTA) error { - return copyMtaContent(source, target, getModulesWithPaths(mta.Modules)) +func copyModuleContent(source, target string, mta *mta.MTA, copyInParallel bool) error { + return copyMtaContent(source, target, getModulesWithPaths(mta.Modules), copyInParallel) } -func copyResourceContent(source, target string, mta *mta.MTA) error { - return copyMtaContent(source, target, getResourcesPaths(mta.Resources)) +func copyResourceContent(source, target string, mta *mta.MTA, copyInParallel bool) error { + return copyMtaContent(source, target, getResourcesPaths(mta.Resources), copyInParallel) } -func copyRequiredDependencyContent(source, target string, mta *mta.MTA) error { - return copyMtaContent(source, target, getRequiredDependencyPaths(mta.Modules)) +func copyRequiredDependencyContent(source, target string, mta *mta.MTA, copyInParallel bool) error { + return copyMtaContent(source, target, getRequiredDependencyPaths(mta.Modules), copyInParallel) } func getRequiredDependencyPaths(mtaModules []*mta.Module) []string { @@ -210,7 +210,7 @@ func getRequiredDependenciesWithPathsForModule(module *mta.Module) []string { } return result } -func copyMtaContent(source, target string, mtaPaths []string) error { +func copyMtaContent(source, target string, mtaPaths []string, copyInParallel bool) error { copiedMtaContents := make([]string, 0) for _, mtaPath := range mtaPaths { sourceMtaContent := filepath.Join(source, mtaPath) @@ -220,7 +220,7 @@ func copyMtaContent(source, target string, mtaPaths []string) error { } copiedMtaContents = append(copiedMtaContents, mtaPath) targetMtaContent := filepath.Join(target, mtaPath) - err := copyMtaContentFromPath(sourceMtaContent, targetMtaContent, mtaPath, target) + err := copyMtaContentFromPath(sourceMtaContent, targetMtaContent, mtaPath, target, copyInParallel) if err != nil { return handleCopyMtaContentFailure(target, copiedMtaContents, `error copying the "%s" MTA content to the "%s" target directory because: %s`, []interface{}{mtaPath, source, err.Error()}) @@ -240,10 +240,14 @@ func handleCopyMtaContentFailure(targetLocation string, copiedMtaContents []stri return fmt.Errorf(message+"; cleanup failed", messageArguments...) } -func copyMtaContentFromPath(sourceMtaContent, targetMtaContent, mtaContentPath, target string) error { +func copyMtaContentFromPath(sourceMtaContent, targetMtaContent, mtaContentPath, target string, copyInParallel bool) error { mtaContentInfo, _ := os.Stat(sourceMtaContent) if mtaContentInfo.IsDir() { - return dir.CopyDir(sourceMtaContent, targetMtaContent, true) + if copyInParallel { + return dir.CopyDir(sourceMtaContent, targetMtaContent, true, dir.CopyEntriesInParallel) + } else { + return dir.CopyDir(sourceMtaContent, targetMtaContent, true, dir.CopyEntries) + } } mtaContentParentDir := filepath.Dir(mtaContentPath) diff --git a/internal/artifacts/module_arch_test.go b/internal/artifacts/module_arch_test.go index e8fec833c..be9dc0b9f 100644 --- a/internal/artifacts/module_arch_test.go +++ b/internal/artifacts/module_arch_test.go @@ -271,13 +271,13 @@ module-types: source, _ = ioutil.TempDir("", "testing-mta-content") }) It("Without no deployment descriptor in the source directory", func() { - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, true, os.Getwd) Ω(err).Should(Not(BeNil())) fmt.Println(err.Error()) Ω(err.Error()).Should(ContainSubstring(fmt.Sprintf(`failed to read the "%s%smtad.yaml" file: open %s%smtad.yaml`, source, pathSep, source, pathSep))) }) It("Location initialization fails", func() { - err := CopyMtaContent("", source, defaultDeploymentDescriptorParam, func() (string, error) { + err := CopyMtaContent("", source, defaultDeploymentDescriptorParam, false, func() (string, error) { return "", errors.New("error") }) Ω(err).Should(Not(BeNil())) @@ -289,18 +289,18 @@ module-types: mta := generateTestMta(source, 2, 0, map[string]string{}, map[string]string{"test-module-0": "zip", "test-module-1": "folder"}) mtaBytes, _ := yaml.Marshal(mta) ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm) - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, true, os.Getwd) Ω(err).Should((BeNil())) info, _ := os.Stat(source) Ω(dirContainsAllElements(source, map[string]bool{"." + info.Name() + dir.TempFolderSuffix: true}, false)).Should(Equal(true)) Ω(dirContainsAllElements(filepath.Join(source, "."+info.Name()+dir.TempFolderSuffix), map[string]bool{"test.zip": true, "test-content": true}, true)).Should(Equal(true)) }) - It("With a deployment descriptor in the source directory with one module path and one resource path as zip archuve and a folder", func() { + It("With a deployment descriptor in the source directory with one module path and one resource path as zip archive and a folder", func() { createFileInGivenPath(filepath.Join(source, defaultDeploymentDescriptorName)) mta := generateTestMta(source, 1, 1, map[string]string{}, map[string]string{"test-resource-0": "zip", "test-module-0": "folder"}) mtaBytes, _ := yaml.Marshal(mta) ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm) - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, true, os.Getwd) Ω(err).Should((BeNil())) info, _ := os.Stat(source) Ω(dirContainsAllElements(source, map[string]bool{"." + info.Name() + dir.TempFolderSuffix: true}, false)).Should(Equal(true)) @@ -311,7 +311,7 @@ module-types: mta := generateTestMta(source, 0, 2, map[string]string{}, map[string]string{"test-resource-0": "zip", "test-resource-1": "folder"}) mtaBytes, _ := yaml.Marshal(mta) ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm) - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, true, os.Getwd) Ω(err).Should((BeNil())) info, _ := os.Stat(source) Ω(dirContainsAllElements(source, map[string]bool{"." + info.Name() + dir.TempFolderSuffix: true}, false)).Should(Equal(true)) @@ -322,7 +322,7 @@ module-types: mta := generateTestMta(source, 2, 2, map[string]string{}, map[string]string{"test-resource-0": "zip", "test-resource-1": "zip", "test-module-0": "zip", "test-module-1": "zip"}) mtaBytes, _ := yaml.Marshal(mta) ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm) - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, false, os.Getwd) Ω(err).Should((BeNil())) info, _ := os.Stat(source) Ω(dirContainsAllElements(source, map[string]bool{"." + info.Name() + dir.TempFolderSuffix: true}, false)).Should(Equal(true)) @@ -334,7 +334,7 @@ module-types: mta := generateTestMta(source, 1, 0, map[string]string{"test-module-0": "test-required"}, map[string]string{"test-module-0": "folder", "test-required": "zip"}) mtaBytes, _ := yaml.Marshal(mta) ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm) - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, false, os.Getwd) Ω(err).Should((BeNil())) info, _ := os.Stat(source) Ω(dirContainsAllElements(source, map[string]bool{"." + info.Name() + dir.TempFolderSuffix: true}, false)).Should(Equal(true)) @@ -346,7 +346,7 @@ module-types: mta.Modules[0].Requires[0].Parameters["path"] = "zip1" mtaBytes, _ := yaml.Marshal(mta) ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm) - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, true, os.Getwd) Ω(err).Should(HaveOccurred()) }) @@ -355,7 +355,7 @@ module-types: mta := generateTestMta(source, 1, 0, map[string]string{}, map[string]string{"test-module-0": "not-existing-contet"}) mtaBytes, _ := yaml.Marshal(mta) ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm) - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, false, os.Getwd) Ω(err).Should(Not(BeNil())) Ω(err.Error()).Should(Equal(`"not-existing-content" does not exist in the MTA project location`)) info, _ := os.Stat(source) @@ -368,7 +368,7 @@ module-types: mta := generateTestMta(source, 2, 0, map[string]string{}, map[string]string{"test-module-0": "not-existing-contet", "test-module-1": "zip"}) mtaBytes, _ := yaml.Marshal(mta) ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm) - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, false, os.Getwd) Ω(err).Should(Not(BeNil())) Ω(err.Error()).Should(Equal(`"not-existing-content" does not exist in the MTA project location`)) info, _ := os.Stat(source) @@ -385,7 +385,7 @@ module-types: mta := generateTestMta(source, 10, 0, map[string]string{}, modulesWithSameContent) mtaBytes, _ := yaml.Marshal(mta) ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm) - err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, os.Getwd) + err := CopyMtaContent(source, source, defaultDeploymentDescriptorParam, false, os.Getwd) Ω(err).Should((BeNil())) info, _ := os.Stat(source) Ω(dirContainsAllElements(source, map[string]bool{"." + info.Name() + dir.TempFolderSuffix: true}, false)).Should(Equal(true)) @@ -402,7 +402,13 @@ module-types: file, _ := os.Create(getTestPath("result")) defer file.Close() Ω(copyMtaContentFromPath(getTestPath("mta", "mta.yaml"), getTestPath("result", "mta.yaml"), - getTestPath("result", "mta.yaml"), getTestPath("result"))).Should(HaveOccurred()) + getTestPath("result", "mta.yaml"), getTestPath("result"), true)).Should(HaveOccurred()) + }) + It("content is file; fails because target folder exists and it's not a folder, but a file; not parallel", func() { + file, _ := os.Create(getTestPath("result")) + defer file.Close() + Ω(copyMtaContentFromPath(getTestPath("mta", "mta.yaml"), getTestPath("result", "mta.yaml"), + getTestPath("result", "mta.yaml"), getTestPath("result"), false)).Should(HaveOccurred()) }) }) @@ -478,7 +484,7 @@ func getContentPath(contentType, source string) string { } if contentType == "folder" { dir.CopyDir(getTestPath("mta_content_copy_test", "test-content"), - filepath.Join(source, "test-content"), true) + filepath.Join(source, "test-content"), true, dir.CopyEntries) return "test-content" } From 8ba6bae6e1746bd6c58f875d1c06af0f2d42d27b Mon Sep 17 00:00:00 2001 From: Volkov Date: Tue, 26 Feb 2019 21:06:12 +0200 Subject: [PATCH 2/3] fix lint --- internal/archive/fsops.go | 34 +++++++++++++++++----------------- internal/archive/fsops_test.go | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/archive/fsops.go b/internal/archive/fsops.go index 711b7d60b..b86d24a25 100755 --- a/internal/archive/fsops.go +++ b/internal/archive/fsops.go @@ -251,27 +251,27 @@ func CopyEntries(entries []os.FileInfo, src, dst string) error { return nil } for _, entry := range entries { - var err error - srcPath := filepath.Join(src, entry.Name()) - dstPath := filepath.Join(dst, entry.Name()) + var err error + srcPath := filepath.Join(src, entry.Name()) + dstPath := filepath.Join(dst, entry.Name()) - if entry.IsDir() { - // execute recursively - err = CopyDir(srcPath, dstPath, false, CopyEntries) + if entry.IsDir() { + // execute recursively + err = CopyDir(srcPath, dstPath, false, CopyEntries) + } else { + // Todo check posix compatibility + if entry.Mode()&os.ModeSymlink != 0 { + logs.Logger.Infof( + `copying of the entries from the "%v" folder to the "%v" folder skipped the "%v" entry because its mode is a symbolic link`, + src, dst, entry.Name()) } else { - // Todo check posix compatibility - if entry.Mode()&os.ModeSymlink != 0 { - logs.Logger.Infof( - `copying of the entries from the "%v" folder to the "%v" folder skipped the "%v" entry because its mode is a symbolic link`, - src, dst, entry.Name()) - } else { - err = CopyFileWithMode(srcPath, dstPath, entry.Mode()) - } - } - if err != nil { - return err + err = CopyFileWithMode(srcPath, dstPath, entry.Mode()) } } + if err != nil { + return err + } + } return nil } diff --git a/internal/archive/fsops_test.go b/internal/archive/fsops_test.go index a800330d3..884cf8820 100644 --- a/internal/archive/fsops_test.go +++ b/internal/archive/fsops_test.go @@ -124,7 +124,7 @@ var _ = Describe("FSOPS", func() { It("TargetFileLocked", func() { f, _ := os.Create(targetPath) sourcePath := getFullPath("testdata", "level2") - Ω(CopyDir(sourcePath, targetPath, true, CopyEntries )).Should(HaveOccurred()) + Ω(CopyDir(sourcePath, targetPath, true, CopyEntries)).Should(HaveOccurred()) f.Close() }) From e6ade5d6cf8c8a0db600bce6cce4a333398ad304 Mon Sep 17 00:00:00 2001 From: Volkov Date: Tue, 26 Feb 2019 21:11:38 +0200 Subject: [PATCH 3/3] fix lint --- cmd/assembly.go | 1 - internal/artifacts/module_arch.go | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/assembly.go b/cmd/assembly.go index 92242f48e..3ddb05b85 100644 --- a/cmd/assembly.go +++ b/cmd/assembly.go @@ -33,7 +33,6 @@ func init() { } - // Generate mtar from build artifacts var assemblyCommand = &cobra.Command{ Use: "assemble", diff --git a/internal/artifacts/module_arch.go b/internal/artifacts/module_arch.go index 360091918..07a40e35a 100644 --- a/internal/artifacts/module_arch.go +++ b/internal/artifacts/module_arch.go @@ -245,9 +245,8 @@ func copyMtaContentFromPath(sourceMtaContent, targetMtaContent, mtaContentPath, if mtaContentInfo.IsDir() { if copyInParallel { return dir.CopyDir(sourceMtaContent, targetMtaContent, true, dir.CopyEntriesInParallel) - } else { - return dir.CopyDir(sourceMtaContent, targetMtaContent, true, dir.CopyEntries) } + return dir.CopyDir(sourceMtaContent, targetMtaContent, true, dir.CopyEntries) } mtaContentParentDir := filepath.Dir(mtaContentPath)