writeFileAtomic moves from memory.go to file.go with no change, because
the token file of the login uses it too, and a helper in the file of its
first user hides the dependency of the other. The test clock moves from
log_test.go to clock_test.go for the same reason: the memory, tree, and
replay tests use it only as a clock.
A search of every cross-file use finds no other helper with an unrelated
user. The other shared declarations are parts of the memory core or of
the model client that compose for one purpose.
Issue:
b14d537
--- /dev/null
+package main
+
+import "time"
+
+// testClock is a clock that tests set by hand.
+type testClock struct {
+ now time.Time
+}
+
+func newTestClock() *testClock {
+ return &testClock{
+ now: time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC),
+ }
+}
+
+func (c *testClock) Now() time.Time {
+ return c.now
+}
--- /dev/null
+package main
+
+import (
+ "errors"
+ "fmt"
+ "os"
+ "path/filepath"
+)
+
+// writeFileAtomic replaces the file at path with data through a temporary file
+// and a rename. A reader or a crash of the process sees the old file or the new
+// file, never a part of one.
+func writeFileAtomic(path string, data []byte) error {
+ file, err := os.CreateTemp(filepath.Dir(path), "."+filepath.Base(path)+".*")
+ if err != nil {
+ return fmt.Errorf("create temporary file: %w", err)
+ }
+
+ _, err = file.Write(data)
+ err = errors.Join(err, file.Close())
+ if err == nil {
+ err = os.Rename(file.Name(), path)
+ }
+
+ if err != nil {
+ return errors.Join(fmt.Errorf("replace file: %w", err), os.Remove(file.Name()))
+ }
+
+ return nil
+}
func truncateToOneAndAHalf(path string) error {
return os.Truncate(path, positionBytes+positionBytes/2)
}
-
-// testClock is a clock that tests set by hand.
-type testClock struct {
- now time.Time
-}
-
-func newTestClock() *testClock {
- return &testClock{
- now: time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC),
- }
-}
-
-func (c *testClock) Now() time.Time {
- return c.now
-}
return m.cview.Context(end)
}
-
-// writeFileAtomic replaces the file at path with data through a temporary file
-// and a rename. A reader or a crash of the process sees the old file or the new
-// file, never a part of one.
-func writeFileAtomic(path string, data []byte) error {
- file, err := os.CreateTemp(filepath.Dir(path), "."+filepath.Base(path)+".*")
- if err != nil {
- return fmt.Errorf("create temporary file: %w", err)
- }
-
- _, err = file.Write(data)
- err = errors.Join(err, file.Close())
- if err == nil {
- err = os.Rename(file.Name(), path)
- }
-
- if err != nil {
- return errors.Join(fmt.Errorf("replace file: %w", err), os.Remove(file.Name()))
- }
-
- return nil
-}