Files: a sweep of the edges

Found by walking every handler and the UI with odd inputs, then a battery of requests
against the live hub. Fixed:
- A save over the 8 MiB cap was cut short in place: the file was truncated, then the
  first 8 MiB written, and the caller told 204. Now the body is read whole first and a
  body over the cap is a 413 with the file untouched.
- A link to a file showed the link's own time; now the file's, so the row reads right
  and the preview key follows the file.
- Reading a link to nothing answered 200 with an empty body (the open failed after the
  headers in root mode); now a 404 that names the target.
- A play request with an unknown codec or size was answered by inspecting the file
  first, so an audio-only file said "no video stream" instead of what was wrong; the
  choice is checked before any work, and is a 400.
- A stream that ended in failure was handed back to the next identical request for ten
  minutes; a failed one is now dropped and a fresh one made.
- A player that left while its stream was still finding a first segment made the loop
  try the next recipe; it stops. A stream closed mid-start is not started again.
- Ending a root-mode ffmpeg could wait forever: the daemon cannot signal root's
  processes, so the wait is bounded and the helper's own grace does the rest.
- A page going away (a phone closing the tab) releases its stream by a beacon, rather
  than ten minutes later by the sweeper.
- The path box resolves like a shell — relative to the folder shown, . and .. applied,
  trailing slashes dropped — in the tab and in the Move picker, with a test. A typed path
  that is a file opens it; a remembered folder that is gone falls back to / once.
- A dropped folder arrived as a nameless empty file; it is refused with a word. The
  upload toast counts what was actually uploaded.
- The viewer names a device, pipe or socket, and a dangling link, instead of calling
  them binary files.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Mitchell-Johnson
2026-10-11 20:31:10 -07:00
co-authored by Claude Fable 5.1
parent d200e5dc2e
commit 1038c010fa
13 changed files with 210 additions and 26 deletions
+1 -1
View File
@@ -142,7 +142,7 @@ func entryOf(dir, name string, lst os.FileInfo) Entry {
} else if st.IsDir() {
e.Type = "dir" // keep dir semantics for navigation; Target says it's a link
} else {
e.Size = st.Size()
e.Size, e.Mtime = st.Size(), st.ModTime().UnixMilli() // the file's, not the link's
}
case lst.IsDir():
e.Type = "dir"
+27
View File
@@ -166,3 +166,30 @@ func TestMoveSameFilesystem(t *testing.T) {
t.Fatalf("onto an existing file: %v", err)
}
}
// A link to a file carries the file's size and time, so the row and the preview key follow
// the file; a link to a folder is a folder; a link to nothing says so.
func TestEntryOfLinks(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "f"), []byte("12345"), 0o644); err != nil {
t.Fatal(err)
}
old := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
_ = os.Chtimes(filepath.Join(dir, "f"), old, old)
_ = os.Mkdir(filepath.Join(dir, "d"), 0o755)
for _, l := range [][2]string{{"lf", "f"}, {"ld", "d"}, {"lx", "nowhere"}} {
if err := os.Symlink(l[1], filepath.Join(dir, l[0])); err != nil {
t.Fatal(err)
}
}
ent := func(n string) Entry { st, _ := os.Lstat(filepath.Join(dir, n)); return entryOf(dir, n, st) }
if e := ent("lf"); e.Type != "link" || e.Size != 5 || e.Mtime != old.UnixMilli() || e.Target != "f" || e.Broken {
t.Fatalf("link to file: %+v", e)
}
if e := ent("ld"); e.Type != "dir" || e.Target != "d" {
t.Fatalf("link to dir: %+v", e)
}
if e := ent("lx"); e.Type != "link" || !e.Broken || e.Preview != "" {
t.Fatalf("dangling: %+v", e)
}
}