[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/VFS/ISOWriter/RealInputStrategy/ -> copy.php (source)

   1  <?php
   2  
   3  /**
   4   * Strategy for copying input tree out of a VFS
   5   *
   6   * $Horde: framework/VFS_ISOWriter/ISOWriter/RealInputStrategy/copy.php,v 1.1.8.5 2006/01/01 21:28:44 jan Exp $
   7   *
   8   * Copyright 2004-2006 Cronosys, LLC <http://www.cronosys.com/>
   9   *
  10   * See the enclosed file COPYING for license information (LGPL). If you
  11   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  12   *
  13   * @author  Jason M. Felice <jfelice@cronosys.com>
  14   * @package VFS_ISO
  15   * @since   Horde 3.0
  16   */
  17  class VFS_ISOWriter_RealInputStrategy_copy extends VFS_ISOWriter_RealInputStrategy {
  18  
  19      var $_tempPath = null;
  20  
  21      function getRealPath()
  22      {
  23          if (is_null($this->_tempPath)) {
  24              $tmp_locations = array('/tmp', '/var/tmp', 'c:\WUTemp', 'c:\temp',
  25                                     'c:\windows\temp', 'c:\winnt\temp');
  26  
  27              /* First, try PHP's upload_tmp_dir directive. */
  28              $tmp = ini_get('upload_tmp_dir');
  29  
  30              /* Otherwise, try to determine the TMPDIR environment
  31               * variable. */
  32              if (empty($tmp)) {
  33                  $tmp = getenv('TMPDIR');
  34              }
  35  
  36              /* If we still cannot determine a value, then cycle through a
  37               * list of preset possibilities. */
  38              while (empty($tmp) && count($tmp_locations)) {
  39                  $tmp_check = array_shift($tmp_locations);
  40                  if (@is_dir($tmp_check)) {
  41                      $tmp = $tmp_check;
  42                  }
  43              }
  44  
  45              if (empty($tmp)) {
  46                  return PEAR::raiseError(_("Cannot find a temporary directory."));
  47              }
  48  
  49              $this->_tempPath = tempnam($tmp, 'isod');
  50              @unlink($this->_tempPath);
  51  
  52              $res = $this->_copyToTempPath();
  53              if (is_a($res, 'PEAR_Error')) {
  54                  return $res;
  55              }
  56          }
  57  
  58          return $this->_tempPath;
  59      }
  60  
  61      function finished()
  62      {
  63          return VFS_ISOWriter_RealInputStrategy_copy::_removeRecursive($this->_tempPath);
  64      }
  65  
  66      function _removeRecursive($path)
  67      {
  68          $dh = @opendir($path);
  69          if (!is_resource($dh)) {
  70              return PEAR::raiseError(sprintf(_("Could not open directory \"%s\"."),
  71                                              $path));
  72          }
  73          while (($ent = readdir($dh)) !== false) {
  74              if ($ent == '.' || $ent == '..') {
  75                  continue;
  76              }
  77  
  78              $full = sprintf('%s/%s', $path, $ent);
  79              if (is_dir($full)) {
  80                  $res = VFS_ISOWriter_RealInputStrategy_copy::_removeRecursive($full);
  81                  if (is_a($res, 'PEAR_Error')) {
  82                      return $res;
  83                  }
  84              } else {
  85                  if (!@unlink($full)) {
  86                      return PEAR::raiseError(sprintf(_("Could not unlink \"%s\"."),
  87                                                      $full));
  88                  }
  89              }
  90          }
  91          closedir($dh);
  92  
  93          if (!@rmdir($path)) {
  94              return PEAR::raiseError(sprintf(_("Could not rmdir \"%s\"."), $full));
  95          }
  96      }
  97  
  98      function _copyToTempPath()
  99      {
 100          $dirStack = array('');
 101  
 102          while (count($dirStack) > 0) {
 103              $dir = array_shift($dirStack);
 104              if (empty($dir)) {
 105                  $target = $this->_tempPath;
 106              } else {
 107                  $target = sprintf('%s/%s', $this->_tempPath, $dir);
 108              }
 109              if (!@mkdir($target)) {
 110                  return PEAR::raiseError(sprintf(_("Could not mkdir \"%s\"."), $target));
 111              }
 112  
 113              $sourcePath = $this->_sourceRoot;
 114              if (!empty($dir)) {
 115                  $sourcePath .= '/' . $dir;
 116              }
 117  
 118              $list = $this->_sourceVfs->listFolder($sourcePath, null, true);
 119              if (is_a($list, 'PEAR_Error')) {
 120                  return $list;
 121              }
 122  
 123              foreach ($list as $entry) {
 124                  if ($entry['type'] == '**dir') {
 125                      if (empty($dir)) {
 126                          $dirStack[] = $entry['name'];
 127                      } else {
 128                          $dirStack[] = sprintf('%s/%s', $dir, $entry['name']);
 129                      }
 130                  } else {
 131                      $data = $this->_sourceVfs->read($sourcePath, $entry['name']);
 132                      if (is_a($data, 'PEAR_Error')) {
 133                          return $data;
 134                      }
 135  
 136                      $targetFile = sprintf('%s/%s', $target, $entry['name']);
 137                      $fh = @fopen($targetFile, 'w');
 138                      if (!is_resource($fh)) {
 139                          return PEAR::raiseError(sprintf(_("Could not open \"%s\" for writing."), $targetFile));
 140                      }
 141                      if (fwrite($fh, $data) != strlen($data)) {
 142                          return PEAR::raiseError(sprintf(_("Error writing \"%s\"."), $targetFile));
 143                      }
 144                      fclose($fh);
 145                  }
 146              }
 147          }
 148      }
 149  
 150  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7