Add FileExists and DirExists for checking what is at a path #16
Reference in New Issue
Block a user
Delete Branch "clawbot/util:proposal-file-exists"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds
FileExists(path string) boolandDirExists(path string) bool, whichreport whether a path holds a regular file or a directory.
These belong here because command-line programs ask the question constantly and
the standard library only offers
os.Statplus an error check, which isregularly written wrongly: a directory passes an "it exists" test when the
caller wanted a file, and an error that is not "not found" gets treated as
absence anyway. They also sit next to the existing
MkdirpandCopyFile.Things to know:
is missing, so a permission problem is indistinguishable from absence. That
is deliberate, since neither case gives the caller a usable file, but a caller
who needs to tell the two apart should use
os.Statdirectly.os.Statfollows them. A link pointingat nothing is false. There are tests for both.
removed between the check and the open, so code that then opens the file
should still handle the error rather than trust the check.
t.TempDir, which needs Go 1.15, whilego.modstill saysgo 1.14. Building with a toolchain that old is not something anyone isdoing in practice, but raising that line would make the file honest, and it
is left out of here so the ten proposal branches do not conflict over it.
exists.go, for the same reason.make teston this branch reports one failure,TestNowUnixMicro. That testalready fails on
masterand is unrelated to this change.Model: opus-5