MCPcopy Create free account
hub / github.com/containers/fetchit / Apply

Method Apply

pkg/engine/apply.go:97–133  ·  view source on GitHub ↗

Side effects are running/applying changes concurrently and on success moving old "current" tag

(
	ctx context.Context,
	mo *SingleMethodObj,
	currentState plumbing.Hash,
	desiredState plumbing.Hash,
	targetPath string,
	tags *[]string,
)

Source from the content-addressed store, hash-verified

95
96// Side effects are running/applying changes concurrently and on success moving old "current" tag
97func (fc *FetchitConfig) Apply(
98 ctx context.Context,
99 mo *SingleMethodObj,
100 currentState plumbing.Hash,
101 desiredState plumbing.Hash,
102 targetPath string,
103 tags *[]string,
104) error {
105 if desiredState.IsZero() {
106 return errors.New("Cannot run Apply if desired state is empty")
107 }
108 directory := filepath.Base(mo.Target.Url)
109
110 currentTree, err := getTreeFromHash(directory, currentState)
111 if err != nil {
112 return utils.WrapErr(err, "Error getting tree from hash %s", currentState)
113 }
114
115 desiredTree, err := getTreeFromHash(directory, desiredState)
116 if err != nil {
117 return utils.WrapErr(err, "Error getting tree from hash %s", desiredState)
118 }
119
120 changeMap, err := getFilteredChangeMap(directory, targetPath, currentTree, desiredTree, tags)
121 if err != nil {
122 return utils.WrapErr(err, "Error getting filtered change map from %s to %s", currentState, desiredState)
123 }
124
125 err = fc.runChangesConcurrent(ctx, mo, changeMap)
126 if err != nil {
127 return utils.WrapErr(err, "Error applying change from %s to %s for path %s in %s",
128 currentState, desiredState, targetPath, directory,
129 )
130 }
131
132 return nil
133}
134
135func getTreeFromHash(directory string, hash plumbing.Hash) (*object.Tree, error) {
136 if hash.IsZero() {

Callers 5

processRawMethod · 0.95
processAnsibleMethod · 0.95
processSystemdMethod · 0.95
processFileTransferMethod · 0.95
processKubeMethod · 0.95

Calls 4

runChangesConcurrentMethod · 0.95
WrapErrFunction · 0.92
getTreeFromHashFunction · 0.85
getFilteredChangeMapFunction · 0.85

Tested by

no test coverage detected