[NebulousLabs/Sia] Persist renter cache settings, and renter bandwidth limiter settings (#3052)

lukechampine commented on this pull request.

> +func (r *Renter) updatePersistVersionFrom040To133() error {
+ metadata := persist.Metadata{
+ Header: settingsMetadata.Header,
+ Version: persistVersion040,
+ }
+
+ err := persist.LoadJSON(metadata, &r.persist, filepath.Join(r.persistDir, PersistFilename))
+ if err != nil {
+ return err
+ }
+ metadata.Version = persistVersion133
+ r.persist.MaxDownloadSpeed = DefaultMaxDownloadSpeed
+ r.persist.MaxUploadSpeed = DefaultMaxUploadSpeed
+ r.persist.StreamCacheSize = DefaultStreamCacheSize
+ return persist.SaveJSON(metadata, r.persist, filepath.Join(r.persistDir, PersistFilename))
+}

this function has some side effects that aren’t obvious to the caller, like setting fields in `r.persist`. I suggest instead doing:
«`go
func updatePersistVersionFrom040To133(persistPath string) error {
var p persistence
LoadJSON(&p, persistPath)
p.MaxDownloadSpeed = DefaultMaxDownloadSpeed
// etc.
return SaveJSON(p, persistPath)
}
«`
then it’s a bit more clear that the old side effect is rewriting the file.

Добавить комментарий