Skip to content

Commit 555cf7c

Browse files
committed
Force cache directory creation only if strictly needed
1 parent 8797c63 commit 555cf7c

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

internal/arduino/builder/core.go

+20-13
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
108108
return true
109109
}
110110

111-
// If there is an archived core in the current build cache, use it
112-
if _, err := buildcache.New(b.coreBuildCachePath).GetOrCreate(archivedCoreName); errors.Is(err, buildcache.CreateDirErr) {
113-
return nil, nil, errors.New(i18n.Tr("creating core cache folder: %s", err))
114-
}
115111
targetArchivedCore = b.coreBuildCachePath.Join(archivedCoreName, "core.a")
116112
if canUseArchivedCore(targetArchivedCore) {
113+
// Update timestamp of the cache folder to extend expire time
114+
if _, err := buildcache.New(b.coreBuildCachePath).GetOrCreate(archivedCoreName); errors.Is(err, buildcache.CreateDirErr) {
115+
return nil, nil, errors.New(i18n.Tr("creating core cache folder: %s", err))
116+
}
117+
117118
// use archived core
118119
if b.logger.Verbose() {
119120
b.logger.Info(i18n.Tr("Using precompiled core: %[1]s", targetArchivedCore))
@@ -151,17 +152,23 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
151152

152153
// archive core.a
153154
if targetArchivedCore != nil && !b.onlyUpdateCompilationDatabase {
154-
err := archiveFile.CopyTo(targetArchivedCore)
155-
if b.logger.Verbose() {
156-
if err == nil {
157-
b.logger.Info(i18n.Tr("Archiving built core (caching) in: %[1]s", targetArchivedCore))
158-
} else if os.IsNotExist(err) {
159-
b.logger.Info(i18n.Tr("Unable to cache built core, please tell %[1]s maintainers to follow %[2]s",
160-
b.actualPlatform,
161-
"https://arduino.github.io/arduino-cli/latest/platform-specification/#recipes-to-build-the-corea-archive-file"))
162-
} else {
155+
if err := targetArchivedCore.Parent().MkdirAll(); err != nil {
156+
if b.logger.Verbose() {
163157
b.logger.Info(i18n.Tr("Error archiving built core (caching) in %[1]s: %[2]s", targetArchivedCore, err))
164158
}
159+
} else {
160+
err := archiveFile.CopyTo(targetArchivedCore)
161+
if b.logger.Verbose() {
162+
if err == nil {
163+
b.logger.Info(i18n.Tr("Archiving built core (caching) in: %[1]s", targetArchivedCore))
164+
} else if os.IsNotExist(err) {
165+
b.logger.Info(i18n.Tr("Unable to cache built core, please tell %[1]s maintainers to follow %[2]s",
166+
b.actualPlatform,
167+
"https://arduino.github.io/arduino-cli/latest/platform-specification/#recipes-to-build-the-corea-archive-file"))
168+
} else {
169+
b.logger.Info(i18n.Tr("Error archiving built core (caching) in %[1]s: %[2]s", targetArchivedCore, err))
170+
}
171+
}
165172
}
166173
}
167174

0 commit comments

Comments
 (0)