Changeset View
Changeset View
Standalone View
Standalone View
src/filesystem/Filesystem.php
| Show First 20 Lines • Show All 482 Lines • ▼ Show 20 Lines | public static function readRandomBytes($number_of_bytes) { | ||||
| // We've failed to find any valid entropy source. Try to fail in the most | // We've failed to find any valid entropy source. Try to fail in the most | ||||
| // useful way we can, based on the platform. | // useful way we can, based on the platform. | ||||
| if (phutil_is_windows()) { | if (phutil_is_windows()) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| '%s requires the PHP OpenSSL extension to be installed and enabled '. | '%s requires the PHP OpenSSL extension to be installed and enabled '. | ||||
| 'to access an entropy source. On Windows, this extension is usually '. | 'to access an entropy source. On Windows, this extension is usually '. | ||||
| 'installed but not enabled by default. Enable it in your "s".', | 'installed but not enabled by default. Enable it in your "php.ini".', | ||||
| __METHOD__.'()', | __METHOD__.'()')); | ||||
| 'php.ini')); | |||||
| } | } | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| '%s requires the PHP OpenSSL extension or access to "%s". Install or '. | '%s requires the PHP OpenSSL extension or access to "%s". Install or '. | ||||
| 'enable the OpenSSL extension, or make sure "%s" is accessible.', | 'enable the OpenSSL extension, or make sure "%s" is accessible.', | ||||
| __METHOD__.'()', | __METHOD__.'()', | ||||
| '/dev/urandom', | '/dev/urandom', | ||||
| ▲ Show 20 Lines • Show All 443 Lines • ▼ Show 20 Lines | public static function resolvePath($path, $relative_to = null) { | ||||
| if ($realpath !== false) { | if ($realpath !== false) { | ||||
| return $realpath; | return $realpath; | ||||
| } | } | ||||
| // This won't work if the file doesn't exist or is on an unreadable mount | // This won't work if the file doesn't exist or is on an unreadable mount | ||||
| // or something crazy like that. Try to resolve a parent so we at least | // or something crazy like that. Try to resolve a parent so we at least | ||||
| // cover the nonexistent file case. | // cover the nonexistent file case. | ||||
| $parts = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR)); | |||||
| while (end($parts) !== false) { | // We're also normalizing path separators to whatever is normal for the | ||||
| // environment. | |||||
| if (phutil_is_windows()) { | |||||
| $parts = trim($path, '/\\'); | |||||
| $parts = preg_split('([/\\\\])', $parts); | |||||
| // Normalize the directory separators in the path. If we find a parent | |||||
| // below, we'll overwrite this with a better resolved path. | |||||
| $path = str_replace('/', '\\', $path); | |||||
| } else { | |||||
| $parts = trim($path, '/'); | |||||
| $parts = explode('/', $parts); | |||||
| } | |||||
| while ($parts) { | |||||
| array_pop($parts); | array_pop($parts); | ||||
| if (phutil_is_windows()) { | if (phutil_is_windows()) { | ||||
| $attempt = implode(DIRECTORY_SEPARATOR, $parts); | $attempt = implode(DIRECTORY_SEPARATOR, $parts); | ||||
| } else { | } else { | ||||
| $attempt = DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts); | $attempt = DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts); | ||||
| } | } | ||||
| $realpath = realpath($attempt); | $realpath = realpath($attempt); | ||||
| if ($realpath !== false) { | if ($realpath !== false) { | ||||
| ▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | if ($real_u) { | ||||
| $u = $real_u; | $u = $real_u; | ||||
| } | } | ||||
| if ($real_v) { | if ($real_v) { | ||||
| $v = $real_v; | $v = $real_v; | ||||
| } | } | ||||
| return ($u == $v); | return ($u == $v); | ||||
| } | } | ||||
| public static function concatenatePaths(array $components) { | |||||
| $components = implode($components, DIRECTORY_SEPARATOR); | |||||
| // Replace any extra sequences of directory separators with a single | |||||
| // separator, so we don't end up with "path//to///thing.c". | |||||
| $components = preg_replace( | |||||
| '('.preg_quote(DIRECTORY_SEPARATOR).'{2,})', | |||||
| DIRECTORY_SEPARATOR, | |||||
| $components); | |||||
| return $components; | |||||
| } | |||||
| /* -( Assert )------------------------------------------------------------- */ | /* -( Assert )------------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * Assert that something (e.g., a file, directory, or symlink) exists at a | * Assert that something (e.g., a file, directory, or symlink) exists at a | ||||
| * specified location. | * specified location. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines | |||||