| 1 | <?php |
| 2 | namespace Civi\Setup; |
| 3 | |
| 4 | class FileUtil { |
| 5 | |
| 6 | public static function isCreateable($file) { |
| 7 | if (file_exists($file)) { |
| 8 | return is_writable($file); |
| 9 | } |
| 10 | |
| 11 | $next = dirname($file); |
| 12 | do { |
| 13 | $current = $next; |
| 14 | if (file_exists($current)) { |
| 15 | return is_writable($current); |
| 16 | } |
| 17 | $next = dirname($current); |
| 18 | } while ($current && $next && $current != $next); |
| 19 | |
| 20 | return FALSE; |
| 21 | } |
| 22 | |
| 23 | public static function makeWebWriteable($path) { |
| 24 | // Blerg: Setting world-writable works as a default, but |
| 25 | // it 'sprone to break systems that rely on umask's or facl's. |
| 26 | chmod($path, 0777); |
| 27 | } |
| 28 | |
| 29 | public static function isDeletable($path) { |
| 30 | return is_writable(dirname($path)); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param $prefix |
| 35 | * |
| 36 | * @return string |
| 37 | */ |
| 38 | public static function createTempDir($prefix) { |
| 39 | $newTempDir = tempnam(sys_get_temp_dir(), $prefix) . '.d'; |
| 40 | mkdir($newTempDir, 0755, TRUE); |
| 41 | |
| 42 | return $newTempDir; |
| 43 | } |
| 44 | |
| 45 | } |