-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mktmpdir has inconsistent behavior #15
Comments
<Rafael Schloming> https://circleci.com/gh/datawire/teleproxy/837 any clue why the mac build is failing? it's a permissions thing, so maybe mac people would have more of a clue? <Luke Shumaker> @rhs At 8:34 last night, https://install.goreleaser.com/github.com/golangci/golangci-lint.sh added `rm -rf "${tmpdir}"` to the end of their script, and `tmpdir` gets set in a braindead way if `TMPDIR` is set. So the short-term fix is swap that URL for https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh, and the longer-term fix is to go yell at the goreleaser guys and maybe send them a PR. See also: goreleaser/godownloader#104 client9/shlib#15 goreleaser/godownloader#105
Is this still an issue? Seems as though the PRs have been merged |
A workaround was merged in to godownloader, but no PR was ever submitted upstream here. |
@LukeShu Can you link me to the fix in godownloader? Would love to backport a fix into shlib as well.
|
The fix in godownloader (goreleaser/godownloader#105) was just "don't use In my opinion, both of the "correct implementations" I included in the issue body are "PR-worthy", but I'm not sure which behavior is desired. |
See: goreleaser/godownloader#104
TMPDIR
is a shared temporary directory (specified by POSIX); being unset should be mostly equivalent toTMPDIR=/tmp
. Many systems will setTMPDIR
to a new temporary directory on each login; I have seen this on many GNU/Linux systems, and know that it is the default behavior on macOS. Multiple programs shareTMPDIR
for the duration of that login.If a program uses more than 1 temporary file, it is likely desirable to contain them in a per-program-invocation temporary subdirectory of
TMPDIR
. In C,mkdtemp(3)
(POSIX) is helpful for this purpose; in shell, the wrapper around that,mktemp -d
(non-POSIX, but widely implemented) is helpful. The program should remember to remove that subdirectory before it exits.mktmpdir
has wildly different behavior whenTMPDIR
is set compared to when it's not set:TMPDIR
is not already set: it is necessary to clean up the returned directory when the program is done; it has created a new temporary directory that would otherwise be leaked.TMPDIR
is already set: it is impermissible to clean up the returned directory when the program is done; it returns the shared temporary directory, other programs may be using it, the user may not have permission to remove it.I believe the intent of the
mktmpdir
author was thatTMPDIR
be a private "static" variable to makemktmpdir
return the same value if you call it multiple times (let us call this property "idempotence". However, that use conflicts with the use ofTMPDIR
as specified by POSIX. Maybe it was just sloppy thinking.Besides idempotency,
mktmpdir
also has the property that it handlesTMPDIR
being set to a directory that does not exist; a scenario thatmktemp -d
does not handle.A correct implementation would look like:
If idempotency is not a desired property:
If idempotency is a desired property:
The text was updated successfully, but these errors were encountered: