refactor: plain error assignment in eviction, storage and config (noinlineerr)
Hand-reviewed rather than mechanical, because two of these functions carried cleanup that depended on the shape being replaced. internal/imgcache/storage.go, writeIfAbsent: dropped the named result and the deferred temp-file cleanup that read it (nonamedreturns), in favour of an explicit os.Remove(tmpPath) on each failing path. The deferred form removed tmpPath whenever the function returned a non-nil error, which is reachable on exactly three paths once the temp file exists: Write, Close and Rename. Each of those now unlinks explicitly, in the same order relative to tmpFile.Close(). The paths that must NOT unlink are unchanged and still cannot: the content-already-present early return, a MkdirAll failure and a CreateTemp failure all happen before tmpPath exists, and the success path renames the temp file away. This is the same cleanup shape MetadataStorage.Store and VariantStorage.Store already use in this file. StoreHashed likewise loses its named results. internal/imgcache/eviction.go: converted 26 inline assignments. In evictSourceBlob the conversions reuse the function-scope err that the transaction already used; the rollback defer does not read it, and the ordering of the delete transaction, its commit, the sidecar deletes and the blob unlink is untouched. In the rows.Next() loops the scan error is declared inside the loop body and rows.Err() is checked after it, as before. internal/config: the remaining conversions are in straight-line code with no defer or named result. No behavior changes. make test (with -race, per script/test) is green, including TestEvictSourceBlobExcludesConcurrentStoreOfIdenticalContent, which exercises the commit-to-unlink window this cleanup protects.
This commit is contained in:
@@ -36,7 +36,9 @@ type FreeSpaceProbeFunc func(path string) (uint64, error)
|
||||
// the given path, as available to unprivileged processes.
|
||||
func defaultFreeSpaceProbe(path string) (uint64, error) {
|
||||
var stat syscall.Statfs_t
|
||||
if err := syscall.Statfs(path, &stat); err != nil {
|
||||
|
||||
err := syscall.Statfs(path, &stat)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -82,9 +84,10 @@ func (c *Config) resolveCacheMaxBytes(
|
||||
if !c.cacheMaxBytesExplicit {
|
||||
cacheDir := filepath.Join(c.StateDir, "cache")
|
||||
|
||||
if err := os.MkdirAll(cacheDir, cacheDirPerms); err != nil {
|
||||
err := os.MkdirAll(cacheDir, cacheDirPerms)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config key %q: cannot create cache directory %q: %w",
|
||||
"cache_max_bytes", cacheDir, err)
|
||||
keyCacheMaxBytes, cacheDir, err)
|
||||
}
|
||||
|
||||
limit, err := ComputeDefaultCacheMaxBytes(cacheDir, probe)
|
||||
|
||||
Reference in New Issue
Block a user