ansible-stow
ansible-stow copied to clipboard
Compute `changed` when `state: latest` by diffing `LINK` and `UNLINK` lines in verbose stderr
Right now, changed
is always true when re-stowing because stderr is always populated. It should be possible to tell when something actually changed by looking at the verbose output on stderr
:
- Any line that matches
^LINK
but not(reverts previous action)$
is a "real" change, because it's a new file. - Any line that matches
^UNLINK
but doesn't have a corresponding line matching^LINK
is a "real" change, because it's file that disappeared. - Any line that doesn't match
^LINK
or^UNLINK
indicates something else that might or might not be a change and should probably just be a change.
Proof of concept would look something like this (untested):
unlink_re = re.compile('^'
'UNLINK: '
'(?P<link_path>.+)'
'$')
link_re = re.compile('^'
'LINK: '
'(?P<file_path>.+)'
' => '
'(?P<link_path>.+)'
'(?P<reverts> \(reverts previous action\))?'
'$')
unlinks = set()
links = set()
for line in _se:
result = re.match()
if result:
unlinks.add(result.group('link_path'))
for line in _se:
result = link_re.match()
if result:
links.add(result.group('link_path'))
changed = unlinks == links
Could you look the PR I sent? Didn't have much time to work on this but it yield some OKish results. Needs to be more stressed.