/** * * Copies $srcDir into $dstDirectory across multiple mount points * * @param $srcDir : expects sanitized absolute directory * @param $dstDirectory : expects sanitized absolute directory, if it doesn't exists, create it! * @param array $options : [recursive (true/false) default true, timeout (seconds) default 60, overwriteModus : XAPP_XFILE_OVERWRITE_NONE | XAPP_XFILE_OVERWRITE_ALL | XAPP_XFILE_OVERWRITE_IF_SIZE_DIFFERS * @param array|string $inclusionMask : null means all, if its a string : it must compatible to a scandir query, if its a string its a regular expression * @param array|string $exclusionMask : null means all, otherwise it must compatible to a scandir query,if its a string its a regular expression * @param $error : a pointer to an array reference, please track all errors and don't abort! Check __copyOrMoveFile below how to write the error messages right! * @param $success : track all copied items here */ public function copy($selection, $dst, $options = array(), $inclusionMask = array(), $exclusionMask = array(), &$error, &$success, $mode) { if ($this->isRemoteOperation($selection[0], $dst)) { } $dstDirectory = $this->toRealPath($dst); if (file_exists($dstDirectory) && !is_writable($dstDirectory)) { throw new Xapp_XFile_Exception(XAPP_TEXT_FORMATTED('DIRECTORY_NOT_WRITEABLE', array($dstDirectory), 55100)); } foreach ($selection as $selectedFile) { $itemPath = $this->toRealPath($selectedFile); if (is_dir($itemPath)) { $dstFile = $dstDirectory . DIRECTORY_SEPARATOR . basename($itemPath); XApp_File_Utils::copyDirectory(XApp_Directory_Utils::normalizePath($itemPath, false), XApp_Directory_Utils::normalizePath($dstFile, false), array(XApp_File_Utils::OPTION_RECURSIVE => true, XApp_File_Utils::OPTION_CONFLICT_MODUS => $mode), $inclusionMask, $exclusionMask, $error, $success); } else { if (is_file($itemPath)) { $destFile = $dstDirectory . DIRECTORY_SEPARATOR . basename($itemPath); if (!is_readable($itemPath)) { $error[] = XAPP_TEXT_FORMATTED('CAN_NOT_READ_FILE', array(basename($itemPath))); continue; } // auto rename file if (file_exists($destFile)) { $base = basename($destFile); $ext = ''; $dotPos = strrpos($base, "."); if ($dotPos > -1) { $radic = substr($base, 0, $dotPos); $ext = substr($base, $dotPos); } $i = 1; $newName = $base; while (file_exists($dstDirectory . "/" . $newName)) { $suffix = "-{$i}"; if (isset($radic)) { $newName = $radic . $suffix . $ext; } else { $newName = $base . $suffix; } $i++; } $destFile = $dstDirectory . "/" . $newName; } if (!file_exists($dstDirectory)) { $error[] = XAPP_TEXT_FORMATTED('DIRECTORY_DOES_NOT_EXISTS', array(basename($dstDirectory))); continue; } try { copy($itemPath, $destFile); // Like `cp`, preserve executable permission bits @chmod($destFile, fileperms($destFile) | fileperms($itemPath) & 0111); } catch (Exception $e) { $error[] = $e->getMessage(); return $error; } $success[] = XAPP_TEXT('THE_FILE') . " " . XApp_SystemTextEncoding::toUTF8(basename($itemPath)) . " " . XAPP_TEXT('HAS_BEEN_COPIED') . " " . XApp_SystemTextEncoding::toUTF8($dst); } } } return $error; }