feat(themes): implement PlanForce
This commit is contained in:
@@ -4,7 +4,6 @@ package themes
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
@@ -116,5 +115,45 @@ func (m Module) Verify(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
|
||||
return module.Plan{}, errors.New("PlanForce not implemented")
|
||||
dst, err := destRoot()
|
||||
if err != nil {
|
||||
return module.Plan{}, err
|
||||
}
|
||||
var pairs []filePair
|
||||
err = filepath.WalkDir(m.cfg.Source, func(p string, d fs.DirEntry, werr error) error {
|
||||
if werr != nil {
|
||||
return werr
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
rel, _ := filepath.Rel(m.cfg.Source, p)
|
||||
pairs = append(pairs, filePair{src: p, dst: filepath.Join(dst, rel)})
|
||||
return nil
|
||||
})
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return module.Plan{}, err
|
||||
}
|
||||
if len(pairs) == 0 {
|
||||
return module.Plan{}, nil
|
||||
}
|
||||
return module.Plan{Actions: []module.Action{{
|
||||
Description: fmt.Sprintf("rewrite %d theme files (force)", len(pairs)),
|
||||
Kind: module.ActionFileWrite,
|
||||
Exec: func(ctx context.Context) error {
|
||||
for _, fp := range pairs {
|
||||
if err := os.MkdirAll(filepath.Dir(fp.dst), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := os.ReadFile(fp.src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(fp.dst, data, 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}}}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user