MCPcopy Create free account
hub / github.com/containerd/nerdctl / Set

Method Set

pkg/store/filestore.go:168–201  ·  view source on GitHub ↗
(data []byte, key ...string)

Source from the content-addressed store, hash-verified

166}
167
168func (vs *fileStore) Set(data []byte, key ...string) error {
169 if vs.locked == nil {
170 return errors.Join(ErrFaultyImplementation, fmt.Errorf("operations on the store must use locking"))
171 }
172
173 if err := validateAllPathComponents(key...); err != nil {
174 return err
175 }
176
177 fileName := key[len(key)-1]
178 parent := vs.dir
179
180 if len(key) > 1 {
181 parent = filepath.Join(append([]string{parent}, key[0:len(key)-1]...)...)
182 err := os.MkdirAll(parent, vs.dirPerm)
183 if err != nil {
184 return errors.Join(ErrSystemFailure, err)
185 }
186 }
187
188 dest := filepath.Join(parent, fileName)
189 st, err := os.Stat(dest)
190 if err == nil {
191 if st.IsDir() {
192 return errors.Join(ErrFaultyImplementation, fmt.Errorf("%q is a directory and cannot be written to", dest))
193 }
194 }
195
196 if err := filesystem.WriteFileWithRename(filepath.Join(parent, fileName), data, vs.filePerm); err != nil {
197 return errors.Join(ErrSystemFailure, err)
198 }
199
200 return nil
201}
202
203func (vs *fileStore) List(key ...string) ([]string, error) {
204 if vs.locked == nil {

Callers

nothing calls this directly

Calls 3

WriteFileWithRenameFunction · 0.92
StatMethod · 0.80

Tested by

no test coverage detected