PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/downloader/lib/Mage/System/Dirs.php

https://gitlab.com/LisovyiEvhenii/ismextensions
PHP | 104 lines | 65 code | 7 blank | 32 comment | 18 complexity | 3a1c0021175e04a93082e3084e0d1dfb MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_System
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. class Mage_System_Dirs
  27. {
  28. public static function rm($dirname)
  29. {
  30. if(is_array($dirname)) {
  31. $dirname = $dirname[1];
  32. }
  33. // Sanity check
  34. if (!@file_exists($dirname)) {
  35. return false;
  36. }
  37. // Simple delete for a file
  38. if (@is_file($dirname) || @is_link($dirname)) {
  39. return unlink($dirname);
  40. }
  41. // Create and iterate stack
  42. $stack = array($dirname);
  43. while ($entry = array_pop($stack)) {
  44. // Watch for symlinks
  45. if (@is_link($entry)) {
  46. @unlink($entry);
  47. continue;
  48. }
  49. // Attempt to remove the directory
  50. if (@rmdir($entry)) {
  51. continue;
  52. }
  53. // Otherwise add it to the stack
  54. $stack[] = $entry;
  55. $dh = opendir($entry);
  56. while (false !== $child = readdir($dh)) {
  57. // Ignore pointers
  58. if ($child === '.' || $child === '..') {
  59. continue;
  60. }
  61. // Unlink files and add directories to stack
  62. $child = $entry . DIRECTORY_SEPARATOR . $child;
  63. if (is_dir($child) && !is_link($child)) {
  64. $stack[] = $child;
  65. } else {
  66. @unlink($child);
  67. }
  68. }
  69. @closedir($dh);
  70. }
  71. return true;
  72. }
  73. public static function mkdirStrict($path, $recursive = true, $mode = 0777)
  74. {
  75. $exists = file_exists($path);
  76. if($exists && is_dir($path)) {
  77. return true;
  78. }
  79. if($exists && !is_dir($path)) {
  80. throw new Exception("'{$path}' already exists, should be a dir, not a file!");
  81. }
  82. $out = @mkdir($path, $mode, $recursive);
  83. if(false === $out) {
  84. throw new Exception("Can't create dir: '{$path}'");
  85. }
  86. return true;
  87. }
  88. public static function copyFileStrict($source, $dest)
  89. {
  90. $exists = file_exists($source);
  91. if(!$exists) {
  92. throw new Exception('No file exists: '.$exists);
  93. }
  94. }
  95. }