/** * @param IFile $target The target file the link will point to * @param bool $overwrite * @return bool TRUE if the link has been successfully created, FALSE otherwise */ public function createNewLink(IFile $target, $overwrite = false) { if ($this->realFile === null) { throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path); } $this->createNewFile($overwrite); try { $meta = MetaManager::getInstance()->getNewMetaDataInstance($this); if ($meta !== null) { $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $group = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosGroup(); $meta->set(self::METADATA_KEY_LINKTARGET, $target->getAbsolutePath()); $meta->set(self::METADATA_KEY_OWNER, $currentUser->getName()); $meta->set(self::METADATA_KEY_GROUP, $group->getName()); $meta->set(self::METADATA_KEY_CREATIONTIME, time()); $meta->set(self::METADATA_KEY_MODIFICATIONTIME, time()); $meta->set(self::METADATA_KEY_PERMISSIONS, AdvancedPathLib::permsToUnix(self::PERMISSIONS_VALUE_LINK)); $this->setMeta($meta); } //notify listeners $this->fireEvent('fileCreated', new FileEvent($this)); return true; } catch (EyeException $e) { $this->deleteImpl(); throw new EyeIOException('Unable to create new link ' . $this->path, 0, $e); } }
/** * TODO: a good algorithm with a stack would be much better here... * * @param IFile $root * @param IFile $leaf * @param int $depth * @return mixed An array of serialized IFiles (see self::toArray), * or FALSE if the maximum depth has been reached. */ private static function getFilesAsTree_private(IFile $root, IFile $leaf = null, $depth) { if ($depth < 0) { if ($leaf === null || stripos($leaf->getAbsolutePath(), $root->getAbsolutePath()) !== 0) { //We're not in the branch leading to the specified leaf: stop recursion here return false; } } $folders = array(); foreach ($root->listFiles('*', AdvancedPathLib::GLOB_ONLY_DIR) as $folder) { try { $subFolders = self::getFilesAsTree_private($folder, $leaf, $depth - 1); } catch (Exception $e) { $subFolders = array(self::toArray(false)); } $folder = self::toArray($folder); $folder['subFolders'] = $subFolders; $folders[] = $folder; } return $folders; }