Open julienlavergne opened 2 years ago
Hi @julienlavergne on what kind of target machine are you seeing this? I cannot replicate on MacOS local nor in an Ubuntu 20 container:
$ pyinfra @docker/ubuntu:20.04 test.py
...
--> Proposed changes:
Groups: @docker
[@docker/ubuntu:20.04] Operations: 2 Commands: 3
--> Beginning operation run...
--> Starting operation: Link with separator
[@docker/ubuntu:20.04] Success
--> Starting operation: Link without separator
[@docker/ubuntu:20.04] Success
...
[@docker/ubuntu:20.04] docker build complete, image ID: 0430ecd73769
$ docker run 0430ecd73769 ls -lh
total 48K
...
lrwxrwxrwx 1 root root 6 Apr 16 09:37 testo-link -> target
I provided python uname output in the description. This is Red Hat 7. I have same result on CentOS 7, CentOS 6 and Red Hat 6.
I might be missing the true nature of the bug, but to me, this does not feel like a bug.
This behavior is the same for ln -s
.
In this example, I'm demonstrating how creating a symlink using a slash at the end of the target behaves.
[kris@NX-01 link-test]$ pwd
/tmp/link-test
[kris@NX-01 link-test]$ ll
total 0
[kris@NX-01 link-test]$ mkdir target
[kris@NX-01 link-test]$ ll
total 0
drwxrwxr-x 2 kris kris 40 Apr 23 10:49 target
[kris@NX-01 link-test]$ ln -s target/ link
[kris@NX-01 link-test]$ ll
total 0
lrwxrwxrwx 1 kris kris 7 Apr 23 10:49 link -> target/
drwxrwxr-x 2 kris kris 40 Apr 23 10:49 target
[kris@NX-01 link-test]$ ln -sf target link
[kris@NX-01 link-test]$ ll
total 0
lrwxrwxrwx 1 kris kris 7 Apr 23 10:49 link -> target/
drwxrwxr-x 2 kris kris 60 Apr 23 10:49 target
In this example, I'm demonstrating the same as above, but I'm not using a slash in the target. This shows that the order of operations matters.
[kris@NX-01 link-test]$ ll
total 0
drwxrwxr-x 2 kris kris 60 Apr 23 10:54 target
[kris@NX-01 link-test]$
[kris@NX-01 link-test]$ ln -s target link
[kris@NX-01 link-test]$ ll
total 0
lrwxrwxrwx 1 kris kris 6 Apr 23 10:55 link -> target
drwxrwxr-x 2 kris kris 60 Apr 23 10:54 target
[kris@NX-01 link-test]$ ln -sf target/ link
[kris@NX-01 link-test]$ ll
total 0
lrwxrwxrwx 1 kris kris 6 Apr 23 10:55 link -> target
drwxrwxr-x 2 kris kris 60 Apr 23 10:55 target
I might be missing the true nature of the bug, but to me, this does not feel like a bug. This behavior is the same for
ln -s
.In this example, I'm demonstrating how creating a symlink using a slash at the end of the target behaves.
[kris@NX-01 link-test]$ pwd /tmp/link-test [kris@NX-01 link-test]$ ll total 0 [kris@NX-01 link-test]$ mkdir target [kris@NX-01 link-test]$ ll total 0 drwxrwxr-x 2 kris kris 40 Apr 23 10:49 target [kris@NX-01 link-test]$ ln -s target/ link [kris@NX-01 link-test]$ ll total 0 lrwxrwxrwx 1 kris kris 7 Apr 23 10:49 link -> target/ drwxrwxr-x 2 kris kris 40 Apr 23 10:49 target [kris@NX-01 link-test]$ ln -sf target link [kris@NX-01 link-test]$ ll total 0 lrwxrwxrwx 1 kris kris 7 Apr 23 10:49 link -> target/ drwxrwxr-x 2 kris kris 60 Apr 23 10:49 target
In this example, I'm demonstrating the same as above, but I'm not using a slash in the target. This shows that the order of operations matters.
[kris@NX-01 link-test]$ ll total 0 drwxrwxr-x 2 kris kris 60 Apr 23 10:54 target [kris@NX-01 link-test]$ [kris@NX-01 link-test]$ ln -s target link [kris@NX-01 link-test]$ ll total 0 lrwxrwxrwx 1 kris kris 6 Apr 23 10:55 link -> target drwxrwxr-x 2 kris kris 60 Apr 23 10:54 target [kris@NX-01 link-test]$ ln -sf target/ link [kris@NX-01 link-test]$ ll total 0 lrwxrwxrwx 1 kris kris 6 Apr 23 10:55 link -> target drwxrwxr-x 2 kris kris 60 Apr 23 10:55 target
You created another symlink inside your target folder, that is why you cannot see the new link. Use ln -nfs
to create your links.
Is it possible this is caused by #801?
@julienlavergne would it be possible to get the full run with -vvv --debug
flags added? I cannot replicate this which makes it hard to debug!
Yes, here is the debug log. I changed some names for privacy but I did not remove any line.
Describe the bug
When a symbolic link exists, points to a directory and contains a trailing separator, using
files.link
to create a link to the same folder without the trailing separator will not replace the existing link.According to the doc: If the link exists and points to a different target, pyinfra will remove it and recreate a new one pointing to then new target.
To Reproduce
tasks/link.py
inventories/local.py
group_data/all.py
Result
Expected behavior
I would expect the link to be replaced if the old link is not strictly the same. It is not possible for pyinfra to know if my link is supposed to refer to a directory or file.
Final link should be
/home/link -> target
Meta
Include output of
pyinfra --support
.