Skip to content

Commit bf58720

Browse files
author
Luca Bianconi
committed
refactor: cleaner flow
1 parent 6ac7fce commit bf58720

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Diff for: buildcache/build_cache.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ import (
2323
"github.com/sirupsen/logrus"
2424
)
2525

26+
type wrapError struct {
27+
wrapped error
28+
}
29+
30+
func (e wrapError) Error() string {
31+
return e.wrapped.Error()
32+
}
33+
34+
func (e wrapError) Unwrap() error {
35+
return e.wrapped
36+
}
37+
38+
type ErrCreateBaseDir struct {
39+
wrapError
40+
}
41+
type ErrWriteLastUsedFile struct {
42+
wrapError
43+
}
44+
2645
const lastUsedFileName = ".last-used"
2746

2847
// BuildCache represents a cache of built files (sketches and cores), it's designed
@@ -37,11 +56,11 @@ type BuildCache struct {
3756
func (bc *BuildCache) GetOrCreate(key string) (*paths.Path, error) {
3857
keyDir := bc.baseDir.Join(key)
3958
if err := keyDir.MkdirAll(); err != nil {
40-
return nil, err
59+
return nil, &ErrCreateBaseDir{wrapError{err}}
4160
}
4261

4362
if err := keyDir.Join(lastUsedFileName).WriteFile([]byte{}); err != nil {
44-
return nil, err
63+
return nil, &ErrWriteLastUsedFile{wrapError{err}}
4564
}
4665
return keyDir, nil
4766
}

Diff for: legacy/builder/phases/core_builder.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
100100
targetArchivedCore = buildCachePath.Join(archivedCoreName, "core.a")
101101
_, buildCacheErr = buildcache.New(buildCachePath).GetOrCreate(archivedCoreName)
102102

103+
if errors.As(buildCacheErr, &buildcache.ErrCreateBaseDir{}) {
104+
return nil, nil, fmt.Errorf(tr("creating core cache folder: %s", err))
105+
}
106+
103107
canUseArchivedCore := !ctx.OnlyUpdateCompilationDatabase &&
104108
!ctx.Clean &&
105109
!builder_utils.CoreOrReferencedCoreHasChanged(realCoreFolder, targetCoreFolder, targetArchivedCore)
@@ -125,11 +129,6 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
125129

126130
// archive core.a
127131
if targetArchivedCore != nil && !ctx.OnlyUpdateCompilationDatabase {
128-
if buildCacheErr != nil {
129-
if err := targetArchivedCore.Parent().Mkdir(); err != nil {
130-
return nil, nil, fmt.Errorf(tr("creating core cache folder: %s", err))
131-
}
132-
}
133132
err := archiveFile.CopyTo(targetArchivedCore)
134133
if ctx.Verbose {
135134
if err == nil {

0 commit comments

Comments
 (0)