watcher.php 2.0 KB

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