Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 7 additions & 5 deletions lib/private/connector/sabre/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,22 @@ public function put($data) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}

// since we skipped the view we need to scan and emit the hooks ourselves
$this->fileView->getUpdater()->update($this->path);

if ($view) {
$this->emitPostHooks($exists);
}

// allow sync clients to send the mtime along in a header
$request = \OC::$server->getRequest();
if (isset($request->server['HTTP_X_OC_MTIME'])) {
if ($this->fileView->touch($this->path, $request->server['HTTP_X_OC_MTIME'])) {
if ($this->fileView->touch($this->path, $request->server['HTTP_X_OC_MTIME'],true)) {
header('X-OC-MTime: accepted');
}
}
// touch() has done already a updateMtime(), now we only need to run a updateFolderSize()
$this->fileView->getUpdater ()->updateFolderSize ( $this->path );
} else { // no touch was done so we need to do a full update
// since we skipped the view we need to scan and emit the hooks ourselves
$this->fileView->getUpdater ()->update ( $this->path );
}
$this->refreshInfo();
} catch (StorageNotAvailableException $e) {
throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage());
Expand Down
59 changes: 52 additions & 7 deletions lib/private/files/cache/updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,66 @@ public function update($path, $time = null) {
if (!$this->enabled or Scanner::isPartialFile($path)) {
return;
}

$this->updateMtime($path,$time, true);
$this->updateFolderSize($path,$time);

}

/**
* Update the cache for $path update the mtime of the parent folders
*
* @param string $path
* @param int $time
* @param boolean $skipPropagatingChanges
*/
public function updateMtime($path, $time = null, $skipPropagatingChanges=false) {
if (!$this->enabled or Scanner::isPartialFile($path)) {
return;
}
/**
* @var \OC\Files\Storage\Storage $storage
* @var string $internalPath
*/
list($storage, $internalPath) = $this->view->resolvePath($path);
if ($storage) {
$this->propagator->addChange($path);
$cache = $storage->getCache($internalPath);
$scanner = $storage->getScanner($internalPath);
$data = $scanner->scan($internalPath, Scanner::SCAN_SHALLOW, -1, false);
$this->correctParentStorageMtime($storage, $internalPath);
$cache->correctFolderSize($internalPath, $data);
$this->propagator->propagateChanges($time);
if (!$skipPropagatingChanges) {
$this->propagator->addChange($path);
$this->propagator->propagateChanges($time);
}
}
}
}


/**
* Update the cache for $path update the size and etag of the parent folders
*
* @param string $path
* @param int $time
* @param boolean $skipPropagatingChanges
*/
public function updateFolderSize($path, $time = null, $skipPropagatingChanges=false) {
if (!$this->enabled or Scanner::isPartialFile($path)) {
return;
}
/**
* @var \OC\Files\Storage\Storage $storage
* @var string $internalPath
*/
list($storage, $internalPath) = $this->view->resolvePath($path);
if ($storage) {
$scanner = $storage->getScanner ( $internalPath );
$data = $scanner->scan ( $internalPath, Scanner::SCAN_SHALLOW, - 1, false );
$cache = $storage->getCache ( $internalPath );
$cache->correctFolderSize ( $internalPath, $data );

if (!$skipPropagatingChanges) {
$this->propagator->addChange($path);
$this->propagator->propagateChanges($time);
}
}
}

/**
* Remove $path from the cache and update the size, etag and mtime of the parent folders
Expand Down
8 changes: 4 additions & 4 deletions lib/private/files/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public function filemtime($path) {
* @param int|string $mtime
* @return bool
*/
public function touch($path, $mtime = null) {
public function touch($path, $mtime = null, $skipPropagatingChanges=false) {
if (!is_null($mtime) and !is_numeric($mtime)) {
$mtime = strtotime($mtime);
}
Expand All @@ -462,7 +462,7 @@ public function touch($path, $mtime = null) {
$hooks[] = 'create';
$hooks[] = 'write';
}
$result = $this->basicOperation('touch', $path, $hooks, $mtime);
$result = $this->basicOperation('touch', $path, $hooks, $mtime, $skipPropagatingChanges);
if (!$result) {
// If create file fails because of permissions on external storage like SMB folders,
// check file exists and return false if not.
Expand Down Expand Up @@ -993,7 +993,7 @@ public function free_space($path = '/') {
* files), processes hooks and proxies, sanitises paths, and finally passes them on to
* \OC\Files\Storage\Storage for delegation to a storage backend for execution
*/
private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) {
private function basicOperation($operation, $path, $hooks = array(), $extraParam = null, $skipPropagatingChanges=false) {
$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (Filesystem::isValidPath($path)
Expand Down Expand Up @@ -1037,7 +1037,7 @@ private function basicOperation($operation, $path, $hooks = array(), $extraParam
$this->updater->update($path);
}
if (in_array('touch', $hooks)) {
$this->updater->update($path, $extraParam);
$this->updater->updateMtime($path, $extraParam, $skipPropagatingChanges);
}

if ((in_array('write', $hooks) || in_array('delete', $hooks)) && ($operation !== 'fopen' || $result === false)) {
Expand Down