diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-11-10 16:14:08 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-11-19 13:32:00 +0100 |
commit | 888df3933df7f3588de11085035d2d3ae9292fb0 (patch) | |
tree | b7976666e9249b0be163b57fb064f3a1ade26919 /lib/private/files/cache/propagator.php | |
parent | d006a7c723e4c51a4132b0f8817392bf1f3cd534 (diff) | |
download | nextcloud-server-888df3933df7f3588de11085035d2d3ae9292fb0.tar.gz nextcloud-server-888df3933df7f3588de11085035d2d3ae9292fb0.zip |
take the etag of child mounts into account for the folder etag
this replaces shared etag propagation
Diffstat (limited to 'lib/private/files/cache/propagator.php')
-rw-r--r-- | lib/private/files/cache/propagator.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/private/files/cache/propagator.php b/lib/private/files/cache/propagator.php new file mode 100644 index 00000000000..bd11cef5990 --- /dev/null +++ b/lib/private/files/cache/propagator.php @@ -0,0 +1,66 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\Files\Cache; + +/** + * Propagate etags and mtimes within the storage + */ +class Propagator { + /** + * @var \OC\Files\Storage\Storage + */ + protected $storage; + + /** + * @param \OC\Files\Storage\Storage $storage + */ + public function __construct(\OC\Files\Storage\Storage $storage) { + $this->storage = $storage; + } + + + /** + * @param string $internalPath + * @param int $time + * @return array[] all propagated entries + */ + public function propagateChange($internalPath, $time) { + $cache = $this->storage->getCache($internalPath); + + $parentId = $cache->getParentId($internalPath); + $propagatedEntries = []; + while ($parentId !== -1) { + $entry = $cache->get($parentId); + $propagatedEntries[] = $entry; + if (!$entry) { + return $propagatedEntries; + } + $mtime = max($time, $entry['mtime']); + + $cache->update($parentId, ['mtime' => $mtime, 'etag' => $this->storage->getETag($entry['path'])]); + + $parentId = $entry['parent']; + } + + return $propagatedEntries; + } +} |