Skip to content

Proposal for the addition of fs/touch #232

@jdjohnston

Description

@jdjohnston

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions