summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-04-19 00:25:47 +0200
committerRobin Appelman <icewind@owncloud.com>2012-04-19 00:25:47 +0200
commit5cefd3466056475f9433d33a74acba0b3ae092e3 (patch)
treebd73a04accfe1ac9c92598242a57bbd9153a5634 /apps/files_external
parent9a707e10bf70619bf1a553b2bc56c989f9725ab2 (diff)
downloadnextcloud-server-5cefd3466056475f9433d33a74acba0b3ae092e3.tar.gz
nextcloud-server-5cefd3466056475f9433d33a74acba0b3ae092e3.zip
emulate touch with custom mtime for swift backend
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/lib/swift.php50
1 files changed, 39 insertions, 11 deletions
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php
index ec09742c449..e53eb1ff3b6 100644
--- a/apps/files_external/lib/swift.php
+++ b/apps/files_external/lib/swift.php
@@ -373,6 +373,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
$obj=$container->create_object(basename($path));
}
+ $this->resetMTime($obj);
return $obj->write($content);
}
@@ -429,30 +430,39 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function touch($path,$mtime=null){
- if(!is_null($mtime)){
- return false;
- }
$obj=$this->getObject($path);
if(is_null($obj)){
return false;
}
- $fp = fopen('php://temp', 'r+');
- $obj->stream($fp);
- rewind($fp);
- $obj->write($fp);
- fclose($fp);
+ if(is_null($mtime)){
+ $mtime=time();
+ }
+
+ //emulate setting mtime with metadata
+ $obj->metadata['Mtime']=$mtime;
+ $obj->sync_metadata();
}
public function rename($path1,$path2){
$sourceContainer=$this->getContainer(dirname($path1));
$targetContainer=$this->getContainer(dirname($path2));
- return $sourceContainer->move_object_to(basename($path1),$targetContainer,basename($path2));
+ $result=$sourceContainer->move_object_to(basename($path1),$targetContainer,basename($path2));
+ if($result){
+ $targetObj=$this->getObject($path2);
+ $this->resetMTime($targetObj);
+ }
+ return $result;
}
public function copy($path1,$path2){
$sourceContainer=$this->getContainer(dirname($path1));
$targetContainer=$this->getContainer(dirname($path2));
- return $sourceContainer->copy_object_to(basename($path1),$targetContainer,basename($path2));
+ $result=$sourceContainer->copy_object_to(basename($path1),$targetContainer,basename($path2));
+ if($result){
+ $targetObj=$this->getObject($path2);
+ $this->resetMTime($targetObj);
+ }
+ return $result;
}
public function stat($path){
@@ -460,8 +470,14 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
if(is_null($obj)){
return false;
}
+
+ if(isset($obj->metadata['Mtime']) and $obj->metadata['Mtime']>-1){
+ $mtime=$obj->metadata['Mtime'];
+ }else{
+ $mtime=strtotime($obj->last_modified);
+ }
return array(
- 'mtime'=>strtotime($obj->last_modified),
+ 'mtime'=>$mtime,
'size'=>$obj->content_length,
'ctime'=>-1,
);
@@ -484,5 +500,17 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
$obj=$this->createObject($path);
}
$obj->load_from_filename($tmpFile);
+ $this->resetMTime($obj);
+ }
+
+ /**
+ * remove custom mtime metadata
+ * @param CF_Object obj
+ */
+ private function resetMTime($obj){
+ if(isset($obj->metadata['Mtime'])){
+ $obj->metadata['Mtime']=-1;
+ $obj->sync_metadata();
+ }
}
}