本文整理汇总了PHP中OC\Files\Filesystem::normalizePath方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::normalizePath方法的具体用法?PHP Filesystem::normalizePath怎么用?PHP Filesystem::normalizePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::normalizePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateTarget
/**
* create unique target
* @param string $filePath
* @param string $shareWith
* @param string $exclude
* @return string
*/
public function generateTarget($filePath, $shareWith, $exclude = null)
{
$shareFolder = \OCA\Files_Sharing\Helper::getShareFolder();
$target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath));
// for group shares we return the target right away
if ($shareWith === false) {
return $target;
}
\OC\Files\Filesystem::initMountPoints($shareWith);
$view = new \OC\Files\View('/' . $shareWith . '/files');
if (!$view->is_dir($shareFolder)) {
$dir = '';
$subdirs = explode('/', $shareFolder);
foreach ($subdirs as $subdir) {
$dir = $dir . '/' . $subdir;
if (!$view->is_dir($dir)) {
$view->mkdir($dir);
}
}
}
$excludeList = \OCP\Share::getItemsSharedWithUser('file', $shareWith, self::FORMAT_TARGET_NAMES);
if (is_array($exclude)) {
$excludeList = array_merge($excludeList, $exclude);
}
return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view);
}
示例2: rename
/**
* rename a file
*
* @param string $dir
* @param string $oldname
* @param string $newname
* @return array
*/
public function rename($dir, $oldname, $newname)
{
$result = array('success' => false, 'data' => NULL);
$normalizedOldPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $oldname);
$normalizedNewPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
// rename to non-existing folder is denied
if (!$this->view->file_exists($normalizedOldPath)) {
$result['data'] = array('message' => $this->l10n->t('%s could not be renamed as it has been deleted', array($oldname)), 'code' => 'sourcenotfound', 'oldname' => $oldname, 'newname' => $newname);
} else {
if (!$this->view->file_exists($dir)) {
$result['data'] = array('message' => (string) $this->l10n->t('The target folder has been moved or deleted.', array($dir)), 'code' => 'targetnotfound');
// rename to existing file is denied
} else {
if ($this->view->file_exists($normalizedNewPath)) {
$result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir)));
} else {
if ($newname !== '.' and $this->view->rename($normalizedOldPath, $normalizedNewPath)) {
// successful rename
$meta = $this->view->getFileInfo($normalizedNewPath);
$meta = \OCA\Files\Helper::populateTags(array($meta));
$fileInfo = \OCA\Files\Helper::formatFileInfo(current($meta));
$fileInfo['path'] = dirname($normalizedNewPath);
$result['success'] = true;
$result['data'] = $fileInfo;
} else {
// rename failed
$result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname)));
}
}
}
}
return $result;
}
示例3: postRestore
/**
* inform encryption module that a file was restored from the trash bin,
* e.g. to update the encryption keys
*
* @param array $params
*/
public function postRestore($params)
{
if ($this->encryptionManager->isEnabled()) {
$path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
$this->update($path);
}
}
示例4: unlink
/**
* Deletes the given file by moving it into the trashbin.
*
* @param string $path
*/
public function unlink($path)
{
if (self::$disableTrash) {
return $this->storage->unlink($path);
}
$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
$result = true;
if (!isset($this->deletedFiles[$normalized])) {
$view = Filesystem::getView();
$this->deletedFiles[$normalized] = $normalized;
if ($filesPath = $view->getRelativePath($normalized)) {
$filesPath = trim($filesPath, '/');
$result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath);
// in cross-storage cases the file will be copied
// but not deleted, so we delete it here
if ($result) {
$this->storage->unlink($path);
}
} else {
$result = $this->storage->unlink($path);
}
unset($this->deletedFiles[$normalized]);
} else {
if ($this->storage->file_exists($path)) {
$result = $this->storage->unlink($path);
}
}
return $result;
}
示例5: propagateChanges
/**
* propagate the registered changes to their parent folders
*
* @param int $time (optional) the mtime to set for the folders, if not set the current time is used
*/
public function propagateChanges($time = null)
{
$changes = $this->getChanges();
$this->changedFiles = [];
if (!$time) {
$time = time();
}
foreach ($changes as $change) {
/**
* @var \OC\Files\Storage\Storage $storage
* @var string $internalPath
*/
$absolutePath = $this->view->getAbsolutePath($change);
$mount = $this->view->getMount($change);
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($absolutePath);
if ($storage) {
$propagator = $storage->getPropagator();
$propagatedEntries = $propagator->propagateChange($internalPath, $time);
foreach ($propagatedEntries as $entry) {
$absolutePath = Filesystem::normalizePath($mount->getMountPoint() . '/' . $entry['path']);
$relativePath = $this->view->getRelativePath($absolutePath);
$this->emit('\\OC\\Files', 'propagate', [$relativePath, $entry]);
}
}
}
}
示例6: checkScanWarning
public function checkScanWarning($fullPath, OutputInterface $output)
{
$normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath));
$path = basename($fullPath);
if ($normalizedPath !== $path) {
$output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>');
}
}
示例7: get
/**
* @brief list bookshelf contents
*
* @return array of FileInfo[], sorted by time added
*/
public static function get()
{
$files = array();
if ($bookshelf = json_decode(Config::get('bookshelf', ''), true)) {
arsort($bookshelf);
while (list($id, $time) = each($bookshelf)) {
array_push($files, \OC\Files\Filesystem::getFileInfo(\OC\Files\Filesystem::normalizePath(\OC\Files\Filesystem::getPath($id))));
}
}
return $files;
}
示例8: propagateForOwner
/**
* @param array $share
* @param string $internalPath
* @param \OC\Files\Cache\ChangePropagator $propagator
*/
private function propagateForOwner($share, $internalPath, ChangePropagator $propagator)
{
// note that we have already set up the filesystem for the owner when mounting the share
$view = new View('/' . $share['uid_owner'] . '/files');
$shareRootPath = $view->getPath($share['item_source']);
if (!is_null($shareRootPath)) {
$path = $shareRootPath . '/' . $internalPath;
$path = Filesystem::normalizePath($path);
$propagator->addChange($path);
$propagator->propagateChanges();
}
}
示例9: renameChildren
/**
* rename mount point from the children if the parent was renamed
*
* @param string $oldPath old path relative to data/user/files
* @param string $newPath new path relative to data/user/files
*/
private static function renameChildren($oldPath, $newPath)
{
$absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath);
$absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath);
$mountManager = \OC\Files\Filesystem::getMountManager();
$mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath);
foreach ($mountedShares as $mount) {
if ($mount->getStorage()->instanceOfStorage('OCA\\Files_Sharing\\ISharedStorage')) {
$mountPoint = $mount->getMountPoint();
$target = str_replace($absOldPath, $absNewPath, $mountPoint);
$mount->moveMount($target);
}
}
}
示例10: releaseLock
/**
* Release an existing lock
* @param string $path Path to file, relative to this storage
* @param integer $lockType The type of lock to release
* @param bool $releaseAll If true, release all outstanding locks
* @return bool true on success, false on failure
*/
protected function releaseLock($path, $lockType, $releaseAll = false)
{
$path = Filesystem::normalizePath($this->storage->getLocalFile($path));
if (is_dir($path)) {
return false;
}
if (isset($this->locks[$path])) {
if ($releaseAll) {
return $this->locks[$path]->releaseAll();
} else {
return $this->locks[$path]->release($lockType);
}
}
return true;
}
示例11: verifyMountPoint
/**
* check if the parent folder exists otherwise move the mount point up
*/
private function verifyMountPoint(&$share, $user)
{
$mountPoint = basename($share['file_target']);
$parent = dirname($share['file_target']);
if (!\OC\Files\Filesystem::is_dir($parent)) {
$parent = Helper::getShareFolder();
}
$newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), array(), new \OC\Files\View('/' . $user . '/files'));
if ($newMountPoint !== $share['file_target']) {
self::updateFileTarget($newMountPoint, $share);
$share['file_target'] = $newMountPoint;
$share['unique_name'] = true;
}
return $newMountPoint;
}
示例12: addShare
public function addShare($remote, $token, $password, $name, $owner)
{
if ($this->uid) {
$query = $this->connection->prepare('
INSERT INTO `*PREFIX*share_external`
(`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
');
$mountPoint = Filesystem::normalizePath('/' . $name);
$hash = md5($mountPoint);
$query->execute(array($remote, $token, $password, $name, $owner, $this->uid, $mountPoint, $hash));
$options = array('remote' => $remote, 'token' => $token, 'password' => $password, 'mountpoint' => $mountPoint, 'owner' => $owner);
return $this->mountShare($options);
}
}
示例13: verifyMountPoint
/**
* check if the parent folder exists otherwise move the mount point up
*
* @param array $share
* @return string
*/
private function verifyMountPoint(&$share)
{
$mountPoint = basename($share['file_target']);
$parent = dirname($share['file_target']);
if (!$this->recipientView->is_dir($parent)) {
$parent = Helper::getShareFolder();
}
$newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), [], $this->recipientView);
if ($newMountPoint !== $share['file_target']) {
$this->updateFileTarget($newMountPoint, $share);
$share['file_target'] = $newMountPoint;
$share['unique_name'] = true;
}
return $newMountPoint;
}
示例14: addShare
public function addShare($remote, $token, $password, $name, $owner, $accepted = false, $user = null, $remoteId = -1)
{
$user = $user ? $user : $this->userSession->getUser()->getUID();
$accepted = $accepted ? 1 : 0;
$mountPoint = Filesystem::normalizePath('/' . $name);
$query = $this->connection->prepare('
INSERT INTO `*PREFIX*share_external`
(`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
');
$hash = md5($mountPoint);
$query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId));
if ($accepted) {
$options = array('remote' => $remote, 'token' => $token, 'password' => $password, 'mountpoint' => $mountPoint, 'owner' => $owner);
return $this->mountShare($options);
}
}
示例15: attachListener
/**
* attach listeners to the scanner
*
* @param \OC\Files\Mount\MountPoint $mount
*/
protected function attachListener($mount)
{
$scanner = $mount->getStorage()->getScanner();
$emitter = $this;
$scanner->listen('\\OC\\Files\\Cache\\Scanner', 'scanFile', function ($path) use($mount, $emitter) {
$emitter->emit('\\OC\\Files\\Utils\\Scanner', 'scanFile', array($mount->getMountPoint() . $path));
});
$scanner->listen('\\OC\\Files\\Cache\\Scanner', 'scanFolder', function ($path) use($mount, $emitter) {
$emitter->emit('\\OC\\Files\\Utils\\Scanner', 'scanFolder', array($mount->getMountPoint() . $path));
});
// propagate etag and mtimes when files are changed or removed
$propagator = $this->propagator;
$propagatorListener = function ($path) use($mount, $propagator) {
$fullPath = Filesystem::normalizePath($mount->getMountPoint() . $path);
$propagator->addChange($fullPath);
};
$scanner->listen('\\OC\\Files\\Cache\\Scanner', 'addToCache', $propagatorListener);
$scanner->listen('\\OC\\Files\\Cache\\Scanner', 'removeFromCache', $propagatorListener);
}