File names, archive member names, symlink targets, error messages and
ebook metadata were written to the terminal unsanitized, allowing
crafted names to inject escape codes (e.g. OSC 52 to overwrite the
clipboard) merely by highlighting the entry.
Create the temporary directory used for staging drops lazily, on the first
drop, instead of at startup, so the kitten works in directories that are not
writable when nothing is dropped into them.
Fixes#10855
Let preview renderers supply extra cache key data instead of checking for
the cmd_renderer type. Include the command line in the key for custom
previews and the video_preview settings in the key for video thumbnails,
so that changing them no longer shows stale previews. GetPath and AddPath
now take this extra key data, replacing GetPathWithAlias.
Track the entry each path uses per extra key, so that previews of one file
with different settings do not evict each other. Do not remove an entry
while another path, such as another symlink to the same file, still uses
it. Cache hits are now recorded so that such shared entries are known.
Failing to remove an orphaned entry on a cache hit no longer turns the hit
into an error.
Fix ensure_entries() discarding unwritten changes when the entries file
does not exist yet, which lost the first path recorded in a new cache.
Also reset the path map when clearing the cache.
Custom preview commands receive the selected path. Include that path
in their cache key so that symlinks to the same file can have different
previews. Keep the resolved target in the key so retargeting a link
still invalidates its entry.
Always reply from the calibre worker, even when reading metadata raises or
calibre emits stray output, so that the request does not block until it
times out.
Accept cached calibre metadata generated for a different path to the same
file, as the disk cache key resolves symlinks. Otherwise a symlink and its
target keep invalidating each other's cache entry.
Dispatch replies by request ID from a single reader so concurrent previews receive their own metadata and late replies cannot interfere with subsequent requests.
Follow up to the previous commit fixing hangs when previewing named pipes:
- Skip previewing anything that is not a regular file (or a symlink to
one) in preview_for, before any previewer opens it. This avoids
unblocking and then breaking writers waiting on a FIFO and covers the
non-text previewers (images, video, archives, calibre, commands) too.
- Apply the text preview size limit to the symlink target instead of the
symlink itself, and enforce it while reading so that files growing
after stat() are also handled.
- Pre-allocate the read buffer based on the file size, as os.ReadFile does.
- Read ignore files during scanning with the same non-blocking reader, so
a FIFO named .ignore or .gitignore cannot stall the scan.
- Unblock goroutines stuck on FIFOs when tests time out.
Open text preview files in nonblocking mode and check the type on
the opened descriptor before reading. Reuse the same read for syntax
highlighting because it can reopen a path after the file changes.
Use Capture.ByteRange() from v2 instead of a hand-rolled rune to byte
offset mapping. The old mapping required capture offsets to be monotonic
across matches, so a capture inside a lookaround overlapping a later match
in non-ASCII text caused all matches to be silently dropped.
Also propagate match errors instead of discarding them. Drops the v1
dependency, v2 was already pulled in by chroma.
Keep edit_loop free of side effects: it now reports whether the editor
was started and edit_and_upload decides whether to keep the local copy.
Print the recovery path verbatim instead of Go-quoted.
Strip the optional leading = from values attached to short options, matching
rg semantics (-e=foo means the pattern foo). Replace the rg execution based
test with unit tests of the argument rewriting.
Move the D-Bus service Exec line generation into a helper with a fast unit
test instead of copying the test binary and re-executing it. Refuse paths
containing a carriage return, since D-Bus decodes \r as a newline and
rejects .service files containing a raw carriage return.
enable_portal checked eerr instead of err after filepath.Abs, so a failing
os.Executable always aborted with a nil error and the Which fallback was
never used, while an Abs error was ignored. Check err, and report the
os.Executable error if kitten is not in PATH either.
Track move source identities in drop_status rather than parsed_uri, and
also compare birth times where available, so that a replacement reusing
the inode number of a deleted source is not removed. Clarify the
changelog entry.
is_case_sensitive_filesystem lost its true default when it moved into
the dnd struct, so remote drops always treated names differing only in
case as conflicting. Detect it properly and also probe for Unicode
normalization aliasing, since a case sensitive filesystem can still
treat differently normalized names as the same.
- List the existing files that will be overwritten under the names they
are stored as in the destination, not the dropped names
- Treat symlinks to directories in the destination as directories in
find_overwrites, matching rename_contents, so the files that will be
overwritten inside the symlink target are listed
- Replace an existing file or dangling symlink with a dropped directory
instead of failing the drop after the user confirmed the overwrite
- Fail up front when a dropped file would replace an existing directory
- Also fold Unicode normalization when uniqifying remote drop names
- Probe for filesystem aliasing once before running the alias test
Walk up from the drop destination using .. relative to its file
descriptor instead of its path, so the check is not fooled if the
destination is moved or replaced while the kitten is running. Also skip
the staging directory when copying, which guards against routes to it
the up-front check cannot see, such as bind mounts. Use readable
subtest names, check the chmod error in test cleanup and link the PR in
the changelog.
Staging two entries with the same basename could fall back from a hard link to a truncating copy and overwrite the first source. Give each local source an unused staging name and use exclusive file and directory creation. Add regressions for files, directories, repeated paths, case conflicts, existing staging entries and symbolic links.
Identify the colliding output by comparing the probe files, matching the
message used for exact duplicates. Skip creating probe files when fewer
than two file outputs are given, so that a single output does not touch
the destination directory. Check both directories for leftover probes in
the test.
Rather than every output sharing a remote MIME type writing its own
temporary copy of the data and decoding images separately, store the
data in a single temporary file per MIME type, decode images once and
save all outputs for that MIME type sequentially from it. The temporary
file is created in the directory of the first output where that is
possible, so a missing directory for one output does not affect others.
Also reject output files that resolve to the same path, following
symlinks as the atomic file update does, since saving to them would race
with the last write winning.
Stream outputs write data as it arrives, so with fan-out to all outputs
sharing a remote MIME type, two outputs to the same stream would
interleave their data chunk by chunk, or encode two images into the
stream concurrently. Reject such duplicates with an error instead.
Also add a changelog entry for saving all outputs sharing a MIME type.