/** * streamWrapper::rename — Renames a file or directory * * @param string $path_from The URL to the current file. * @param string $path_to The URL which the $path_from should be renamed to. * @return boolean Returns TRUE on success or FALSE on failure. */ public function rename($path_from, $path_to) { try { $pathFrom = $this->getPath($path_from); if ($pathFrom->getRef() != 'HEAD') { throw new \Exception(sprintf('Cannot rename a non-HEAD file [%s#%s]', $pathFrom->getFullPath(), $pathFrom->getRef())); } if (!file_exists($pathFrom->getFullPath())) { throw new \Exception(sprintf('Path %s not found', $pathFrom->getFullPath())); } if (!is_file($pathFrom->getFullPath())) { throw new \Exception(sprintf('Path %s is not a file', $pathFrom->getFullPath())); } $pathTo = PathInformation::parseUrl($path_to, self::$protocol); $pathTo = $pathTo['path']; if (strpos($pathTo, $pathFrom->getRepositoryPath()) !== 0) { throw new \Exception(sprintf('Cannot rename across repositories [%s -> %s]', $pathFrom->getFullPath(), $pathTo)); } $repo = $pathFrom->getRepository(); $commitMsg = $this->getContextOption('commitMsg', null); $author = $this->getContextOption('author', null); $repo->renameFile($pathFrom->getLocalPath(), $pathTo, $commitMsg, false, $author); return true; } catch (\Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); return false; } }