The idea is to provide a basic touch function in the babashka.fs namespace. The
function would provide an easy way to create files (e.g., for testing) or an easy way to ensure a file has a certain timestamp (can be useful in a build process), perhaps to "dirty" the file without actually changing it. Google for something like "linux use cases for touch(1)" for more ideas.
The intent is not to "clone" touch(1). As part of a Babashka library it can be used in ways that would be difficult to duplicate with touch(1) in the shell. OTOH, for some of the more esoteric options that won't be implemented, one can always invoke a subprocess if needed.
fs/touch
[fil] [fil tim]
- If
fil doesn't exist, create it
- If not specified,
tim defaults to the time the function is called
- If
tim is specified it should be suitable for fs/set-last-modified-time
- Set the file last-modified time for
fil to tim
(It might seem inelegant to set a freshly created file to the current time, but I suspect that's the most direct code path & not a efficency concern for typical use.)
If fil refers to a symbolic link, the default behavior is to follow the link and set the
time of the target. This matches the default for Gnu touch(1). To specify other
behavior, pass an option map {:nofollow-links true}, matching the behavior of most fs functions. (At least once #231 is taken care of)
The idea is to provide a basic
touchfunction in thebabashka.fsnamespace. Thefunction would provide an easy way to create files (e.g., for testing) or an easy way to ensure a file has a certain timestamp (can be useful in a build process), perhaps to "dirty" the file without actually changing it. Google for something like "linux use cases for touch(1)" for more ideas.
The intent is not to "clone"
touch(1). As part of a Babashka library it can be used in ways that would be difficult to duplicate withtouch(1)in the shell. OTOH, for some of the more esoteric options that won't be implemented, one can always invoke a subprocess if needed.fs/touch
[fil] [fil tim]
fildoesn't exist, create ittimdefaults to the time the function is calledtimis specified it should be suitable forfs/set-last-modified-timefiltotim(It might seem inelegant to set a freshly created file to the current time, but I suspect that's the most direct code path & not a efficency concern for typical use.)
If
filrefers to a symbolic link, the default behavior is to follow the link and set thetime of the target. This matches the default for Gnu
touch(1). To specify otherbehavior, pass an option map
{:nofollow-links true}, matching the behavior of mostfsfunctions. (At least once #231 is taken care of)