Skip to content

Commit 755f642

Browse files
author
Dominik Przybyl
committed
minor
1 parent 5f79a8f commit 755f642

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

cmd/aem/content.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func (c *CLI) contentPushCmd() *cobra.Command {
198198
if err = instance.ContentManager().Push(path, clean, vault, pkg.PackageCreateOpts{
199199
FilterRoots: filterRoots,
200200
ExcludePatterns: excludePatterns,
201+
ContentPath: path,
201202
}); err != nil {
202203
c.Error(err)
203204
return
@@ -340,7 +341,7 @@ func determineFilterRoots(cmd *cobra.Command) []string {
340341

341342
func determineExcludePatterns(cmd *cobra.Command) []string {
342343
file, _ := determineContentFile(cmd)
343-
if file == "" || !strings.HasSuffix(file, content.JCRContentFile) {
344+
if file == "" || !strings.HasSuffix(file, content.JCRContentFile) || content.IsPageContentFile(file) {
344345
return nil
345346
}
346347

pkg/content/content.go

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
XmlFileSuffix = ".xml"
2323
JCRMixinTypesProp = "jcr:mixinTypes"
2424
JCRRootPrefix = "<jcr:root"
25+
JCRContentNode = "jcr:content"
2526
PropPattern = "^\\s*([^ =]+)=\"([^\"]+)\"(.*)$"
2627
NamespacePattern = "^\\w+:(\\w+)=\"[^\"]+\"$"
2728
FileWithNamespacePattern = "[\\\\/]_([a-zA-Z0-9]+)_[^\\\\/]+([\\\\/]\\.content)?\\.xml$"
@@ -357,3 +358,18 @@ func determineStringSlice(values any, key string) []string {
357358
}
358359
return result
359360
}
361+
362+
func IsPageContentFile(path string) bool {
363+
if pathx.IsDir(path) || !strings.HasSuffix(path, JCRContentFile) {
364+
return false
365+
}
366+
367+
lines, err := readLines(path)
368+
if err != nil {
369+
return false
370+
}
371+
372+
return lo.SomeBy(lines, func(line string) bool {
373+
return strings.Contains(line, "cq:PageContent")
374+
})
375+
}

pkg/content_manager.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (cm *ContentManager) Download(localFile string, clean bool, vault bool, opt
119119
return nil
120120
}
121121

122-
func (cm *ContentManager) PullDir(dir string, clean bool, replace bool, vault bool, opts PackageCreateOpts) error {
122+
func (cm *ContentManager) PullDir(dir string, clean bool, vault bool, replace bool, opts PackageCreateOpts) error {
123123
workDir := pathx.RandomDir(cm.tmpDir(), "content_pull")
124124
defer func() { _ = pathx.DeleteIfExists(workDir) }()
125125
if err := cm.pullContent(workDir, vault, opts); err != nil {
@@ -168,11 +168,8 @@ func (cm *ContentManager) PullFile(file string, clean bool, vault bool, opts Pac
168168

169169
func (cm *ContentManager) pushContent(destInstance *Instance, vault bool, opts PackageCreateOpts) error {
170170
if vault {
171-
mainDir := opts.ContentPath
172-
if pathx.IsFile(mainDir) {
173-
mainDir = filepath.Dir(mainDir)
174-
}
175-
jcrPath := DetermineFilterRoot(mainDir)
171+
mainDir, _, _ := strings.Cut(opts.ContentPath, content.JCRRoot)
172+
jcrPath := DetermineFilterRoot(opts.ContentPath)
176173
vaultCliArgs := []string{
177174
"vlt",
178175
"--credentials", fmt.Sprintf("%s:%s", destInstance.user, destInstance.password),
@@ -202,10 +199,10 @@ func (cm *ContentManager) Push(path string, clean bool, vault bool, opts Package
202199
}
203200
workDir := pathx.RandomDir(cm.tmpDir(), "content_push")
204201
defer func() { _ = pathx.DeleteIfExists(workDir) }()
202+
if opts.PID == "" {
203+
opts.PID = fmt.Sprintf("aemc:content-push:%s-SNAPSHOT", timex.FileTimestampForNow())
204+
}
205205
if clean || vault && pathx.IsFile(path) {
206-
if opts.PID == "" {
207-
opts.PID = fmt.Sprintf("aemc:content-push:%s-SNAPSHOT", timex.FileTimestampForNow())
208-
}
209206
if err := copyPackageAllFiles(workDir, opts); err != nil {
210207
return err
211208
}

pkg/package_manager.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ func (pm *PackageManager) Create(opts PackageCreateOpts) (string, error) {
240240
func DetermineFilterRoot(path string) string {
241241
_, filterRoot, _ := strings.Cut(path, content.JCRRoot)
242242
filterRoot = strings.ReplaceAll(filterRoot, "\\", "/")
243-
if strings.HasSuffix(path, content.JCRContentFile) {
243+
if content.IsPageContentFile(path) {
244+
filterRoot = strings.ReplaceAll(filterRoot, content.JCRContentFile, content.JCRContentNode)
245+
} else if strings.HasSuffix(path, content.JCRContentFile) {
244246
filterRoot = filepath.Dir(filterRoot)
245247
} else if strings.HasSuffix(path, content.XmlFileSuffix) {
246248
filterRoot = strings.ReplaceAll(filterRoot, content.XmlFileSuffix, "")

0 commit comments

Comments
 (0)