Fix saveTofile; Add a global panic, Add a recoverer for everything functions

This commit is contained in:
Mukhtar Akere
2025-03-11 18:08:03 +01:00
parent 4f92b135d4
commit a30861984c
3 changed files with 43 additions and 25 deletions

View File

@@ -219,14 +219,14 @@ func (ts *TorrentStorage) DeleteMultiple(hashes []string) {
}
func (ts *TorrentStorage) Save() error {
ts.mu.RLock()
defer ts.mu.RUnlock()
return ts.saveToFile()
}
// saveToFile is a helper function to write the current state to the JSON file
func (ts *TorrentStorage) saveToFile() error {
ts.mu.RLock()
data, err := json.MarshalIndent(ts.torrents, "", " ")
ts.mu.RUnlock()
if err != nil {
return err
}