Documentation
¶
Overview ¶
Command tmppath refuses a fixed path in the shared temporary directory in the non-test Go source of a tree.
⛔ WHY IT EXISTS. go-filesystems/ext4 v0.7.1-v0.7.3 wrote logs and raw block dumps to fixed `/tmp/ext4_*` paths, and go-filesystems/kerneljudge <= v0.4.0 wrote a Python script to `os.TempDir()/kerneljudge-ole.py` and EXECUTED it: a fixed name in a directory every user can write is a swap or a symlink away from overwriting a file or running somebody else's code. Both were fixed with a copied source-test guard; this is the one shared gate.
It reads the SYNTAX TREE, not the text: a comment that mentions os.TempDir() does not match (unarchive dmg.go:48, oci limits.go:147 do exactly that). In every non-_test.go file, skipping testdata/ and dot-directories, it flags
- a string literal that is /tmp or /var/tmp, or begins with either followed by a slash (so "/tmpl" is not one);
- os.TempDir, ioutil.TempFile and ioutil.TempDir, called or taken as a value (the import is resolved, so an alias is seen and a local variable named os is not).
os.CreateTemp and os.MkdirTemp are NOT flagged: their names are random and created O_EXCL.
An allow comment `//tmppath:ok <reason>` on the same line accepts one finding. A comment with an EMPTY reason is itself a finding and accepts nothing.
⛔ A FILE IT COULD NOT READ IS UNREAD, NEVER CLEAN: a parse error or an unreadable directory is reported UNREAD and makes the status 2.