kittygfx: Ensure temporary files are named per spec

Temporary files used with Kitty graphics must have
"tty-graphics-protocol" somewhere in their full path.

https://sw.kovidgoyal.net/kitty/graphics-protocol/#the-transmission-medium
This commit is contained in:
David Leadbeater
2025-01-03 11:12:33 +11:00
parent 7e1b7bb8b3
commit c9dfcd2781
2 changed files with 5 additions and 0 deletions

View File

@ -382,6 +382,7 @@ fn encodeError(r: *Response, err: EncodeableError) void {
error.DecompressionFailed => r.message = "EINVAL: decompression failed", error.DecompressionFailed => r.message = "EINVAL: decompression failed",
error.FilePathTooLong => r.message = "EINVAL: file path too long", error.FilePathTooLong => r.message = "EINVAL: file path too long",
error.TemporaryFileNotInTempDir => r.message = "EINVAL: temporary file not in temp dir", error.TemporaryFileNotInTempDir => r.message = "EINVAL: temporary file not in temp dir",
error.TemporaryFileNotNamedCorrectly => r.message = "EINVAL: temporary file not named correctly",
error.UnsupportedFormat => r.message = "EINVAL: unsupported format", error.UnsupportedFormat => r.message = "EINVAL: unsupported format",
error.UnsupportedMedium => r.message = "EINVAL: unsupported medium", error.UnsupportedMedium => r.message = "EINVAL: unsupported medium",
error.UnsupportedDepth => r.message = "EINVAL: unsupported pixel depth", error.UnsupportedDepth => r.message = "EINVAL: unsupported pixel depth",

View File

@ -220,6 +220,9 @@ pub const LoadingImage = struct {
// Temporary file logic // Temporary file logic
if (medium == .temporary_file) { if (medium == .temporary_file) {
if (!isPathInTempDir(path)) return error.TemporaryFileNotInTempDir; if (!isPathInTempDir(path)) return error.TemporaryFileNotInTempDir;
if (std.mem.indexOf(u8, path, "tty-graphics-protocol") == null) {
return error.TemporaryFileNotNamedCorrectly;
}
} }
defer if (medium == .temporary_file) { defer if (medium == .temporary_file) {
posix.unlink(path) catch |err| { posix.unlink(path) catch |err| {
@ -469,6 +472,7 @@ pub const Image = struct {
DimensionsTooLarge, DimensionsTooLarge,
FilePathTooLong, FilePathTooLong,
TemporaryFileNotInTempDir, TemporaryFileNotInTempDir,
TemporaryFileNotNamedCorrectly,
UnsupportedFormat, UnsupportedFormat,
UnsupportedMedium, UnsupportedMedium,
UnsupportedDepth, UnsupportedDepth,