Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-przybyl-wttech committed Aug 24, 2024
1 parent 90cf57d commit 23879c1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
34 changes: 14 additions & 20 deletions pkg/content_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/oak_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
26 changes: 12 additions & 14 deletions pkg/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand All @@ -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
}
}
Expand All @@ -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
}
Expand Down

0 comments on commit 23879c1

Please sign in to comment.