Skip to content

Commit be31c28

Browse files
committed
fail if backend does not have a runfile
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 62a97c9 commit be31c28

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

core/gallery/backends.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func InstallBackend(ctx context.Context, systemState *system.SystemState, modelL
164164
return fmt.Errorf("failed copying: %w", err)
165165
}
166166
} else {
167-
uri := downloader.URI(config.URI)
167+
log.Debug().Str("uri", config.URI).Str("backendPath", backendPath).Msg("Downloading backend")
168168
if err := uri.DownloadFileWithContext(ctx, backendPath, "", 1, 1, downloadStatus); err != nil {
169169
success := false
170170
// Try to download from mirrors
@@ -177,16 +177,27 @@ func InstallBackend(ctx context.Context, systemState *system.SystemState, modelL
177177
}
178178
if err := downloader.URI(mirror).DownloadFileWithContext(ctx, backendPath, "", 1, 1, downloadStatus); err == nil {
179179
success = true
180+
log.Debug().Str("uri", config.URI).Str("backendPath", backendPath).Msg("Downloaded backend")
180181
break
181182
}
182183
}
183184

184185
if !success {
186+
log.Error().Str("uri", config.URI).Str("backendPath", backendPath).Err(err).Msg("Failed to download backend")
185187
return fmt.Errorf("failed to download backend %q: %v", config.URI, err)
186188
}
189+
} else {
190+
log.Debug().Str("uri", config.URI).Str("backendPath", backendPath).Msg("Downloaded backend")
187191
}
188192
}
189193

194+
// sanity check - check if runfile is present
195+
runFile := filepath.Join(backendPath, runFile)
196+
if _, err := os.Stat(runFile); os.IsNotExist(err) {
197+
log.Error().Str("runFile", runFile).Msg("Run file not found")
198+
return fmt.Errorf("not a valid backend: run file not found %q", runFile)
199+
}
200+
190201
// Create metadata for the backend
191202
metadata := &BackendMetadata{
192203
Name: name,

core/gallery/backends_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ var _ = Describe("Gallery Backends", func() {
563563
)
564564
Expect(err).NotTo(HaveOccurred())
565565
err = InstallBackend(context.TODO(), systemState, ml, &backend, nil)
566-
Expect(err).To(HaveOccurred()) // Will fail due to invalid URI, but path should be created
567566
Expect(newPath).To(BeADirectory())
567+
Expect(err).To(HaveOccurred()) // Will fail due to invalid URI, but path should be created
568568
})
569569

570570
It("should overwrite existing backend", func() {

pkg/downloader/uri.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func (uri URI) DownloadFileWithContext(ctx context.Context, filePath, sha string
323323
// Check if the file already exists
324324
_, err := os.Stat(filePath)
325325
if err == nil {
326+
log.Debug().Str("filePath", filePath).Msg("[downloader] File already exists")
326327
// File exists, check SHA
327328
if sha != "" {
328329
// Verify SHA

0 commit comments

Comments
 (0)