Open srchulo opened 5 years ago
The unlink
command only logs something if it would actually do something. However, in your example the file to be deleted was only created with a dry-run command itself, so it did not exist for the unlink
command.
This problem is broader. For example dry-run would even fail if one touches a file and then runs the change_file
command — because change_file
requires an existing file. I was thinking about keeping track what would happen to the file system in a dry-run mode, e.g. files created, files deleted, content to files written... some kind of a virtual in-memory file system. If the user would then use one of the Doit commands for touching a file (touch
or create_file_if_nonexisting
), then unlink
could first lookup into this virtual file system. However, this would not work if the user uses run
or system
--- in this case probably the user should give Doit a hint that the system commands creates something in the file system, similar to Puppet's creates
option in its exec
resource.
Ah, I see. I guess I misunderstood --dry-run
mode. I expected it to log what it would attempt to do, not what it would actually do, since that could be different at runtime, based on the other doit commands, as you noted. It could also be different based on other perl code run locally in the same script not via Doit, so I think it would be very hard to predict if it would have an effect or not. I expected unlink
to run and have have no effect if the file did not exist.
I think a hint like you mentioned above may be best, since as you pointed out, run
or system
could really do anything.
And I guess this probably also applies to things like cond_run
as well. I guess even though it's really hard to know what will happen since we are not actually running commands, showing everything may not be the best either, since there is branching and only some things may actually be run.
I do think branching is slightly different from things that could be attempted and aren't conditional. For instance, unlink
I think it would be clear that if it was shown, I wouldn't expect it to do anything if the file didn't exist. But for cond_run
or if
/else
branching, that would be really complicated.
When I run a script with
--dry-run
that callsunlink
via ssh, it does not show theunlink
command in the--dry-run
:But when I actually run it, it does run the
unlink
and it logs it out: