Skip to content

Commit 00c5539

Browse files
committed
fix: Fixed some issues
1 parent 6c0691d commit 00c5539

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

internal/tools/search_file_content_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ line 5
4949
"## Content Search Results",
5050
"### `main.go`",
5151
"*1 match(es)*",
52-
" 7: \tfmt.Println(\"World\") // match me",
52+
" 7: \tfmt.Println(\"World\") // match me",
5353
},
5454
},
5555
{

internal/tools/tinygo_manager.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (m *TinyGoManager) SetStatusCallback(callback func(string)) {
5454
}
5555

5656
// updateStatus sends a status update if callback is set
57+
// This acquires the lock internally, so it should NOT be called while holding the lock
5758
func (m *TinyGoManager) updateStatus(status string) {
5859
m.mu.Lock()
5960
callback := m.statusCallback
@@ -64,6 +65,14 @@ func (m *TinyGoManager) updateStatus(status string) {
6465
}
6566
}
6667

68+
// updateStatusLocked sends a status update if callback is set
69+
// This should be called while already holding the lock (e.g., from within GetTinyGoBinary)
70+
func (m *TinyGoManager) updateStatusLocked(status string) {
71+
if m.statusCallback != nil {
72+
m.statusCallback(status)
73+
}
74+
}
75+
6776
// getTinyGoCacheDir returns the platform-specific cache directory for TinyGo
6877
func getTinyGoCacheDir() (string, error) {
6978
var baseDir string
@@ -189,15 +198,15 @@ func (m *TinyGoManager) GetTinyGoBinary(ctx context.Context) (string, error) {
189198

190199
// Download and extract TinyGo
191200
m.logger.Info("TinyGo not found in cache, downloading version %s...", tinyGoVersion)
192-
m.updateStatus(fmt.Sprintf("Downloading TinyGo %s (first use only, ~50MB)...", tinyGoVersion))
201+
m.updateStatusLocked(fmt.Sprintf("Downloading TinyGo %s (first use only, ~50MB)...", tinyGoVersion))
193202

194203
if err := m.downloadTinyGo(ctx); err != nil {
195-
m.updateStatus("")
204+
m.updateStatusLocked("")
196205
return "", fmt.Errorf("failed to download TinyGo: %w", err)
197206
}
198207

199208
m.logger.Info("TinyGo downloaded and cached successfully")
200-
m.updateStatus("TinyGo download complete")
209+
m.updateStatusLocked("TinyGo download complete")
201210

202211
// Clear status after a brief moment
203212
go func() {
@@ -261,10 +270,10 @@ func (m *TinyGoManager) downloadTinyGo(ctx context.Context) error {
261270
lastUpdate = time.Now()
262271
if totalBytes > 0 {
263272
percent := float64(downloaded) / float64(totalBytes) * 100
264-
m.updateStatus(fmt.Sprintf("Downloading TinyGo %s... %.0f%%", tinyGoVersion, percent))
273+
m.updateStatusLocked(fmt.Sprintf("Downloading TinyGo %s... %.0f%%", tinyGoVersion, percent))
265274
} else {
266275
mb := float64(downloaded) / (1024 * 1024)
267-
m.updateStatus(fmt.Sprintf("Downloading TinyGo %s... %.1f MB", tinyGoVersion, mb))
276+
m.updateStatusLocked(fmt.Sprintf("Downloading TinyGo %s... %.1f MB", tinyGoVersion, mb))
268277
}
269278
}
270279
},
@@ -277,7 +286,7 @@ func (m *TinyGoManager) downloadTinyGo(ctx context.Context) error {
277286

278287
// Extract to cache directory
279288
m.logger.Info("Extracting TinyGo...")
280-
m.updateStatus(fmt.Sprintf("Extracting TinyGo %s...", tinyGoVersion))
289+
m.updateStatusLocked(fmt.Sprintf("Extracting TinyGo %s...", tinyGoVersion))
281290
extractDir := filepath.Join(m.cacheDir, tinyGoVersion)
282291
if err := os.MkdirAll(extractDir, 0755); err != nil {
283292
return fmt.Errorf("failed to create cache directory: %w", err)

0 commit comments

Comments
 (0)