Closed timotheecour closed 3 years ago
This makes sense in the context of a shell, but for a language? Why not just use writeFile(path, "")
.
"touching" a file is (almost?) always a workaround for a broken tool that uses timestamps rather than checksums. I can't imagine use cases that are not gross hacks.
Why not just use writeFile(path, "").
that has different semantics; touch creates the file if it doesn't exist, else updates the timestamp
This makes sense in the context of a shell, but for a language?
nim is general purpose and users shouldn't have to resort to shelling out to run their scripts (which is also less safe)
it's also built in python >= 3.4 standard library, see https://stackoverflow.com/questions/1158076/implement-touch-using-python
from pathlib import Path
Path('path/to/file.txt').touch()
Path.touch(mode=0o777, exist_ok=True) Create a file at this given path. If mode is given, it is combined with the process’ umask value to determine the file mode and access flags. If the file already exists, the function succeeds if exist_ok is true (and its modification time is updated to the current time), otherwise FileExistsError is raised.
"touching" a file is (almost?) always a workaround for a broken tool that uses timestamps rather than checksums. I can't imagine use cases that are not gross hacks.
a doc comment pointing to MD5 hash can be added, but this has its use cases, just like linux's touch
+ python's pathlib.touch
does, if anything, to port scripts, write tests etc.
if it's ommitted, users who want it will likely resort to the unsafe/not portable alternative execShellCmd(fmt"touch {file.quoteSell}")
out of laziness.
note: as an alternative, I can add it to new fusion/os
module (which is expected to grow)
would avoid packages having to roll their own versions:
if path.fileExists: ... else: ...
which have race conditionslikeliky similar to https://remarkablemark.org/blog/2017/12/17/touch-file-nodejs/ based on try ... except
to avoid race condition
Look, "touch" is really a metaphor for an incredibly poor mechanism which could also be named as updateTimestampOrCreateFile
. Known cases where I don't know which of these two unrelated functions I really need: None.
Can we close this now?
willing to drop this one for the sake of moving on
semantics
raises if touchDir is applied on a file or touchFile is applied on a dir, or if these calls fail on windows, emulation can be used, eg: https://stackoverflow.com/questions/30011267/windows-equivalent-of-touch-i-e-the-node-js-way-to-create-an-index-html
design choice
touchPath
that'd work with both files and dirs, but touchFile+touchDir probably makes more sense to ensure desired semantics; touchPath could be added in future if needed, which would work with either.