mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
chore: Cleaned up some files.
This commit is contained in:
6
TODOS.md
6
TODOS.md
@@ -54,6 +54,8 @@
|
|||||||
|
|
||||||
27. "Encryption failed" in tests.
|
27. "Encryption failed" in tests.
|
||||||
|
|
||||||
|
28. Pass allocator to findr?
|
||||||
|
|
||||||
## Double-check AI output
|
## Double-check AI output
|
||||||
|
|
||||||
- [ ] cli.odin
|
- [ ] cli.odin
|
||||||
@@ -73,7 +75,7 @@
|
|||||||
- [x] cmd_scan.odin
|
- [x] cmd_scan.odin
|
||||||
- [x] cmd_sync.odin
|
- [x] cmd_sync.odin
|
||||||
- [x] cmd_version.odin
|
- [x] cmd_version.odin
|
||||||
- [ ] config.odin
|
- [x] config.odin
|
||||||
- [ ] config_test.odin
|
- [ ] config_test.odin
|
||||||
- [ ] crypto.odin
|
- [ ] crypto.odin
|
||||||
- [ ] crypto_test.odin
|
- [ ] crypto_test.odin
|
||||||
@@ -82,7 +84,7 @@
|
|||||||
- [ ] db_test.odin
|
- [ ] db_test.odin
|
||||||
- [x] main.odin
|
- [x] main.odin
|
||||||
- [x] prompt.odin
|
- [x] prompt.odin
|
||||||
- [ ] scan.odin
|
- [x] scan.odin
|
||||||
- [ ] scan_test.odin
|
- [ ] scan_test.odin
|
||||||
- [ ] sodium.odin
|
- [ ] sodium.odin
|
||||||
- [x] sqlite/sqlite.odin
|
- [x] sqlite/sqlite.odin
|
||||||
|
|||||||
15
config.odin
15
config.odin
@@ -1,5 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "base:runtime"
|
||||||
import "core:encoding/json"
|
import "core:encoding/json"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
@@ -126,6 +127,8 @@ new_config :: proc(
|
|||||||
append(&keys, SshKeyPair{private = priv_key, public = pub})
|
append(&keys, SshKeyPair{private = priv_key, public = pub})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we don't clone the strings, the cleanup semantics differ for Db created
|
||||||
|
// configs vs user created configs.
|
||||||
exclude := make([dynamic]string, 0, 4)
|
exclude := make([dynamic]string, 0, 4)
|
||||||
append(&exclude, strings.clone("*\\.envrc"))
|
append(&exclude, strings.clone("*\\.envrc"))
|
||||||
append(&exclude, strings.clone("\\.local/"))
|
append(&exclude, strings.clone("\\.local/"))
|
||||||
@@ -199,7 +202,6 @@ find_git_roots :: proc(
|
|||||||
) {
|
) {
|
||||||
paths := search_paths(cfg, allocator)
|
paths := search_paths(cfg, allocator)
|
||||||
// TODO: Pass allocator to findr
|
// TODO: Pass allocator to findr
|
||||||
// findr.find_repos(paths[:], &roots, os.get_processor_core_count(), allocator)
|
|
||||||
findr.find_repos(paths[:], &roots, os.get_processor_core_count())
|
findr.find_repos(paths[:], &roots, os.get_processor_core_count())
|
||||||
ok = true
|
ok = true
|
||||||
return
|
return
|
||||||
@@ -231,8 +233,13 @@ envr_dir :: proc(config_path: string) -> string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// User is responsible for freeing the path
|
// User is responsible for freeing the path
|
||||||
data_path :: proc(config_path: string, allocator := context.allocator) -> string {
|
data_path :: proc(
|
||||||
path, _ := filepath.join([]string{envr_dir(config_path), "data.envr"}, allocator)
|
config_path: string,
|
||||||
return path
|
allocator := context.allocator,
|
||||||
|
) -> (
|
||||||
|
string,
|
||||||
|
runtime.Allocator_Error,
|
||||||
|
) #optional_allocator_error {
|
||||||
|
return filepath.join([]string{envr_dir(config_path), "data.envr"}, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
40
db.odin
40
db.odin
@@ -81,14 +81,14 @@ db_init :: proc() -> (db: Db, ok: bool) {
|
|||||||
conn: sqlite.Db
|
conn: sqlite.Db
|
||||||
rc := sqlite.open(":memory:", &conn)
|
rc := sqlite.open(":memory:", &conn)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error opening in-memory database: %s\n", sqlite.db_errmsg(conn))
|
fmt.printf("Error opening in-memory database: %s\n", sqlite.errmsg(conn))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
create_sql: cstring = "CREATE TABLE IF NOT EXISTS envr_env_files (path TEXT PRIMARY KEY NOT NULL, remotes TEXT, sha256 TEXT NOT NULL, contents TEXT NOT NULL)"
|
create_sql: cstring = "CREATE TABLE IF NOT EXISTS envr_env_files (path TEXT PRIMARY KEY NOT NULL, remotes TEXT, sha256 TEXT NOT NULL, contents TEXT NOT NULL)"
|
||||||
rc = sqlite.db_exec(conn, create_sql, nil, nil, nil)
|
rc = sqlite.exec(conn, create_sql, nil, nil, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error creating table: %s\n", sqlite.db_errmsg(conn))
|
fmt.printf("Error creating table: %s\n", sqlite.errmsg(conn))
|
||||||
sqlite.close(conn)
|
sqlite.close(conn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ db_restore_from_encrypted :: proc(db: ^Db, data_path: string) -> bool {
|
|||||||
rc := sqlite.deserialize(db.conn, "main", buf, n, n, flags)
|
rc := sqlite.deserialize(db.conn, "main", buf, n, n, flags)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
sqlite.free(buf)
|
sqlite.free(buf)
|
||||||
fmt.printf("Error deserializing database: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error deserializing database: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,9 +150,9 @@ db_close :: proc(db: ^Db) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if db.changed {
|
if db.changed {
|
||||||
rc := sqlite.db_exec(db.conn, "VACUUM", nil, nil, nil)
|
rc := sqlite.exec(db.conn, "VACUUM", nil, nil, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error vacuuming database: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error vacuuming database: %s\n", sqlite.errmsg(db.conn))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ db_list :: proc(db: ^Db) -> ([]EnvFile, bool) {
|
|||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error preparing query: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error preparing query: %s\n", sqlite.errmsg(db.conn))
|
||||||
return []EnvFile{}, false
|
return []EnvFile{}, false
|
||||||
}
|
}
|
||||||
defer sqlite.finalize(stmt)
|
defer sqlite.finalize(stmt)
|
||||||
@@ -212,7 +212,7 @@ db_list :: proc(db: ^Db) -> ([]EnvFile, bool) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if rc != sqlite.ROW {
|
if rc != sqlite.ROW {
|
||||||
fmt.printf("Error stepping query: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error stepping query: %s\n", sqlite.errmsg(db.conn))
|
||||||
#no_bounds_check return results[:], false
|
#no_bounds_check return results[:], false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
|
|||||||
stmt: sqlite.Stmt
|
stmt: sqlite.Stmt
|
||||||
rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil)
|
rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error preparing insert: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error preparing insert: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer sqlite.finalize(stmt)
|
defer sqlite.finalize(stmt)
|
||||||
@@ -262,7 +262,7 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
|
|||||||
defer delete(cpath)
|
defer delete(cpath)
|
||||||
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
|
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error binding path: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error binding path: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
|
|||||||
defer delete(cremotes)
|
defer delete(cremotes)
|
||||||
rc = sqlite.bind_text(stmt, 2, cremotes, -1, nil)
|
rc = sqlite.bind_text(stmt, 2, cremotes, -1, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error binding remotes: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error binding remotes: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
|
|||||||
defer delete(csha)
|
defer delete(csha)
|
||||||
rc = sqlite.bind_text(stmt, 3, csha, -1, nil)
|
rc = sqlite.bind_text(stmt, 3, csha, -1, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error binding sha256: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error binding sha256: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,13 +286,13 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
|
|||||||
defer delete(ccontents)
|
defer delete(ccontents)
|
||||||
rc = sqlite.bind_text(stmt, 4, ccontents, -1, nil)
|
rc = sqlite.bind_text(stmt, 4, ccontents, -1, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error binding contents: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error binding contents: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite.step(stmt)
|
rc = sqlite.step(stmt)
|
||||||
if rc != sqlite.DONE {
|
if rc != sqlite.DONE {
|
||||||
fmt.printf("Error inserting: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error inserting: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +306,7 @@ db_fetch :: proc(db: ^Db, path: string) -> (EnvFile, bool) {
|
|||||||
stmt: sqlite.Stmt
|
stmt: sqlite.Stmt
|
||||||
rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil)
|
rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error preparing fetch: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error preparing fetch: %s\n", sqlite.errmsg(db.conn))
|
||||||
return EnvFile{}, false
|
return EnvFile{}, false
|
||||||
}
|
}
|
||||||
defer sqlite.finalize(stmt)
|
defer sqlite.finalize(stmt)
|
||||||
@@ -317,7 +317,7 @@ db_fetch :: proc(db: ^Db, path: string) -> (EnvFile, bool) {
|
|||||||
defer delete(cpath, allocator)
|
defer delete(cpath, allocator)
|
||||||
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
|
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error binding path: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error binding path: %s\n", sqlite.errmsg(db.conn))
|
||||||
return EnvFile{}, false
|
return EnvFile{}, false
|
||||||
}
|
}
|
||||||
rc = sqlite.step(stmt)
|
rc = sqlite.step(stmt)
|
||||||
@@ -326,7 +326,7 @@ db_fetch :: proc(db: ^Db, path: string) -> (EnvFile, bool) {
|
|||||||
return EnvFile{}, false
|
return EnvFile{}, false
|
||||||
}
|
}
|
||||||
if rc != sqlite.ROW {
|
if rc != sqlite.ROW {
|
||||||
fmt.printf("Error fetching: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error fetching: %s\n", sqlite.errmsg(db.conn))
|
||||||
return EnvFile{}, false
|
return EnvFile{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ db_delete :: proc(db: ^Db, path: string) -> bool {
|
|||||||
stmt: sqlite.Stmt
|
stmt: sqlite.Stmt
|
||||||
rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil)
|
rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error preparing delete: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error preparing delete: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer sqlite.finalize(stmt)
|
defer sqlite.finalize(stmt)
|
||||||
@@ -362,12 +362,12 @@ db_delete :: proc(db: ^Db, path: string) -> bool {
|
|||||||
defer delete(cpath)
|
defer delete(cpath)
|
||||||
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
|
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
|
||||||
if rc != sqlite.OK {
|
if rc != sqlite.OK {
|
||||||
fmt.printf("Error binding path: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error binding path: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
rc = sqlite.step(stmt)
|
rc = sqlite.step(stmt)
|
||||||
if rc != sqlite.DONE {
|
if rc != sqlite.DONE {
|
||||||
fmt.printf("Error deleting: %s\n", sqlite.db_errmsg(db.conn))
|
fmt.printf("Error deleting: %s\n", sqlite.errmsg(db.conn))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ scan_path :: proc(search_path: string, cfg: Config) -> (paths: [dynamic]string,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The returned values live on the temp_allocator
|
||||||
find_unbacked :: proc(local_files: []string, db_files: []EnvFile) -> []string {
|
find_unbacked :: proc(local_files: []string, db_files: []EnvFile) -> []string {
|
||||||
backed_set := make(map[string]bool, len(db_files), context.temp_allocator)
|
backed_set := make(map[string]bool, len(db_files), context.temp_allocator)
|
||||||
for file in db_files {
|
for file in db_files {
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ foreign lib {
|
|||||||
@(link_name = "sqlite3_close")
|
@(link_name = "sqlite3_close")
|
||||||
close :: proc(db: Db) -> c.int ---
|
close :: proc(db: Db) -> c.int ---
|
||||||
@(link_name = "sqlite3_errmsg")
|
@(link_name = "sqlite3_errmsg")
|
||||||
db_errmsg :: proc(db: Db) -> cstring ---
|
errmsg :: proc(db: Db) -> cstring ---
|
||||||
@(link_name = "sqlite3_exec")
|
@(link_name = "sqlite3_exec")
|
||||||
db_exec :: proc(db: Db, sql: cstring, callback: rawptr, callback_arg: rawptr, errmsg: ^cstring) -> c.int ---
|
exec :: proc(db: Db, sql: cstring, callback: rawptr, callback_arg: rawptr, errmsg: ^cstring) -> c.int ---
|
||||||
@(link_name = "sqlite3_prepare_v2")
|
@(link_name = "sqlite3_prepare_v2")
|
||||||
prepare_v2 :: proc(db: Db, sql: cstring, nByte: c.int, ppStmt: ^Stmt, pzTail: ^cstring) -> c.int ---
|
prepare_v2 :: proc(db: Db, sql: cstring, nByte: c.int, ppStmt: ^Stmt, pzTail: ^cstring) -> c.int ---
|
||||||
@(link_name = "sqlite3_step")
|
@(link_name = "sqlite3_step")
|
||||||
|
|||||||
Reference in New Issue
Block a user