{"action":"created","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/20910","labels_url":"https://api.github.com/repos/saltstack/salt/issues/20910/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/20910/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/20910/events","html_url":"https://github.com/saltstack/salt/issues/20910","id":58480186,"number":20910,"title":"file.replace overwrites symbolic links","user":{"login":"lorengordon","id":8457307,"avatar_url":"https://avatars.githubusercontent.com/u/8457307?v=3","gravatar_id":"","url":"https://api.github.com/users/lorengordon","html_url":"https://github.com/lorengordon","followers_url":"https://api.github.com/users/lorengordon/followers","following_url":"https://api.github.com/users/lorengordon/following{/other_user}","gists_url":"https://api.github.com/users/lorengordon/gists{/gist_id}","starred_url":"https://api.github.com/users/lorengordon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lorengordon/subscriptions","organizations_url":"https://api.github.com/users/lorengordon/orgs","repos_url":"https://api.github.com/users/lorengordon/repos","events_url":"https://api.github.com/users/lorengordon/events{/privacy}","received_events_url":"https://api.github.com/users/lorengordon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-21T23:38:48Z","updated_at":"2015-02-23T16:58:42Z","closed_at":null,"body":"If the target of `file.replace` is a symbolic link, `file.replace` is writing a new, regular file over the symbolic link. This happens whether or not there is a change to the file.\r\n\r\n```\r\n# echo \"baz\" > foo\r\n# ln -s foo bar\r\n# ls -al\r\ntotal 40\r\ndr-xr-x---  4 root root 4096 Feb 21 18:20 .\r\ndr-xr-xr-x 24 root root 4096 Feb 21  2015 ..\r\nlrwxrwxrwx  1 root root    3 Feb 21 18:20 bar -> foo\r\n-rw-r--r--  1 root root    4 Feb 21 17:47 foo\r\n```\r\n\r\nNote that `bar` is a symbolic link. Now:\r\n\r\n```\r\n# salt-call --local file.replace bar badstring justbecause\r\nlocal:\r\n\r\n#\r\n# ls -al\r\ntotal 44\r\ndr-xr-x---  4 root root 4096 Feb 21 18:22 .\r\ndr-xr-xr-x 24 root root 4096 Feb 21  2015 ..\r\n-rw-r--r--  1 root root    4 Feb 21 18:22 bar\r\nlrwxrwxrwx  1 root root    3 Feb 21 18:20 bar.bak -> foo\r\n-rw-r--r--  1 root root    4 Feb 21 17:47 foo\r\n```\r\n\r\nNote that `bar` is no longer a symbolic link.\r\n\r\n```\r\n# salt-call --versions-report\r\n           Salt: 2014.7.0\r\n         Python: 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)\r\n         Jinja2: 2.2.1\r\n       M2Crypto: 0.20.2\r\n msgpack-python: 0.4.4\r\n   msgpack-pure: Not Installed\r\n       pycrypto: 2.0.1\r\n        libnacl: Not Installed\r\n         PyYAML: 3.10\r\n          ioflo: Not Installed\r\n          PyZMQ: 14.3.1\r\n           RAET: Not Installed\r\n            ZMQ: 3.2.4\r\n           Mako: Not Installed\r\n```"},"comment":{"url":"https://api.github.com/repos/saltstack/salt/issues/comments/75583015","html_url":"https://github.com/saltstack/salt/issues/20910#issuecomment-75583015","issue_url":"https://api.github.com/repos/saltstack/salt/issues/20910","id":75583015,"user":{"login":"jfindlay","id":702905,"avatar_url":"https://avatars.githubusercontent.com/u/702905?v=3","gravatar_id":"","url":"https://api.github.com/users/jfindlay","html_url":"https://github.com/jfindlay","followers_url":"https://api.github.com/users/jfindlay/followers","following_url":"https://api.github.com/users/jfindlay/following{/other_user}","gists_url":"https://api.github.com/users/jfindlay/gists{/gist_id}","starred_url":"https://api.github.com/users/jfindlay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfindlay/subscriptions","organizations_url":"https://api.github.com/users/jfindlay/orgs","repos_url":"https://api.github.com/users/jfindlay/repos","events_url":"https://api.github.com/users/jfindlay/events{/privacy}","received_events_url":"https://api.github.com/users/jfindlay/received_events","type":"User","site_admin":false},"created_at":"2015-02-23T16:58:42Z","updated_at":"2015-02-23T16:58:42Z","body":"Part of the reason for having symbolic links is to redirect actions to the target, \r\n```\r\n$ echo asdf > file\r\n$ ln -s file link\r\n$ echo zxcv > link\r\n$ cat file\r\nzxcv\r\n```\r\nCausing `file.replace` to respect symbolic links would be a change of behavior, but I don't know of any tool or utility that operates on files that will clobber a symbolic link in this way.  Such behavior is less than well-defined and is somewhat risky, but you create symbolic links knowing and expecting this."}}