mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
fix: Fixed some leaks in backup and scan.
This commit is contained in:
@@ -15,7 +15,10 @@ cmd_backup :: proc(cmd: ^Command) {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: allow new_env_file to accept allocator?
|
||||
// TODO: Write a test that covers this leak
|
||||
file, ok := new_env_file(path)
|
||||
defer delete_envfile(&file)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -72,7 +72,11 @@ cmd_scan :: proc(cmd: ^Command) {
|
||||
selected, result := multi_select("Select .env files to backup:", files[:])
|
||||
defer delete(selected)
|
||||
if result == .Cancel {
|
||||
fmt.wprintln(cmd.out, ansi.CSI + ansi.FAINT + ansi.SGR + "Cancelled." + ANSI_RESET, flush = false)
|
||||
fmt.wprintln(
|
||||
cmd.out,
|
||||
ansi.CSI + ansi.FAINT + ansi.SGR + "Cancelled." + ANSI_RESET,
|
||||
flush = false,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -81,7 +85,9 @@ cmd_scan :: proc(cmd: ^Command) {
|
||||
if !selected[i] {
|
||||
continue
|
||||
}
|
||||
// TODO: Test cover this leak
|
||||
env_file, ok := new_env_file(files[i])
|
||||
defer delete_envfile(&env_file)
|
||||
if !ok {
|
||||
fmt.wprintf(cmd.err, "Error reading %s\n", files[i], flush = false)
|
||||
continue
|
||||
@@ -96,12 +102,23 @@ cmd_scan :: proc(cmd: ^Command) {
|
||||
if added_count > 0 {
|
||||
fmt.wprintf(
|
||||
cmd.out,
|
||||
ansi.CSI + ansi.BOLD + ";" + ansi.FG_GREEN + ansi.SGR + "Successfully added %d file(s) to backup." + ANSI_RESET + "\n",
|
||||
ansi.CSI +
|
||||
ansi.BOLD +
|
||||
";" +
|
||||
ansi.FG_GREEN +
|
||||
ansi.SGR +
|
||||
"Successfully added %d file(s) to backup." +
|
||||
ANSI_RESET +
|
||||
"\n",
|
||||
added_count,
|
||||
flush = false,
|
||||
)
|
||||
} else {
|
||||
fmt.wprintln(cmd.out, ansi.CSI + ansi.FAINT + ansi.SGR + "No files were added." + ANSI_RESET, flush = false)
|
||||
fmt.wprintln(
|
||||
cmd.out,
|
||||
ansi.CSI + ansi.FAINT + ansi.SGR + "No files were added." + ANSI_RESET,
|
||||
flush = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
db.odin
2
db.odin
@@ -387,6 +387,7 @@ db_delete :: proc(db: ^Db, path: string) -> bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Caller is responsible for the returned memory
|
||||
new_env_file :: proc(path: string) -> (EnvFile, bool) {
|
||||
abs_path, abs_err := filepath.abs(path)
|
||||
if abs_err != nil {
|
||||
@@ -400,7 +401,6 @@ new_env_file :: proc(path: string) -> (EnvFile, bool) {
|
||||
remotes := get_git_remotes(dir, context.allocator)
|
||||
|
||||
data, read_err := os.read_entire_file_from_path(abs_path, context.allocator)
|
||||
defer delete(data)
|
||||
if read_err != nil {
|
||||
fmt.printf("Error reading file %s: %v\n", abs_path, read_err)
|
||||
return EnvFile{}, false
|
||||
|
||||
@@ -348,6 +348,7 @@ test_new_env_file :: proc(t: ^testing.T) {
|
||||
file, ok := new_env_file(env_path)
|
||||
testing.expect(t, ok, "new_env_file should succeed")
|
||||
if !ok do return
|
||||
defer delete(file.contents)
|
||||
defer delete(file.Remotes)
|
||||
defer delete(file.Sha256)
|
||||
defer delete(file.Path)
|
||||
|
||||
Reference in New Issue
Block a user