예제 #1
0
/**
 * 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);
    }
}
예제 #2
0
파일: Node.php 프로젝트: jasny/Q
 /**
  * Get a list of extended attributes.
  * @see http://www.php.net/xattr_list
  * 
  * @param int $flags  FS::% and/or XATTR_% options as binary set
  * @return array
  */
 public function getXattributes($flags = 0)
 {
     if (!extension_loaded('xattr') || !xattr_supported($this->_path, $flags)) {
         throw new Fs_Exception("Unable to get attributes of {$this->_path}; Extended attributes are not supported.");
     }
     $file = $flags & Fs::NO_DEREFERENCE ? $this->_path : (string) $this->realpath();
     $attr = @xattr_list($file, $flags);
     if ($attr === false) {
         throw new Fs_Exception("Failed to get extended attributes of '{$this->_path}'", error_get_last());
     }
     return $attr;
 }
예제 #3
0
 /**
  * @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;
     }
 }
예제 #4
0
 /**
  * Get a files extended attributes 
  *
  * @access public
  *
  * @param $path path information
  * @param $retval the returned attributes
  */
 public static function listxattr($path, &$retval)
 {
     $attributes = array();
     Log::in("passthru - listxattr");
     /* If no xattr package installed, say so */
     if (function_exists(xattr_list)) {
         $attributes = xattr_list($path);
     } else {
         $attributes['Message'] = "You do not have the PHP xattr library installed";
         $attributes['Solution'] = "Please install this package for passthru attributes to work";
     }
     $retval = $attributes;
     Log::out("passthru - listxattr");
     return 0;
 }