MCPcopy
hub / github.com/kopia/kopia / createDirectory

Method createDirectory

snapshot/restore/local_fs_output.go:362–382  ·  view source on GitHub ↗
(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

360}
361
362func (o *FilesystemOutput) createDirectory(ctx context.Context, path string) error {
363 switch st, err := os.Stat(path); {
364 case os.IsNotExist(err):
365 //nolint:wrapcheck
366 return os.MkdirAll(path, outputDirMode)
367 case err != nil:
368 return errors.Wrap(err, "failed to stat path "+path)
369 case st.Mode().IsDir():
370 if !o.OverwriteDirectories {
371 if empty, _ := isEmptyDirectory(path); !empty {
372 return errors.Errorf("non-empty directory already exists, not overwriting it: %q", path)
373 }
374 }
375
376 log(ctx).Debugf("Not creating already existing directory: %v", path)
377
378 return nil
379 default:
380 return errors.Errorf("unable to create directory, %q already exists and it is not a directory", path)
381 }
382}
383
384func write(targetPath string, r fs.Reader, size int64, flush bool, c streamCopier) (err error) {
385 f, err := os.OpenFile(targetPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600) //nolint:gosec,mnd

Callers 1

BeginDirectoryMethod · 0.95

Calls 7

isEmptyDirectoryFunction · 0.85
ErrorfMethod · 0.80
StatMethod · 0.65
IsNotExistMethod · 0.65
MkdirAllMethod · 0.65
IsDirMethod · 0.45
ModeMethod · 0.45

Tested by

no test coverage detected