From e0575975912e04c95413e81a89d3a9516a74fbb5 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 19 Jun 2026 11:26:42 +0200 Subject: [PATCH] util/managedfile: fix symlink creation for local case When a HTTPProvider driver is used a second time the link to the file already exists, so instead of just creating it we must replace it as done with the ln -f flag in the remote case. In the local case we currently get a FileExistsError when creating the link over an already existing one. Fix this by removing the old link before re-creating it. Fixes: 18646f74 ("util/managedfile: replace ssh usage for local case") Signed-off-by: Sascha Hauer --- labgrid/util/managedfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/labgrid/util/managedfile.py b/labgrid/util/managedfile.py index 79218a745..fe649bcfb 100644 --- a/labgrid/util/managedfile.py +++ b/labgrid/util/managedfile.py @@ -81,7 +81,9 @@ def sync_to_resource(self, symlink=None): # --symbolic --force --no-dereference conn.run_check(f"ln -sfn {self.rpath}{os.path.basename(self.local_path)} {symlink}") else: - if os.path.exists(symlink) and not os.path.islink(symlink): + if os.path.islink(symlink): + os.unlink(symlink) + elif os.path.exists(symlink): raise ManagedFileError(f"Path {symlink} exists but is not a symlink.") os.symlink(f"{self.rpath}{os.path.basename(self.local_path)}", symlink)