Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK Compact command #285

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmd/aem/oak.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (c *CLI) oakCmd() *cobra.Command {
Short: "Manages OAK repository",
}
cmd.AddCommand(c.oakIndexCmd())
cmd.AddCommand(c.oakCompactCmd())
return cmd
}

Expand Down Expand Up @@ -195,3 +196,33 @@ func oakIndexByFlags(cmd *cobra.Command, i pkg.Instance) (*pkg.OAKIndex, error)
}
return nil, fmt.Errorf("flag 'name' is required")
}

func (c *CLI) oakCompactCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "compact",
Short: "Compact OAK store",
Run: func(cmd *cobra.Command, args []string) {
instances, err := c.aem.InstanceManager().Some()
if err != nil {
c.Error(err)
return
}
compacted, err := pkg.InstanceProcess(c.aem, instances, func(instance pkg.Instance) (map[string]any, error) {
if err := instance.OAK().Compact(); err != nil {
return nil, err
}
return map[string]any{
OutputChanged: true,
"instance": instance,
}, nil
})
if err != nil {
c.Error(err)
return
}
c.SetOutput("compacted", compacted)
c.Changed("store compacted")
},
}
return cmd
}
8 changes: 8 additions & 0 deletions pkg/oak.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ func NewOAK(instance *Instance) *OAK {
func (o *OAK) IndexManager() *OAKIndexManager {
return o.indexManager
}

func (o *OAK) oakRun() *OakRun {
return o.instance.manager.aem.vendorManager.oakRun
}

func (o *OAK) Compact() error {
return o.instance.manager.aem.vendorManager.oakRun.Compact(o.instance.local.Dir())
}
23 changes: 22 additions & 1 deletion pkg/oak_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ func (or OakRun) SetPassword(instanceDir string, user string, password string) e
return nil
}

func (or OakRun) StoreDir(instanceDir string) string {
return fmt.Sprintf("%s/%s", instanceDir, or.StorePath)
}

func (or OakRun) RunScript(instanceDir string, scriptFile string) error {
storeDir := fmt.Sprintf("%s/%s", instanceDir, or.StorePath)
storeDir := or.StoreDir(instanceDir)
cmd, err := or.vendorManager.javaManager.Command(
"-Djava.io.tmpdir="+pathx.Canonical(or.vendorManager.aem.baseOpts.TmpDir),
"-jar", or.JarFile(),
Expand All @@ -114,3 +118,20 @@ func (or OakRun) RunScript(instanceDir string, scriptFile string) error {
}
return nil
}

func (or OakRun) Compact(instanceDir string) error {
storeDir := or.StoreDir(instanceDir)
cmd, err := or.vendorManager.javaManager.Command(
"-Djava.io.tmpdir="+pathx.Canonical(or.vendorManager.aem.baseOpts.TmpDir),
"-jar", or.JarFile(),
"compact", storeDir,
)
if err != nil {
return err
}
or.vendorManager.aem.CommandOutput(cmd)
if err := cmd.Run(); err != nil {
return fmt.Errorf("cannot run Oak Run compact command for instance dir '%s': %w", instanceDir, err)
}
return nil
}
Loading