Heavy security and file splitting
CI / Go Tests (push) Successful in 15s
CI / Build (push) Successful in 9s
Format / gofmt (push) Successful in 7s
Release Artifacts / Validate release tag (push) Successful in 2s
Release Artifacts / Build and release executables (push) Successful in 15s
Release Artifacts / Build and release Docker image (push) Successful in 28s
CI / Go Tests (push) Successful in 15s
CI / Build (push) Successful in 9s
Format / gofmt (push) Successful in 7s
Release Artifacts / Validate release tag (push) Successful in 2s
Release Artifacts / Build and release executables (push) Successful in 15s
Release Artifacts / Build and release Docker image (push) Successful in 28s
This commit is contained in:
@@ -2,7 +2,6 @@ package storage
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
@@ -107,11 +106,11 @@ func newFilesystemStore(dataDir string, defaultTTL time.Duration, encryptionKey
|
||||
return store, nil
|
||||
}
|
||||
|
||||
func (s *FilesystemStore) Create(ctx context.Context, body io.Reader, contentType string, ttl time.Duration) (Metadata, error) {
|
||||
return s.CreateWithOriginalName(ctx, body, contentType, "", ttl)
|
||||
func (s *FilesystemStore) Create(body io.Reader, contentType string, ttl time.Duration) (Metadata, error) {
|
||||
return s.CreateWithOriginalName(body, contentType, "", ttl)
|
||||
}
|
||||
|
||||
func (s *FilesystemStore) CreateWithOriginalName(ctx context.Context, body io.Reader, contentType string, originalName string, ttl time.Duration) (Metadata, error) {
|
||||
func (s *FilesystemStore) CreateWithOriginalName(body io.Reader, contentType string, originalName string, ttl time.Duration) (Metadata, error) {
|
||||
tempFile, err := os.CreateTemp(s.filesDir, "scratch.tmp-*")
|
||||
if err != nil {
|
||||
return Metadata{}, fmt.Errorf("create temp file: %w", err)
|
||||
@@ -264,9 +263,11 @@ func (s *FilesystemStore) Delete(id string) error {
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
if err := os.Remove(meta.FilePath); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return fmt.Errorf("remove scratch file: %w", err)
|
||||
}
|
||||
// Best-effort remove of the blob after metadata has been durably deleted from the index.
|
||||
// On error we tolerate an orphan on-disk blob (no meta entry points to it); reads already
|
||||
// fail cleanly with ErrNotFound. This prevents Delete from failing due to transient FS issues
|
||||
// on the blob and avoids meta inconsistency.
|
||||
_ = os.Remove(meta.FilePath)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -292,11 +293,20 @@ func (s *FilesystemStore) DeleteExpired(now time.Time) (int, error) {
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
// Attempt *all* removes (do not abort on first); return count of expired + first remove err if any.
|
||||
// Callers (cleanup worker) log errs; meta is already gone from index so orphans tolerated.
|
||||
var firstRemoveErr error
|
||||
for _, meta := range expired {
|
||||
if err := os.Remove(meta.FilePath); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return 0, fmt.Errorf("remove expired file %s: %w", meta.ID, err)
|
||||
if firstRemoveErr == nil {
|
||||
firstRemoveErr = fmt.Errorf("remove expired file %s: %w", meta.ID, err)
|
||||
}
|
||||
// continue to clean other entries
|
||||
}
|
||||
}
|
||||
if firstRemoveErr != nil {
|
||||
return len(expired), firstRemoveErr
|
||||
}
|
||||
return len(expired), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user