Exemplo n.º 1
0
 /**
  * Copy a file.
  *
  * @param File $src Source path and name file to copy.
  * @param File $dest Destination path and name of new file.
  *
  * @return void
  * @throws Exception if file cannot be copied.
  */
 public function copy(File $src, File $dest)
 {
     global $php_errormsg;
     // Recursively copy a directory
     if ($src->isDirectory()) {
         return $this->copyr($src->getAbsolutePath()->toNative(), $dest->getAbsolutePath()->toNative());
     }
     $srcPath = $src->getAbsolutePath()->toNative();
     $destPath = $dest->getAbsolutePath()->toNative();
     if (false === @copy($srcPath, $destPath)) {
         // Copy FAILED. Log and return err.
         // Add error from php to end of log message. $php_errormsg.
         $msg = "FileSystem::copy() FAILED. Cannot copy {$srcPath} to {$destPath}. {$php_errormsg}";
         throw new Exception($msg);
     }
     try {
         $dest->setMode($src->getMode());
     } catch (Exception $exc) {
         // [MA] does chmod returns an error on systems that do not support it ?
         // eat it up for now.
     }
 }