Skip to content

Instantly share code, notes, and snippets.

@schneems
Last active September 15, 2021 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schneems/681a42ee54aa91a2185f49556469b319 to your computer and use it in GitHub Desktop.
Save schneems/681a42ee54aa91a2185f49556469b319 to your computer and use it in GitHub Desktop.

Pathname#touch kwargs

Looking into supporting all kwargs. Here's FileUtils.touch:

  def touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil)

and here's FileUtils.mkdir_p:

  def mkdir_p(list, mode: nil, noop: nil, verbose: nil)

The API I'm proposing does both of these operations. We would need to make sure all options make sense with both of these APIs. It would be confusing to specify "noop" and have it create the directories, but not the file.

The superset of all options are:

  • mtime
  • nocreate
  • noop
  • verbose
  • mode

Most of these make sense to me, but i'm unfamiliar with nocreate from the manpages on touch:

-c Do not create the file if it does not exist.  The touch utility does not treat this as an error.  No error messages are displayed and the exit value is not affected.

Since not all interfaces use all options we would need to consider what we want to happen for each:

  • mtime
    • touch: Supports this keyword
    • mkpath: Change nothing, make the directories, interface sets mtime of file, not directory
  • nocreate
    • touch: Supports this keyword
    • mkpath: Change nothing, make the directories, flag only makes sense on touch
  • mode
    • touch: Change nothing, inherit whatever mode is set from the OS
    • mkpath: Supports this keyword
  • noop
    • touch: Supports this keyword
    • mkpath: Supports this keyword
  • verbose
    • touch: Supports this keyword
    • mkpath: Supports this keyword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment