本文整理汇总了PHP中OC\Files\Filesystem::isIgnoredDir方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::isIgnoredDir方法的具体用法?PHP Filesystem::isIgnoredDir怎么用?PHP Filesystem::isIgnoredDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::isIgnoredDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTrashFiles
/**
* Retrieves the contents of a trash bin directory.
*
* @param string $dir path to the directory inside the trashbin
* or empty to retrieve the root of the trashbin
* @param string $user
* @param string $sortAttribute attribute to sort on or empty to disable sorting
* @param bool $sortDescending true for descending sort, false otherwise
* @return \OCP\Files\FileInfo[]
*/
public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false)
{
$result = array();
$timestamp = null;
$view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
throw new \Exception('Directory does not exists');
}
$dirContent = $view->opendir($dir);
if ($dirContent === false) {
return $result;
}
$mount = $view->getMount($dir);
$storage = $mount->getStorage();
$absoluteDir = $view->getAbsolutePath($dir);
$internalPath = $mount->getInternalPath($absoluteDir);
if (is_resource($dirContent)) {
$originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
while (($entryName = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
$id = $entryName;
if ($dir === '' || $dir === '/') {
$size = $view->filesize($id);
$pathparts = pathinfo($entryName);
$timestamp = substr($pathparts['extension'], 1);
$id = $pathparts['filename'];
} else {
if ($timestamp === null) {
// for subfolders we need to calculate the timestamp only once
$size = $view->filesize($dir . '/' . $id);
$parts = explode('/', ltrim($dir, '/'));
$timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
}
}
$originalPath = '';
if (isset($originalLocations[$id][$timestamp])) {
$originalPath = $originalLocations[$id][$timestamp];
if (substr($originalPath, -1) === '/') {
$originalPath = substr($originalPath, 0, -1);
}
}
$i = array('name' => $id, 'mtime' => $timestamp, 'mimetype' => $view->is_dir($dir . '/' . $entryName) ? 'httpd/unix-directory' : \OC_Helper::getFileNameMimeType($id), 'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file', 'directory' => $dir === '/' ? '' : $dir, 'size' => $size);
if ($originalPath) {
$i['extraData'] = $originalPath . '/' . $id;
}
$result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
}
}
closedir($dirContent);
}
if ($sortAttribute !== '') {
return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
}
return $result;
}
示例2: getTrashFiles
/**
* Retrieves the contents of a trash bin directory.
* @param string $dir path to the directory inside the trashbin
* or empty to retrieve the root of the trashbin
* @return array of files
*/
public static function getTrashFiles($dir)
{
$result = array();
$user = \OCP\User::getUser();
if ($dir && $dir !== '/') {
$view = new \OC_Filesystemview('/' . $user . '/files_trashbin/files');
$dirContent = $view->opendir($dir);
if ($dirContent === false) {
return null;
}
if (is_resource($dirContent)) {
while (($entryName = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
$pos = strpos($dir . '/', '/', 1);
$tmp = substr($dir, 0, $pos);
$pos = strrpos($tmp, '.d');
$timestamp = substr($tmp, $pos + 2);
$result[] = array('id' => $entryName, 'timestamp' => $timestamp, 'mime' => $view->getMimeType($dir . '/' . $entryName), 'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file', 'location' => $dir);
}
}
closedir($dirContent);
}
} else {
$query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?');
$result = $query->execute(array($user))->fetchAll();
}
$files = array();
$id = 0;
foreach ($result as $r) {
$i = array();
$i['id'] = $id++;
$i['name'] = $r['id'];
$i['date'] = \OCP\Util::formatDate($r['timestamp']);
$i['timestamp'] = $r['timestamp'];
$i['etag'] = $i['timestamp'];
// dummy etag
$i['mimetype'] = $r['mime'];
$i['type'] = $r['type'];
if ($i['type'] === 'file') {
$fileinfo = pathinfo($r['id']);
$i['basename'] = $fileinfo['filename'];
$i['extension'] = isset($fileinfo['extension']) ? '.' . $fileinfo['extension'] : '';
}
$i['directory'] = $r['location'];
if ($i['directory'] === '/') {
$i['directory'] = '';
}
$i['permissions'] = \OCP\PERMISSION_READ;
$i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($r['mime']);
$i['icon'] = \OCA\Files\Helper::determineIcon($i);
$files[] = $i;
}
usort($files, array('\\OCA\\Files\\Helper', 'fileCmp'));
return $files;
}
示例3: tearDown
public function tearDown()
{
// test that nothing outside our jail is touched
$contents = array();
$dh = $this->sourceStorage->opendir('');
while ($file = readdir($dh)) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
$contents[] = $file;
}
}
$this->assertEquals(array('foo'), $contents);
$this->sourceStorage->cleanUp();
parent::tearDown();
}
示例4: copyRecursive
/**
* For adapters that dont support copying folders natively
*
* @param $source
* @param $target
* @return bool
*/
protected function copyRecursive($source, $target)
{
$dh = $this->opendir($source);
$result = true;
while ($file = readdir($dh)) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if ($this->is_dir($source . '/' . $file)) {
$this->mkdir($target . '/' . $file);
$result = $this->copyRecursive($source . '/' . $file, $target . '/' . $file);
} else {
$result = parent::copy($source . '/' . $file, $target . '/' . $file);
}
if (!$result) {
break;
}
}
}
return $result;
}
示例5: scanChildren
/**
* scan all the files and folders in a folder
*
* @param string $path
* @param bool $recursive
* @param int $reuse
* @return int the size of the scanned folder or -1 if the size is unknown at this stage
*/
public function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1)
{
if ($reuse === -1) {
$reuse = $recursive === self::SCAN_SHALLOW ? self::REUSE_ETAG | self::REUSE_SIZE : 0;
}
$this->emit('\\OC\\Files\\Cache\\Scanner', 'scanFolder', array($path, $this->storageId));
$size = 0;
$childQueue = array();
$existingChildren = array();
if ($this->cache->inCache($path)) {
$children = $this->cache->getFolderContents($path);
foreach ($children as $child) {
$existingChildren[] = $child['name'];
}
}
$newChildren = array();
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
$exceptionOccurred = false;
\OC_DB::beginTransaction();
if (is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
$child = $path ? $path . '/' . $file : $file;
if (!Filesystem::isIgnoredDir($file)) {
$newChildren[] = $file;
try {
$data = $this->scanFile($child, $reuse, true);
if ($data) {
if ($data['size'] === -1) {
if ($recursive === self::SCAN_RECURSIVE) {
$childQueue[] = $child;
} else {
$size = -1;
}
} else {
if ($size !== -1) {
$size += $data['size'];
}
}
}
} catch (\Doctrine\DBAL\DBALException $ex) {
// might happen if inserting duplicate while a scanning
// process is running in parallel
// log and ignore
\OC_Log::write('core', 'Exception while scanning file "' . $child . '": ' . $ex->getMessage(), \OC_Log::DEBUG);
$exceptionOccurred = true;
}
}
}
}
$removedChildren = \array_diff($existingChildren, $newChildren);
foreach ($removedChildren as $childName) {
$child = $path ? $path . '/' . $childName : $childName;
$this->cache->remove($child);
}
\OC_DB::commit();
if ($exceptionOccurred) {
// It might happen that the parallel scan process has already
// inserted mimetypes but those weren't available yet inside the transaction
// To make sure to have the updated mime types in such cases,
// we reload them here
$this->cache->loadMimetypes();
}
foreach ($childQueue as $child) {
$childSize = $this->scanChildren($child, self::SCAN_RECURSIVE, $reuse);
if ($childSize === -1) {
$size = -1;
} else {
$size += $childSize;
}
}
$this->cache->put($path, array('size' => $size));
}
$this->emit('\\OC\\Files\\Cache\\Scanner', 'postScanFolder', array($path, $this->storageId));
return $size;
}
示例6: copyr
/**
* copies a directory recursively
*
* @param string $source
* @param string $target
* @return void
*/
public static function copyr($source, $target)
{
$dir = opendir($source);
@mkdir($target);
while (false !== ($file = readdir($dir))) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if (is_dir($source . '/' . $file)) {
OC_Util::copyr($source . '/' . $file, $target . '/' . $file);
} else {
copy($source . '/' . $file, $target . '/' . $file);
}
}
}
closedir($dir);
}
示例7: copyr
/**
* copies a directory recursively by using streams
*
* @param string $source
* @param \OCP\Files\Folder $target
* @return void
*/
public static function copyr($source, \OCP\Files\Folder $target) {
$dir = opendir($source);
while (false !== ($file = readdir($dir))) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if (is_dir($source . '/' . $file)) {
$child = $target->newFolder($file);
self::copyr($source . '/' . $file, $child);
} else {
$child = $target->newFile($file);
stream_copy_to_stream(fopen($source . '/' . $file,'r'), $child->fopen('w'));
}
}
}
closedir($dir);
}
示例8: verifyPath
/**
* @param string $path
* @param string $fileName
* @throws InvalidPathException
*/
public function verifyPath($path, $fileName)
{
$l10n = \OC::$server->getL10N('lib');
// verify empty and dot files
$trimmed = trim($fileName);
if ($trimmed === '') {
throw new InvalidPathException($l10n->t('Empty filename is not allowed'));
}
if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
throw new InvalidPathException($l10n->t('Dot files are not allowed'));
}
// verify database - e.g. mysql only 3-byte chars
if (preg_match('%(?:
\\xF0[\\x90-\\xBF][\\x80-\\xBF]{2} # planes 1-3
| [\\xF1-\\xF3][\\x80-\\xBF]{3} # planes 4-15
| \\xF4[\\x80-\\x8F][\\x80-\\xBF]{2} # plane 16
)%xs', $fileName)) {
throw new InvalidPathException($l10n->t('4-byte characters are not supported in file names'));
}
try {
/** @type \OCP\Files\Storage $storage */
list($storage, $internalPath) = $this->resolvePath($path);
$storage->verifyPath($internalPath, $fileName);
} catch (ReservedWordException $ex) {
throw new InvalidPathException($l10n->t('File name is a reserved word'));
} catch (InvalidCharacterInPathException $ex) {
throw new InvalidPathException($l10n->t('File name contains at least one invalid character'));
} catch (FileNameTooLongException $ex) {
throw new InvalidPathException($l10n->t('File name is too long'));
}
}
示例9: copyFromStorage
/**
* @param \OCP\Files\Storage $sourceStorage
* @param string $sourceInternalPath
* @param string $targetInternalPath
* @param bool $preserveMtime
* @return bool
*/
public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false)
{
if ($sourceStorage === $this) {
return $this->copy($sourceInternalPath, $targetInternalPath);
}
if ($sourceStorage->is_dir($sourceInternalPath)) {
$dh = $sourceStorage->opendir($sourceInternalPath);
$result = $this->mkdir($targetInternalPath);
if (is_resource($dh)) {
while ($result and ($file = readdir($dh)) !== false) {
if (!Filesystem::isIgnoredDir($file)) {
$result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file);
}
}
}
} else {
$source = $sourceStorage->fopen($sourceInternalPath, 'r');
// TODO: call fopen in a way that we execute again all storage wrappers
// to avoid that we bypass storage wrappers which perform important actions
// for this operation. Same is true for all other operations which
// are not the same as the original one.Once this is fixed we also
// need to adjust the encryption wrapper.
$target = $this->fopen($targetInternalPath, 'w');
list(, $result) = \OC_Helper::streamCopy($source, $target);
if ($result and $preserveMtime) {
$this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
}
fclose($source);
fclose($target);
if (!$result) {
// delete partially written target file
$this->unlink($targetInternalPath);
// delete cache entry that was created by fopen
$this->getCache()->remove($targetInternalPath);
}
}
return (bool) $result;
}
示例10: copy
public function copy($path1, $path2)
{
if ($this->is_dir($path1)) {
$this->remove($path2);
$dir = $this->opendir($path1);
$this->mkdir($path2);
while ($file = readdir($dir)) {
if (!Filesystem::isIgnoredDir($file)) {
if (!$this->copy($path1 . '/' . $file, $path2 . '/' . $file)) {
return false;
}
}
}
closedir($dir);
return true;
} else {
$source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w');
list(, $result) = \OC_Helper::streamCopy($source, $target);
$this->removeCachedFile($path2);
return $result;
}
}
示例11: searchInDir
/**
* @param string $query
* @param string $dir
* @return array
*/
protected function searchInDir($query, $dir = '')
{
$files = array();
$physicalDir = $this->getSourcePath($dir);
foreach (scandir($physicalDir) as $item) {
if (\OC\Files\Filesystem::isIgnoredDir($item)) {
continue;
}
$physicalItem = $physicalDir . '/' . $item;
if (strstr(strtolower($item), strtolower($query)) !== false) {
$files[] = $dir . '/' . $item;
}
if (is_dir($physicalItem)) {
$files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item));
}
}
return $files;
}
示例12: recursiveDelShareKeys
/**
* recursively delete share keys from given users
*
* @param string $dir directory
* @param array $userIds user ids for which the share keys should be deleted
* @param \OC\Files\View $view view relative to data/
*/
private static function recursiveDelShareKeys($dir, $userIds, $view)
{
$dirContent = $view->opendir($dir);
if (is_resource($dirContent)) {
while (($file = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if ($view->is_dir($dir . '/' . $file)) {
self::recursiveDelShareKeys($dir . '/' . $file, $userIds, $view);
} else {
foreach ($userIds as $userId) {
if ($userId . '.shareKey' === $file) {
\OCP\Util::writeLog('files_encryption', 'recursiveDelShareKey: delete share key: ' . $file, \OCP\Util::DEBUG);
self::deleteKey($view, $dir . '/' . $file);
}
}
}
}
}
closedir($dirContent);
}
}
示例13: cleanTmpNoClean
/**
* remove all files in PHP /oc-noclean temp dir
*/
public static function cleanTmpNoClean()
{
$tmpDirNoCleanName = get_temp_dir() . '/oc-noclean/';
if (file_exists($tmpDirNoCleanName) && is_dir($tmpDirNoCleanName)) {
$files = scandir($tmpDirNoCleanName);
foreach ($files as $file) {
$fileName = $tmpDirNoCleanName . $file;
if (!\OC\Files\Filesystem::isIgnoredDir($file) && filemtime($fileName) + 600 < time()) {
unlink($fileName);
}
}
// if oc-noclean is empty delete it
$isTmpDirNoCleanEmpty = true;
$tmpDirNoClean = opendir($tmpDirNoCleanName);
if (is_resource($tmpDirNoClean)) {
while (false !== ($file = readdir($tmpDirNoClean))) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
$isTmpDirNoCleanEmpty = false;
}
}
}
if ($isTmpDirNoCleanEmpty) {
rmdir($tmpDirNoCleanName);
}
}
}
示例14: findShareKeys
/**
* find all share keys for a given file
* @param string $path to the file
* @param \OC\Files\View $view view, relative to data/
* @return array list of files, path relative to data/
*/
public static function findShareKeys($path, $view)
{
$result = array();
$pathinfo = pathinfo($path);
$dirContent = $view->opendir($pathinfo['dirname']);
if (is_resource($dirContent)) {
while (($file = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if (preg_match("/" . $pathinfo['filename'] . ".(.*).shareKey/", $file)) {
$result[] = $pathinfo['dirname'] . '/' . $file;
}
}
}
closedir($dirContent);
}
return $result;
}
示例15: deleteAll
/**
* @brief Deletes all files and folders recursively within a directory
* @param string $directory The directory whose contents will be deleted
* @param bool $empty Flag indicating whether directory will be emptied
* @returns bool
*
* @note By default the directory specified by $directory will be
* deleted together with its contents. To avoid this set $empty to true
*/
public function deleteAll($directory, $empty = false)
{
$directory = trim($directory, '/');
if (!$this->is_dir($directory) || !$this->isReadable($directory)) {
return false;
} else {
$directoryHandle = $this->opendir($directory);
if (is_resource($directoryHandle)) {
while (($contents = readdir($directoryHandle)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
$path = $directory . '/' . $contents;
if ($this->is_dir($path)) {
$this->deleteAll($path);
} else {
$this->unlink($path);
}
}
}
}
if ($empty === false) {
if (!$this->rmdir($directory)) {
return false;
}
}
return true;
}
}