On Wed, Aug 05, 2020 at 09:57:17AM +0100, Daniel P. Berrangé wrote: > On Tue, Aug 04, 2020 at 06:27:08PM +0200, Erik Skultety wrote: > > By default, symlink re-creation fails if the link already exists, more > > specifically in case of meson-install-symlink.py: > > > > Traceback (most recent call last): > > File "/<path_to_libvirt_repo>/scripts/meson-install-symlink.py", > > line 15, in <module> > > os.symlink(target, link) > > FileExistsError: File exists: '../default.xml' -> 'default.xml' > > > > Unfortunately, Python can't mimic "ln -sf", so we have to fix this > > differently - create a temporary name which is then going to be used > > for the temporary link followed by a rename with the original link's > > name. > > Note that this solution is racy as mktemp() doesn't guarantee > > atomicity in link creation, so theoretically another process could come > > and create a file with the same name as the temporary link name, but > > a proper solution would be longer and not as elegant. > > You've just described exactly what python does for "ln -sf foo bar". > try stracing it and you'll see it do: > > symlinkat("foo", AT_FDCWD, "CubmxbFT") = 0 > renameat(AT_FDCWD, "CubmxbFT", AT_FDCWD, "bar") = 0 Oh, I didn't know that, in which case v1 is actually the correct fix here. I sent v2 in the meantime where I remove the pre-existing link which is even more compact, so I don't care which one we go for. Erik