Changeset View
Changeset View
Standalone View
Standalone View
src/filesystem/Filesystem.php
Context not available. | |||||
$path, | $path, | ||||
pht("Failed to open file '%s'.", $path)); | pht("Failed to open file '%s'.", $path)); | ||||
} | } | ||||
$dlen = strlen($data); | $dlen = @strlen($data); | ||||
if (fwrite($fh, $data) !== $dlen) { | if (fwrite($fh, $data) !== $dlen) { | ||||
throw new FilesystemException( | throw new FilesystemException( | ||||
$path, | $path, | ||||
Context not available. | |||||
$trap->destroy(); | $trap->destroy(); | ||||
if (!$ok) { | if (!$ok) { | ||||
if (strlen($err)) { | if (@strlen($err)) { | ||||
throw new FilesystemException( | throw new FilesystemException( | ||||
$to, | $to, | ||||
pht( | pht( | ||||
Context not available. | |||||
* @task file | * @task file | ||||
*/ | */ | ||||
public static function remove($path) { | public static function remove($path) { | ||||
if (!strlen($path)) { | if (!@strlen($path)) { | ||||
// Avoid removing PWD. | // Avoid removing PWD. | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
Context not available. | |||||
'openssl_random_pseudo_bytes()')); | 'openssl_random_pseudo_bytes()')); | ||||
} | } | ||||
if (strlen($data) != $number_of_bytes) { | if (@strlen($data) != $number_of_bytes) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'%s returned an unexpected number of bytes (got %s, expected %s)!', | '%s returned an unexpected number of bytes (got %s, expected %s)!', | ||||
'openssl_random_pseudo_bytes()', | 'openssl_random_pseudo_bytes()', | ||||
new PhutilNumber(strlen($data)), | new PhutilNumber(@strlen($data)), | ||||
new PhutilNumber($number_of_bytes))); | new PhutilNumber($number_of_bytes))); | ||||
} | } | ||||
Context not available. | |||||
if ($urandom) { | if ($urandom) { | ||||
$data = @fread($urandom, $number_of_bytes); | $data = @fread($urandom, $number_of_bytes); | ||||
@fclose($urandom); | @fclose($urandom); | ||||
if (strlen($data) != $number_of_bytes) { | if (@strlen($data) != $number_of_bytes) { | ||||
throw new FilesystemException( | throw new FilesystemException( | ||||
'/dev/urandom', | '/dev/urandom', | ||||
pht('Failed to read random bytes!')); | pht('Failed to read random bytes!')); | ||||
Context not available. | |||||
} | } | ||||
// If we come back with an encoding, strip it off. | // If we come back with an encoding, strip it off. | ||||
if (strpos($mime_type, ';') !== false) { | if (@strpos($mime_type, ';') !== false) { | ||||
list($type, $encoding) = explode(';', $mime_type, 2); | list($type, $encoding) = @explode(';', $mime_type, 2); | ||||
$mime_type = $type; | $mime_type = $type; | ||||
} | } | ||||
Context not available. | |||||
$tries = 3; | $tries = 3; | ||||
do { | do { | ||||
$dir = $base.substr(base_convert(md5(mt_rand()), 16, 36), 0, 16); | $dir = $base.@substr(base_convert(md5(mt_rand()), 16, 36), 0, 16); | ||||
try { | try { | ||||
self::createDirectory($dir, $umask); | self::createDirectory($dir, $umask); | ||||
break; | break; | ||||
Context not available. | |||||
} | } | ||||
$walk = array(); | $walk = array(); | ||||
$parts = explode(DIRECTORY_SEPARATOR, $path); | $parts = @explode(DIRECTORY_SEPARATOR, $path); | ||||
foreach ($parts as $k => $part) { | foreach ($parts as $k => $part) { | ||||
if (!strlen($part)) { | if (!@strlen($part)) { | ||||
unset($parts[$k]); | unset($parts[$k]); | ||||
} | } | ||||
} | } | ||||
Context not available. | |||||
*/ | */ | ||||
public static function isAbsolutePath($path) { | public static function isAbsolutePath($path) { | ||||
if (phutil_is_windows()) { | if (phutil_is_windows()) { | ||||
return (bool)preg_match('/^[A-Za-z]+:/', $path); | return (bool)@preg_match('/^[A-Za-z]+:/', $path); | ||||
} else { | } else { | ||||
return !strncmp($path, DIRECTORY_SEPARATOR, 1); | return !strncmp($path, DIRECTORY_SEPARATOR, 1); | ||||
} | } | ||||
Context not available. | |||||
$path = str_replace('/', '\\', $path); | $path = str_replace('/', '\\', $path); | ||||
} else { | } else { | ||||
$parts = trim($path, '/'); | $parts = trim($path, '/'); | ||||
$parts = explode('/', $parts); | $parts = @explode('/', $parts); | ||||
} | } | ||||
while ($parts) { | while ($parts) { | ||||
Context not available. | |||||
} | } | ||||
$realpath = realpath($attempt); | $realpath = realpath($attempt); | ||||
if ($realpath !== false) { | if ($realpath !== false) { | ||||
$path = $realpath.substr($path, strlen($attempt)); | $path = $realpath.@substr($path, @strlen($attempt)); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
Context not available. | |||||
foreach (array($pwd, self::resolvePath($pwd)) as $parent) { | foreach (array($pwd, self::resolvePath($pwd)) as $parent) { | ||||
$parent = rtrim($parent, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; | $parent = rtrim($parent, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; | ||||
$len = strlen($parent); | $len = @strlen($parent); | ||||
if (!strncmp($parent, $path, $len)) { | if (!strncmp($parent, $path, $len)) { | ||||
$path = substr($path, $len); | $path = @substr($path, $len); | ||||
return $path; | return $path; | ||||
} | } | ||||
} | } | ||||
Context not available. |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0