/** * Traverse over the files and subdirectories * * @global MongoCollection $collection The MongoDB collection * @global Array $CONFIG The configuration parameters * @param DirectoryIterator $iterator The DirectoryIterator to iterate over * @return void */ function traverse($iterator) { global $collection, $CONFIG; foreach ($iterator as $fileinfo) { $file = $fileinfo->getPathname(); if ($fileinfo->isDot()) { continue; } elseif ($fileinfo->isDir()) { traverse(new DirectoryIterator($file)); } $attributes = xattr_list($file); $stored_props = array(); if (!$fileinfo->isDir()) { $encodedKey = str_replace(array('%', '$', '.'), array('%25', '%24', '%2E'), DAV::PROP_GETCONTENTLENGTH); $stored_props[$encodedKey] = $fileinfo->getSize(); } foreach ($attributes as $attribute) { $decodedKey = rawurldecode($attribute); $value = xattr_get($file, $attribute); // Transform the value of the owner and sponsor properties (but only if necessary) if (($decodedKey === 'DAV: owner' || $decodedKey === 'http://beehub.nl/ sponsor') && substr($value, 0, 1) === '/') { $value = rawurldecode(basename($value)); } // Property names are already stored url encoded in extended attributes, but we just need it a few characters to be encoded. // This url encodes only the characters needed to create valid mongoDB keys. You can just run rawurldecode to decode it. $encodedKey = str_replace(array('%', '$', '.'), array('%25', '%24', '%2E'), $decodedKey); $stored_props[$encodedKey] = mb_convert_encoding($value, 'UTF-8'); } $unslashifiedPath = \DAV::unslashify(substr($file, strlen($CONFIG['environment']['datadir']))); if (substr($unslashifiedPath, 0, 1) === '/') { $unslashifiedPath = substr($unslashifiedPath, 1); } if ($unslashifiedPath === '') { $depth = 0; } else { $depth = substr_count($unslashifiedPath, '/') + 1; } $document = array('path' => mb_convert_encoding($unslashifiedPath, 'UTF-8'), 'depth' => $depth, 'props' => $stored_props); if ($fileinfo->isDir()) { $document['collection'] = true; } $collection->save($document); } }
/** * Get a cache element using xattr * * @param string $name Name for cache element * @param int $time * * @return mixed */ private function getXattr($name, $time) { $cacheFile = $name . ".cache"; if (file_exists($cacheFile)) { $expire = xattr_get($cacheFile, "EXPIRE", XATTR_DONTFOLLOW); if ($expire === false) { $this->raiseError("Error reading cache ttl (File) (XATTR), exiting gracefully", pathinfo($cacheFile)); $this->setErrorState(); $return = null; } else { if ($expire < $time) { $return = null; } else { $data = file_get_contents($cacheFile); if ($data === false) { $this->raiseError("Error reading cache content (File), exiting gracefully", pathinfo($cacheFile)); $this->setErrorState(); $return = null; } else { $return = $data; } } } } else { $return = null; } return $return; }
/** * ArrayAccess; Check if attribute exists. * * @param string $att Attribute name * @return boolean */ public function offsetExists($att) { return in_array($att, array('size', 'type', 'atime', 'ctime', 'mtime', 'mode', 'perms', 'uid', 'owner', 'gid', 'group', 'dev', 'ino', 'nlink', 'rdev', 'blksize', 'blocks')) || extension_loaded('xattr') && xattr_supported($this->_path) && xattr_get($this->_path, $att) !== false; }
/** * @abstract * @param AJXP_Node $ajxpNode * @param String $nameSpace * @param bool|String $private * @param int $scope * @return array() */ public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope = AJXP_METADATA_SCOPE_REPOSITORY) { $path = $ajxpNode->getRealFile(); if (!file_exists($path)) { return array(); } if (!xattr_supported($path)) { //throw new Exception("Filesystem does not support Extended Attributes!"); return array(); } if ($private == AJXP_METADATA_ALLUSERS) { $startKey = $this->getMetaKey($nameSpace, $scope, ""); $arrMeta = array(); $keyList = xattr_list($path); foreach ($keyList as $k) { if (strpos($k, $startKey) === 0) { $mData = xattr_get($path, $k); $decData = unserialize(base64_decode($mData)); if (is_array($decData)) { $arrMeta = array_merge_recursive($arrMeta, $decData); } } } return $arrMeta; } else { $key = $this->getMetaKey($nameSpace, $scope, $this->getUserId($private, $ajxpNode)); $data = xattr_get($path, $key); $data = unserialize(base64_decode($data)); if (empty($data) || !is_array($data)) { return array(); } return $data; } }
/** * @abstract * @param AJXP_Node $ajxpNode * @param String $nameSpace * @param bool $private * @param int $scope */ public function retrieveMetadata($ajxpNode, $nameSpace, $private = false, $scope = AJXP_METADATA_SCOPE_REPOSITORY) { $path = $ajxpNode->getRealFile(); if (!file_exists($path)) { return array(); } $key = $this->getMetaKey($nameSpace, $scope, $this->getUserId($private)); if (!xattr_supported($path)) { //throw new Exception("Filesystem does not support Extended Attributes!"); return array(); } $data = xattr_get($path, $key); $data = unserialize(base64_decode($data)); if (empty($data) || !is_array($data)) { return array(); } return $data; }