Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
start implementing a solution to fix broken etags for shared files
  • Loading branch information
Björn Schießle committed Nov 6, 2012
commit 52f25ac55260018270bc95ebdfe7c19b253e6750
33 changes: 29 additions & 4 deletions lib/connector/sabre/node.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,38 @@ public function touch($mtime) {
* @return bool|array
*/
public function updateProperties($properties) {
// get source path of shared files
if (!strncmp($this->path, '/Shared/', 8)) {
$source = OC_Filestorage_Shared::getSourcePath(str_replace('/Shared/', '', $this->path));
$parts = explode('/', $source, 4);
$user = $parts[1];
$path = '/'.$parts[3];
} else {
$user = OC_User::getUser();
$path = $this->path;
}

$existing = $this->getProperties(array());
foreach($properties as $propertyName => $propertyValue) {
// If it was null, we need to delete the property
if (is_null($propertyValue)) {
if(array_key_exists( $propertyName, $existing )) {
$query = OC_DB::prepare( 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?' );
$query->execute( array( OC_User::getUser(), $this->path, $propertyName ));
$query->execute( array( $user, $path, $propertyName ));
}
}
else {
if( strcmp( $propertyName, self::LASTMODIFIED_PROPERTYNAME) === 0 ) {
error_log("propertyName: " . $propertyName);
$this->touch($propertyValue);
} else {
error_log("update/insert property: user: $user; path: $path");
if(!array_key_exists( $propertyName, $existing )) {
$query = OC_DB::prepare( 'INSERT INTO `*PREFIX*properties` (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)' );
$query->execute( array( OC_User::getUser(), $this->path, $propertyName, $propertyValue ));
$query->execute( array( $user, $path, $propertyName, $propertyValue ));
} else {
$query = OC_DB::prepare( 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ? WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?' );
$query->execute( array( $propertyValue, OC_User::getUser(), $this->path, $propertyName ));
$query->execute( array( $propertyValue, $user, $path, $propertyName ));
}
}
}
Expand All @@ -181,6 +194,7 @@ public function updateProperties($properties) {
* @return void
*/
public function getProperties($properties) {
//TODO: Shared files?!?
if (is_null($this->property_cache)) {
$query = OC_DB::prepare( 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' );
$result = $query->execute( array( OC_User::getUser(), $this->path ));
Expand Down Expand Up @@ -222,9 +236,19 @@ static public function getETagPropertyForPath($path) {
if (empty($tag)) {
return null;
}

if (!strncmp($path, '/Shared/', 8)) {
$source = OC_Filestorage_Shared::getSourcePath(str_replace('/Shared/', '', $path));
$parts = explode('/', $source, 4);
$user = $parts[1];
$path = '/'.$parts[3];
} else {
$user = OC_User::getUser();
}

$etag = '"'.$tag.'"';
$query = OC_DB::prepare( 'INSERT INTO `*PREFIX*properties` (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)' );
$query->execute( array( OC_User::getUser(), $path, self::GETETAG_PROPERTYNAME, $etag ));
$query->execute( array( $user, $path, self::GETETAG_PROPERTYNAME, $etag ));
return $etag;
}

Expand All @@ -234,6 +258,7 @@ static public function getETagPropertyForPath($path) {
*/
static public function removeETagPropertyForPath($path) {
// remove tags from this and parent paths
//TODO Shared Files?!?
$paths = array();
while ($path != '/' && $path != '.' && $path != '' && $path != '\\') {
$paths[] = $path;
Expand Down