watcher.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @author Christopher Schäpers <kondou@ts.unde.re>
  4. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <icewind@owncloud.com>
  7. * @author Vincent Petry <pvince81@owncloud.com>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Files\Cache;
  26. /**
  27. * check the storage backends for updates and change the cache accordingly
  28. */
  29. class Shared_Watcher extends Watcher {
  30. /**
  31. * check $path for updates
  32. *
  33. * @param string $path
  34. * @param array $cachedEntry
  35. * @return boolean true if path was updated
  36. */
  37. public function checkUpdate($path, $cachedEntry = null) {
  38. if (parent::checkUpdate($path, $cachedEntry) === true) {
  39. // since checkUpdate() has already updated the size of the subdirs,
  40. // only apply the update to the owner's parent dirs
  41. // find last parent before reaching the shared storage root,
  42. // which is the actual shared dir from the owner
  43. $sepPos = strpos($path, '/');
  44. if ($sepPos > 0) {
  45. $baseDir = substr($path, 0, $sepPos);
  46. } else {
  47. $baseDir = $path;
  48. }
  49. // find the path relative to the data dir
  50. $file = $this->storage->getFile($baseDir);
  51. $view = new \OC\Files\View('/' . $file['fileOwner']);
  52. // find the owner's storage and path
  53. list($storage, $internalPath) = $view->resolvePath($file['path']);
  54. // update the parent dirs' sizes in the owner's cache
  55. $storage->getCache()->correctFolderSize(dirname($internalPath));
  56. return true;
  57. }
  58. return false;
  59. }
  60. /**
  61. * remove deleted files in $path from the cache
  62. *
  63. * @param string $path
  64. */
  65. public function cleanFolder($path) {
  66. if ($path != '') {
  67. parent::cleanFolder($path);
  68. }
  69. }
  70. }