(ctx context.Context, path string)
| 360 | } |
| 361 | |
| 362 | func (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 | |
| 384 | func 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 |
no test coverage detected