From: Michael Wallner Date: Wed, 19 Aug 2015 19:39:04 +0000 (+0200) Subject: remove hard dependency on ext/posix X-Git-Tag: v4.1.0~20 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=ce54d468fa97453d949185c0128b435add9aa68d;p=pharext%2Fpharext remove hard dependency on ext/posix --- diff --git a/bin/pharext b/bin/pharext index f3ff98a..7640c6d 100755 Binary files a/bin/pharext and b/bin/pharext differ 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 */