diff --git a/pkg/content_manager.go b/pkg/content_manager.go index d07495c..284e7cb 100644 --- a/pkg/content_manager.go +++ b/pkg/content_manager.go @@ -51,9 +51,7 @@ func (cm *ContentManager) Download(localFile string, packageOpts PackageCreateOp if err != nil { return err } - defer func() { - _ = cm.pkgMgr().Delete(remotePath) - }() + defer func() { _ = cm.pkgMgr().Delete(remotePath) }() if err := cm.pkgMgr().Build(remotePath); err != nil { return err } @@ -65,14 +63,14 @@ func (cm *ContentManager) Download(localFile string, packageOpts PackageCreateOp func (cm *ContentManager) PullDir(dir string, clean bool, replace bool, opts PackageCreateOpts) error { pkgFile := pathx.RandomFileName(cm.tmpDir(), "content_pull", ".zip") - if err := cm.Download(pkgFile, opts); err != nil { - return err - } workDir := pathx.RandomDir(cm.tmpDir(), "content_pull") defer func() { _ = pathx.DeleteIfExists(pkgFile) _ = pathx.DeleteIfExists(workDir) }() + if err := cm.Download(pkgFile, opts); err != nil { + return err + } if err := content.Unzip(pkgFile, workDir); err != nil { return err } @@ -105,14 +103,14 @@ func (cm *ContentManager) PullDir(dir string, clean bool, replace bool, opts Pac func (cm *ContentManager) PullFile(file string, clean bool, opts PackageCreateOpts) error { pkgFile := pathx.RandomFileName(cm.tmpDir(), "content_pull", ".zip") - if err := cm.Download(pkgFile, opts); err != nil { - return err - } workDir := pathx.RandomDir(cm.tmpDir(), "content_pull") defer func() { _ = pathx.DeleteIfExists(pkgFile) _ = pathx.DeleteIfExists(workDir) }() + if err := cm.Download(pkgFile, opts); err != nil { + return err + } if err := content.Unzip(pkgFile, workDir); err != nil { return err } @@ -135,19 +133,17 @@ func (cm *ContentManager) PullFile(file string, clean bool, opts PackageCreateOp return nil } -func (cm *ContentManager) Push(contentPath string, clean bool, packageOpts PackageCreateOpts) error { - if !pathx.Exists(contentPath) { - return fmt.Errorf("cannot push content as it does not exist '%s'", contentPath) +func (cm *ContentManager) Push(path string, clean bool, packageOpts PackageCreateOpts) error { + if !pathx.Exists(path) { + return fmt.Errorf("cannot push content as it does not exist '%s'", path) } if packageOpts.PID == "" { packageOpts.PID = fmt.Sprintf("aemc:content-push:%s-SNAPSHOT", timex.FileTimestampForNow()) } if clean { workDir := pathx.RandomDir(cm.tmpDir(), "content_push") - defer func() { - _ = pathx.DeleteIfExists(workDir) - }() - if err := copyContentFiles(contentPath, workDir); err != nil { + defer func() { _ = pathx.DeleteIfExists(workDir) }() + if err := copyContentFiles(path, workDir); err != nil { return err } contentManager := cm.instance.manager.aem.contentManager @@ -156,15 +152,13 @@ func (cm *ContentManager) Push(contentPath string, clean bool, packageOpts Packa } packageOpts.ContentPath = filepath.Join(workDir, content.JCRRoot) } else { - packageOpts.ContentPath = contentPath + packageOpts.ContentPath = path } remotePath, err := cm.pkgMgr().Create(packageOpts) if err != nil { return err } - defer func() { - _ = cm.pkgMgr().Delete(remotePath) - }() + defer func() { _ = cm.pkgMgr().Delete(remotePath) }() if err = cm.pkgMgr().Install(remotePath); err != nil { return err } diff --git a/pkg/oak_run.go b/pkg/oak_run.go index a1f419b..034a1ac 100644 --- a/pkg/oak_run.go +++ b/pkg/oak_run.go @@ -86,9 +86,7 @@ func (or OakRun) SetPassword(instanceDir string, user string, password string) e if err := tplx.RenderFile(scriptFile, instance.OakRunSetPassword, map[string]any{"User": user, "Password": password}); err != nil { return err } - defer func() { - pathx.DeleteIfExists(scriptFile) - }() + defer func() { pathx.DeleteIfExists(scriptFile) }() if err := or.RunScript(instanceDir, scriptFile); err != nil { return err } diff --git a/pkg/package_manager.go b/pkg/package_manager.go index e188c65..9e78b0c 100644 --- a/pkg/package_manager.go +++ b/pkg/package_manager.go @@ -230,14 +230,14 @@ func (pm *PackageManager) Create(opts PackageCreateOpts) (string, error) { return status.Path, nil } -func DetermineFilterRoot(contentPath string) string { - _, filterRoot, _ := strings.Cut(contentPath, content.JCRRoot) +func DetermineFilterRoot(path string) string { + _, filterRoot, _ := strings.Cut(path, content.JCRRoot) filterRoot = strings.ReplaceAll(filterRoot, "\\", "/") - if strings.HasSuffix(filterRoot, content.JCRContentFile) && content.IsContentFile(contentPath) { + if strings.HasSuffix(path, content.JCRContentFile) && content.IsContentFile(path) { filterRoot = strings.ReplaceAll(filterRoot, content.JCRContentFile, content.JCRContentNode) - } else if strings.HasSuffix(filterRoot, content.JCRContentFile) { + } else if strings.HasSuffix(path, content.JCRContentFile) { filterRoot = filepath.Dir(filterRoot) - } else if strings.HasSuffix(filterRoot, content.XmlFileSuffix) { + } else if strings.HasSuffix(path, content.XmlFileSuffix) { filterRoot = strings.ReplaceAll(filterRoot, content.XmlFileSuffix, "") } filterRoot = namespacePatternRegex.ReplaceAllString(filterRoot, "/$2:") @@ -246,14 +246,14 @@ func DetermineFilterRoot(contentPath string) string { return filterRoot } -func copyContentFiles(contentPath string, tmpDir string) error { - _, jcrPath, _ := strings.Cut(contentPath, content.JCRRoot) - if pathx.IsDir(contentPath) { - if err := filex.CopyDir(contentPath, filepath.Join(tmpDir, content.JCRRoot, jcrPath)); err != nil { +func copyContentFiles(path string, tmpDir string) error { + _, jcrPath, _ := strings.Cut(path, content.JCRRoot) + if pathx.IsDir(path) { + if err := filex.CopyDir(path, filepath.Join(tmpDir, content.JCRRoot, jcrPath)); err != nil { return err } - } else if pathx.IsFile(contentPath) { - if err := filex.Copy(contentPath, filepath.Join(tmpDir, content.JCRRoot, jcrPath), true); err != nil { + } else if pathx.IsFile(path) { + if err := filex.Copy(path, filepath.Join(tmpDir, content.JCRRoot, jcrPath), true); err != nil { return err } } @@ -262,9 +262,7 @@ func copyContentFiles(contentPath string, tmpDir string) error { func (pm *PackageManager) Copy(remotePath string, destInstance *Instance) error { var localPath = pathx.RandomFileName(pm.tmpDir(), "pkg_copy", ".zip") - defer func() { - _ = pathx.DeleteIfExists(localPath) - }() + defer func() { _ = pathx.DeleteIfExists(localPath) }() if err := pm.Download(remotePath, localPath); err != nil { return err }