X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fpharext%2FTempname.php;h=31160235ddc4ad7afb72cec19749aa171f02386e;hb=f55545591b80c22e8e3ca4dffe2ac68c59090835;hp=d46250f7472b379e44ea17f98355af06d2f83eab;hpb=b632c5fcceda2e2b1cda995e34a34708e3a87ce0;p=pharext%2Fpharext diff --git a/src/pharext/Tempname.php b/src/pharext/Tempname.php index d46250f..3116023 100644 --- a/src/pharext/Tempname.php +++ b/src/pharext/Tempname.php @@ -19,13 +19,23 @@ class Tempname * @param string $suffix e.g. file extension */ public function __construct($prefix, $suffix = null) { - $temp = sys_get_temp_dir() . "/pharext-" . posix_getlogin(); + $temp = sys_get_temp_dir() . "/pharext-" . $this->getUser(); if (!is_dir($temp) && !mkdir($temp, 0700, true)) { throw new Exception; } $this->name = $temp ."/". uniqid($prefix) . $suffix; } + private function getUser() { + if (extension_loaded("posix") && function_exists("posix_getpwuid")) { + return posix_getpwuid(posix_getuid())["name"]; + } + return trim(`whoami 2>/dev/null`) + ?: trim(`id -nu 2>/dev/null`) + ?: getenv("USER") + ?: get_current_user(); + } + /** * @return string */