feat(cli): add read-only tuning history
Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
8466f47ceb
commit
e2b87e0416
4 files changed
+393
-4
No files matched your search
@@ -23,7 +23,7 @@ func databasePath() string {
|
||||
return "/var/lib/zapret-autotune/autotune.db"
|
||||
}
|
||||
|
||||
func openStore(path string) (*sql.DB, error) {
|
||||
func storeURI(path string) (*url.URL, error) {
|
||||
// Configuration is a filesystem path, never a caller-supplied SQLite DSN.
|
||||
if path == "" || path == ":memory:" || strings.HasPrefix(path, ":memory:?") || strings.HasPrefix(strings.ToLower(path), "file:") {
|
||||
return nil, fmt.Errorf("database location must be a filesystem path, not a SQLite DSN")
|
||||
@@ -32,6 +32,41 @@ func openStore(path string) (*sql.DB, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Escape path characters so they cannot become URI options or fragments.
|
||||
return &url.URL{Scheme: "file", Path: filepath.ToSlash(path)}, nil
|
||||
}
|
||||
|
||||
// A nil database means the validated path does not exist. Never initialize it.
|
||||
func openHistoryStore(path string) (*sql.DB, error) {
|
||||
uri, err := storeURI(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := os.Stat(filepath.FromSlash(uri.Path)); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
uri.RawQuery = "mode=ro"
|
||||
db, err := sql.Open("sqlite", uri.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db.SetMaxOpenConns(1)
|
||||
if err := db.Ping(); err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func openStore(path string) (*sql.DB, error) {
|
||||
uri, err := storeURI(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
path = filepath.FromSlash(uri.Path)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -46,9 +81,7 @@ func openStore(path string) (*sql.DB, error) {
|
||||
if err := file.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Escape path characters so they cannot become URI options or fragments.
|
||||
dsn := (&url.URL{Scheme: "file", Path: filepath.ToSlash(path)}).String()
|
||||
db, err := sql.Open("sqlite", dsn)
|
||||
db, err := sql.Open("sqlite", uri.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user