|
|
|
|
@@ -94,23 +94,22 @@ func (s *ContentStorage) Store(r io.Reader) (ContentHash, int64, error) {
|
|
|
|
|
_, err = tmpFile.Write(data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = tmpFile.Close()
|
|
|
|
|
_ = os.Remove(tmpPath) //nolint:gosec // G703: our own temp file, not user input
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
|
|
|
|
|
return "", 0, fmt.Errorf("failed to write content: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = tmpFile.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = os.Remove(tmpPath) //nolint:gosec // G703: our own temp file, not user input
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
|
|
|
|
|
return "", 0, fmt.Errorf("failed to close temp file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Atomic rename
|
|
|
|
|
//nolint:gosec // G703: tmp file is ours, path is derived from content hash
|
|
|
|
|
err = os.Rename(filepath.Clean(tmpPath), filepath.Clean(path))
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = os.Remove(tmpPath) //nolint:gosec // G703: our own temp file, not user input
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
|
|
|
|
|
return "", 0, fmt.Errorf("failed to rename temp file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
@@ -254,23 +253,22 @@ func (s *MetadataStorage) Store(
|
|
|
|
|
_, err = tmpFile.Write(data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = tmpFile.Close()
|
|
|
|
|
_ = os.Remove(tmpPath) //nolint:gosec // G703: our own temp file, not user input
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
|
|
|
|
|
return fmt.Errorf("failed to write metadata: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = tmpFile.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = os.Remove(tmpPath) //nolint:gosec // G703: our own temp file, not user input
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
|
|
|
|
|
return fmt.Errorf("failed to close temp file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Atomic rename
|
|
|
|
|
//nolint:gosec // G703: tmp file is ours, path is derived from cache key
|
|
|
|
|
err = os.Rename(filepath.Clean(tmpPath), filepath.Clean(path))
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = os.Remove(tmpPath) //nolint:gosec // G703: our own temp file, not user input
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
|
|
|
|
|
return fmt.Errorf("failed to rename temp file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
@@ -412,23 +410,22 @@ func (s *VariantStorage) Store(
|
|
|
|
|
_, err = tmpFile.Write(data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = tmpFile.Close()
|
|
|
|
|
_ = os.Remove(tmpPath) //nolint:gosec // G703: our own temp file, not user input
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
|
|
|
|
|
return 0, fmt.Errorf("failed to write content: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = tmpFile.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = os.Remove(tmpPath) //nolint:gosec // G703: our own temp file, not user input
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
|
|
|
|
|
return 0, fmt.Errorf("failed to close temp file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Atomic rename content
|
|
|
|
|
//nolint:gosec // G703: tmp file is ours, path is derived from cache key
|
|
|
|
|
err = os.Rename(filepath.Clean(tmpPath), filepath.Clean(path))
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = os.Remove(tmpPath) //nolint:gosec // G703: our own temp file, not user input
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
|
|
|
|
|
return 0, fmt.Errorf("failed to rename temp file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|