MCPcopy
hub / github.com/kptdev/kpt / sync

Method sync

internal/util/sync/sync.go:107–154  ·  view source on GitHub ↗
(dependency kptfile.Dependency)

Source from the content-addressed store, hash-verified

105}
106
107func (c Command) sync(dependency kptfile.Dependency) error {
108 path := filepath.Join(c.Dir, dependency.Name)
109 f, err := os.Stat(path)
110
111 // dep missing
112 if os.IsNotExist(err) {
113 if dependency.EnsureNotExists {
114 // dep already deleted -- no action required
115 return nil
116 }
117 // fetch the dep
118 return c.get(dependency)
119 }
120 if err != nil {
121 return errors.Wrap(err)
122 }
123
124 // verify the dep is well formed
125 if !f.IsDir() {
126 // place where dep should be fetched exists and is not a directory
127 return errors.Errorf("cannot sync to %q, non-directory file exists", path)
128 }
129 _, err = os.Stat(filepath.Join(path, kptfile.KptFileName))
130 if os.IsNotExist(err) {
131 // dep doesn't have a Kptfile -- something is wrong
132 return errors.Errorf("expected Kptfile under dependency %q", path)
133 }
134 if err != nil {
135 return errors.Wrap(err)
136 }
137
138 // delete the dep -- it exists
139 if dependency.EnsureNotExists {
140 return c.delete(dependency)
141 }
142
143 // read the Kptfile
144 b, err := ioutil.ReadFile(filepath.Join(path, kptfile.KptFileName))
145 if err != nil {
146 return errors.Wrap(err)
147 }
148 k := &kptfile.KptFile{}
149 if err = yaml.Unmarshal(b, k); err != nil {
150 return errors.Wrap(err)
151 }
152
153 return c.update(dependency, k)
154}
155
156// get fetches the dependency
157func (c Command) get(dependency kptfile.Dependency) error {

Callers 1

RunMethod · 0.95

Calls 3

getMethod · 0.95
deleteMethod · 0.95
updateMethod · 0.95

Tested by

no test coverage detected