Example #1
0
 /**
  * Rename a normal file to a db file
  *
  * @access public
  *
  * @param $path file from path
  * @param $pi the pi of the db entry
  */
 public static function renameToDb($path, $pi)
 {
     Log::in("query - renameToDb - path is - {$path}");
     $dbConn = Pool::get();
     /* Get the query properties */
     $tableType = $pi[PI_TI];
     $table = $tableType[TI_TABLE];
     $name = $tableType[TI_NAMEFIELD];
     $prefix = Pool::getTableprefix();
     $toFilename = $pi[PI_FILENAME];
     /* Get the from file name */
     $fromFilename = basename($path);
     $fromFilenameArray = explode('.', $fromFilename);
     $fromFilename = $fromFilenameArray[0];
     Log::output("query - renameToDb - create sql");
     $sql = "UPDATE ";
     $sql .= "`{$prefix}" . "{$table}`";
     $sql .= " SET {$name} = '{$toFilename}'";
     $sql .= " WHERE {$name} = '{$fromFilename}'";
     Log::output($sql);
     /* Check for failure */
     Log::output("query - renameToDb - check for failure");
     $result = mysql_query($sql, $dbConn);
     $rows = mysql_affected_rows($dbConn);
     if ($result === false || $rows == 0) {
         /* If no rows, create the entity */
         if ($rows == 0) {
             Log::output("query - renameToDb - creating entity");
             $buf = file_get_contents($path);
             $size = strlen($buf);
             $ret = Query::mknod($pi);
             if ($ret != 0) {
                 Pool::release($dbConn);
                 Log::out("query - renameToDb failed - cannot create entity");
                 return -FUSE_EIO;
             }
             Query::fillContentId($pi, 0);
             Query::Write($pi, $buf, $size, 0);
             Pool::release($dbConn);
             Log::out("query - renameToDb - create - OK");
             return 0;
         }
         /* Otherwise process the error */
         $error = mysql_error($dbConn);
         Log::output($error);
         Pool::release($dbConn);
         Log::out("query - renameToDb failed");
         return -FUSE_EIO;
     }
     Pool::release($dbConn);
     Log::out("query - renameToDb");
     return 0;
 }
Example #2
0
 /**
  * List extended attributes of a file/directory
  *
  * @access public
  *
  * @param $path file path
  * @param $retval file name array of extended attributes
  */
 function listxattr($path, &$retval)
 {
     Log::in("LISTXATTR {$path}");
     /* Check for passthru */
     if (PassThru::check($path)) {
         $ret = PassThru::listxattr($path, $retval);
     } else {
         $pi = Query::pathInfo($path);
         Query::fillContentId($pi, 0);
         $ret = Query::listxattr($pi, $retval);
         if ($ret == 0) {
             Query::resolveAttributes($retval);
         }
     }
     Log::out("LISTXATTR");
     return $ret;
 }