Bundled KDE Connect: no copy left behind by a stop or a local read error

- A start turned off while copying removes the copy instead of starting an
  agent that would be killed before it could tidy up.
- A local read error while copying removes the partial copy too.
- The retry race test holds the new start until the retry has decided, so
  it fails every time without the fix (checked 3/3), not by luck.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
saphidandClaude Opus 5.5 committed 2026-09-28 21:44:02 +10:00
1 parent d5e8193ce5
commit efffd72c52
2 files changed
+73 -15

No files matched your search

+15 -5
View File
@@ -648,14 +648,19 @@ class InputAgent:
quoted = shlex.quote(name)
ssh(f"cd {folder} && cat > {quoted}.part && mv {quoted}.part {quoted}",
stdin=path.read_bytes(), text=False, timeout=600)
except Failure:
try:
ssh(f"rm -rf {folder}", timeout=20) # a partial copy is no use to anyone
except Failure:
pass # the agent tidies it later
except (Failure, OSError):
self.discard(folder) # a partial copy is no use to anyone
raise
return f"~/{folder}"
def discard(self, folder):
"""Remove a copy no agent will take over (best effort; agents tidy up old ones too)."""
if folder and not LOCAL:
try:
ssh(f"rm -rf {folder}", timeout=20)
except Failure:
pass
def start(self):
with self.lock:
if self.launching == self.generation or (self.proc and self.proc.poll() is None):
@@ -674,6 +679,11 @@ class InputAgent:
try:
ensure_master()
folder = self.deliver(report, force)
with self.lock:
stopped = self.generation != generation
if stopped: # turned off while copying: no agent will take the copy over
self.discard(folder.removeprefix("~/"))
raise Failure("stopped")
proc = subprocess.Popen([*SSH, FRAME, self.command(folder)], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=errors)
except (Failure, OSError) as e: