Fixed segfault

All together now: thank you spytheman
main^2
Jef Roosens 2022-02-21 22:32:54 +01:00
parent e13252d368
commit 398758a727
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
3 changed files with 5 additions and 8 deletions

View File

@ -20,13 +20,14 @@ fn read_repos(path string) ?[]GitRepo {
f.close()
}
f.write_string('{}') ?
f.write_string('[]') ?
return []
}
content := os.read_file(path) ?
return json.decode([]GitRepo, content)
res := json.decode([]GitRepo, content) ?
return res
}
fn write_repos(path string, repos []GitRepo) ? {
@ -36,7 +37,6 @@ fn write_repos(path string, repos []GitRepo) ? {
f.close()
}
dump(repos)
value := json.encode(repos)
f.write_string(value) ?
}
@ -91,9 +91,7 @@ pub fn (mut app App) post_repo() web.Result {
repos << new_repo
lock app.git_mutex {
write_repos(app.conf.repos_file, repos) or {
return app.server_error(500)
}
write_repos(app.conf.repos_file, repos) or { return app.server_error(500) }
}
return app.ok('Repo added successfully.')

View File

@ -88,4 +88,3 @@ pub fn pretty_bytes(bytes int) string {
return '${n:.2}${util.prefixes[i]}'
}