Ensure tmpdir used for remote drag is deleted on kitty exit

This commit is contained in:
Kovid Goyal
2026-04-14 11:27:55 +05:30
parent bcae760ea7
commit e455b29a85
2 changed files with 20 additions and 5 deletions

View File

@@ -109,7 +109,7 @@ mktempdir_in_cache(const char *prefix, int *fd) {
if (module) {
RAII_PyObject(func, PyObject_GetAttrString(module, "mktempdir_in_cache"));
if (func) {
RAII_PyObject(ret, PyObject_CallFunction(func, "s", prefix));
RAII_PyObject(ret, PyObject_CallFunction(func, "sO", prefix, dnd_is_test_mode() ? Py_False : Py_True));
if (ret) {
if (PyArg_ParseTuple(ret, "si", &ans, fd)) {
if (*fd < 0) {

View File

@@ -33,7 +33,19 @@ from .constants import (
shell_path,
ssh_control_master_template,
)
from .fast_data_types import WINDOW_FULLSCREEN, WINDOW_HIDDEN, WINDOW_MAXIMIZED, WINDOW_MINIMIZED, WINDOW_NORMAL, Color, Shlex, get_options, monotonic, open_tty
from .fast_data_types import (
WINDOW_FULLSCREEN,
WINDOW_HIDDEN,
WINDOW_MAXIMIZED,
WINDOW_MINIMIZED,
WINDOW_NORMAL,
Color,
Shlex,
get_boss,
get_options,
monotonic,
open_tty,
)
from .fast_data_types import timed_debug_print as _timed_debug_print
from .types import run_once
from .typing_compat import AddressFamily, PopenType, StartupCtx
@@ -1158,16 +1170,19 @@ def rmtree_best_effort(relpath: str, dir_fd: int) -> None:
shutil.rmtree(relpath, ignore_errors=True, dir_fd=dir_fd)
def mktempdir_in_cache(prefix: str) -> tuple[str, int]:
def mktempdir_in_cache(prefix: str, delete_on_kitty_exit: bool) -> tuple[str, int]:
import tempfile
ans = tempfile.mkdtemp(prefix, dir=cache_dir())
ans = os.path.abspath(tempfile.mkdtemp(prefix, dir=cache_dir()))
try:
return os.path.abspath(ans), os.open(ans, os.O_DIRECTORY | os.O_RDONLY)
retval = ans, os.open(ans, os.O_DIRECTORY | os.O_RDONLY)
except OSError as e:
import errno
import shutil
shutil.rmtree(ans, ignore_errors=True)
return "", -e.errno if e.errno is not None else -errno.EIO
if delete_on_kitty_exit:
get_boss().atexit.rmtree(retval[0])
return retval
def sanitized_filename_from_url(url: str) -> str: