p2.1: honcho-embed, wayback http/204, memento, keys owner
Embed requests send dixie.embed_model (default honcho-embed). Wayback accepts http://web.archive.org, rewrites to https, skips non-200 closest.status. Memento-Datetime is parsed as an HTTP date and future/garbage values become empty snapshot_at. keys add writes via temp+fchown/chmod/rename so root does not clobber keys.toml. Digest fallback is capped at the 6k-token budget.
This commit is contained in:
+48
-6
@@ -8,8 +8,10 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
@@ -112,11 +114,7 @@ func Add(path, name, workspace, keyOut string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmp := path + ".tmp"
|
||||
if err := os.WriteFile(tmp, out, 0o640); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(tmp, path)
|
||||
return writePreserving(path, out)
|
||||
}
|
||||
|
||||
func List(path string) ([]Caller, error) {
|
||||
@@ -151,5 +149,49 @@ func Revoke(path, name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, raw, 0o640)
|
||||
return writePreserving(path, raw)
|
||||
}
|
||||
|
||||
func writePreserving(path string, data []byte) error {
|
||||
mode := os.FileMode(0o640)
|
||||
uid, gid := -1, -1
|
||||
if st, err := os.Stat(path); err == nil {
|
||||
mode = st.Mode()
|
||||
if sys, ok := st.Sys().(*syscall.Stat_t); ok {
|
||||
uid, gid = int(sys.Uid), int(sys.Gid)
|
||||
}
|
||||
}
|
||||
f, err := os.CreateTemp(filepath.Dir(path), ".sift-keys-*.tmp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmp := f.Name()
|
||||
ok := false
|
||||
defer func() {
|
||||
if !ok {
|
||||
_ = os.Remove(tmp)
|
||||
}
|
||||
}()
|
||||
if _, err := f.Write(data); err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
if err := f.Chmod(mode.Perm()); err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
if uid >= 0 {
|
||||
if err := f.Chown(uid, gid); err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Rename(tmp, path); err != nil {
|
||||
return err
|
||||
}
|
||||
ok = true
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user