@@ -32,113 +32,113 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class Watcher implements IWatcher { |
| 34 | 34 | |
| 35 | - protected $watchPolicy = self::CHECK_ONCE; |
|
| 35 | + protected $watchPolicy = self::CHECK_ONCE; |
|
| 36 | 36 | |
| 37 | - protected $checkedPaths = array(); |
|
| 37 | + protected $checkedPaths = array(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var \OC\Files\Storage\Storage $storage |
|
| 41 | - */ |
|
| 42 | - protected $storage; |
|
| 39 | + /** |
|
| 40 | + * @var \OC\Files\Storage\Storage $storage |
|
| 41 | + */ |
|
| 42 | + protected $storage; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var Cache $cache |
|
| 46 | - */ |
|
| 47 | - protected $cache; |
|
| 44 | + /** |
|
| 45 | + * @var Cache $cache |
|
| 46 | + */ |
|
| 47 | + protected $cache; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var Scanner $scanner ; |
|
| 51 | - */ |
|
| 52 | - protected $scanner; |
|
| 49 | + /** |
|
| 50 | + * @var Scanner $scanner ; |
|
| 51 | + */ |
|
| 52 | + protected $scanner; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param \OC\Files\Storage\Storage $storage |
|
| 56 | - */ |
|
| 57 | - public function __construct(\OC\Files\Storage\Storage $storage) { |
|
| 58 | - $this->storage = $storage; |
|
| 59 | - $this->cache = $storage->getCache(); |
|
| 60 | - $this->scanner = $storage->getScanner(); |
|
| 61 | - } |
|
| 54 | + /** |
|
| 55 | + * @param \OC\Files\Storage\Storage $storage |
|
| 56 | + */ |
|
| 57 | + public function __construct(\OC\Files\Storage\Storage $storage) { |
|
| 58 | + $this->storage = $storage; |
|
| 59 | + $this->cache = $storage->getCache(); |
|
| 60 | + $this->scanner = $storage->getScanner(); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param int $policy either \OC\Files\Cache\Watcher::CHECK_NEVER, \OC\Files\Cache\Watcher::CHECK_ONCE, \OC\Files\Cache\Watcher::CHECK_ALWAYS |
|
| 65 | - */ |
|
| 66 | - public function setPolicy($policy) { |
|
| 67 | - $this->watchPolicy = $policy; |
|
| 68 | - } |
|
| 63 | + /** |
|
| 64 | + * @param int $policy either \OC\Files\Cache\Watcher::CHECK_NEVER, \OC\Files\Cache\Watcher::CHECK_ONCE, \OC\Files\Cache\Watcher::CHECK_ALWAYS |
|
| 65 | + */ |
|
| 66 | + public function setPolicy($policy) { |
|
| 67 | + $this->watchPolicy = $policy; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return int either \OC\Files\Cache\Watcher::CHECK_NEVER, \OC\Files\Cache\Watcher::CHECK_ONCE, \OC\Files\Cache\Watcher::CHECK_ALWAYS |
|
| 72 | - */ |
|
| 73 | - public function getPolicy() { |
|
| 74 | - return $this->watchPolicy; |
|
| 75 | - } |
|
| 70 | + /** |
|
| 71 | + * @return int either \OC\Files\Cache\Watcher::CHECK_NEVER, \OC\Files\Cache\Watcher::CHECK_ONCE, \OC\Files\Cache\Watcher::CHECK_ALWAYS |
|
| 72 | + */ |
|
| 73 | + public function getPolicy() { |
|
| 74 | + return $this->watchPolicy; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * check $path for updates and update if needed |
|
| 79 | - * |
|
| 80 | - * @param string $path |
|
| 81 | - * @param ICacheEntry|null $cachedEntry |
|
| 82 | - * @return boolean true if path was updated |
|
| 83 | - */ |
|
| 84 | - public function checkUpdate($path, $cachedEntry = null) { |
|
| 85 | - if (is_null($cachedEntry)) { |
|
| 86 | - $cachedEntry = $this->cache->get($path); |
|
| 87 | - } |
|
| 88 | - if ($cachedEntry === false || $this->needsUpdate($path, $cachedEntry)) { |
|
| 89 | - $this->update($path, $cachedEntry); |
|
| 90 | - return true; |
|
| 91 | - } else { |
|
| 92 | - return false; |
|
| 93 | - } |
|
| 94 | - } |
|
| 77 | + /** |
|
| 78 | + * check $path for updates and update if needed |
|
| 79 | + * |
|
| 80 | + * @param string $path |
|
| 81 | + * @param ICacheEntry|null $cachedEntry |
|
| 82 | + * @return boolean true if path was updated |
|
| 83 | + */ |
|
| 84 | + public function checkUpdate($path, $cachedEntry = null) { |
|
| 85 | + if (is_null($cachedEntry)) { |
|
| 86 | + $cachedEntry = $this->cache->get($path); |
|
| 87 | + } |
|
| 88 | + if ($cachedEntry === false || $this->needsUpdate($path, $cachedEntry)) { |
|
| 89 | + $this->update($path, $cachedEntry); |
|
| 90 | + return true; |
|
| 91 | + } else { |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Update the cache for changes to $path |
|
| 98 | - * |
|
| 99 | - * @param string $path |
|
| 100 | - * @param ICacheEntry $cachedData |
|
| 101 | - */ |
|
| 102 | - public function update($path, $cachedData) { |
|
| 103 | - if ($this->storage->is_dir($path)) { |
|
| 104 | - $this->scanner->scan($path, Scanner::SCAN_SHALLOW); |
|
| 105 | - } else { |
|
| 106 | - $this->scanner->scanFile($path); |
|
| 107 | - } |
|
| 108 | - if (is_array($cachedData) && $cachedData['mimetype'] === 'httpd/unix-directory') { |
|
| 109 | - $this->cleanFolder($path); |
|
| 110 | - } |
|
| 111 | - if ($this->cache instanceof Cache) { |
|
| 112 | - $this->cache->correctFolderSize($path); |
|
| 113 | - } |
|
| 114 | - } |
|
| 96 | + /** |
|
| 97 | + * Update the cache for changes to $path |
|
| 98 | + * |
|
| 99 | + * @param string $path |
|
| 100 | + * @param ICacheEntry $cachedData |
|
| 101 | + */ |
|
| 102 | + public function update($path, $cachedData) { |
|
| 103 | + if ($this->storage->is_dir($path)) { |
|
| 104 | + $this->scanner->scan($path, Scanner::SCAN_SHALLOW); |
|
| 105 | + } else { |
|
| 106 | + $this->scanner->scanFile($path); |
|
| 107 | + } |
|
| 108 | + if (is_array($cachedData) && $cachedData['mimetype'] === 'httpd/unix-directory') { |
|
| 109 | + $this->cleanFolder($path); |
|
| 110 | + } |
|
| 111 | + if ($this->cache instanceof Cache) { |
|
| 112 | + $this->cache->correctFolderSize($path); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Check if the cache for $path needs to be updated |
|
| 118 | - * |
|
| 119 | - * @param string $path |
|
| 120 | - * @param ICacheEntry $cachedData |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - public function needsUpdate($path, $cachedData) { |
|
| 124 | - if ($this->watchPolicy === self::CHECK_ALWAYS or ($this->watchPolicy === self::CHECK_ONCE and array_search($path, $this->checkedPaths) === false)) { |
|
| 125 | - $this->checkedPaths[] = $path; |
|
| 126 | - return $this->storage->hasUpdated($path, $cachedData['storage_mtime']); |
|
| 127 | - } |
|
| 128 | - return false; |
|
| 129 | - } |
|
| 116 | + /** |
|
| 117 | + * Check if the cache for $path needs to be updated |
|
| 118 | + * |
|
| 119 | + * @param string $path |
|
| 120 | + * @param ICacheEntry $cachedData |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + public function needsUpdate($path, $cachedData) { |
|
| 124 | + if ($this->watchPolicy === self::CHECK_ALWAYS or ($this->watchPolicy === self::CHECK_ONCE and array_search($path, $this->checkedPaths) === false)) { |
|
| 125 | + $this->checkedPaths[] = $path; |
|
| 126 | + return $this->storage->hasUpdated($path, $cachedData['storage_mtime']); |
|
| 127 | + } |
|
| 128 | + return false; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * remove deleted files in $path from the cache |
|
| 133 | - * |
|
| 134 | - * @param string $path |
|
| 135 | - */ |
|
| 136 | - public function cleanFolder($path) { |
|
| 137 | - $cachedContent = $this->cache->getFolderContents($path); |
|
| 138 | - foreach ($cachedContent as $entry) { |
|
| 139 | - if (!$this->storage->file_exists($entry['path'])) { |
|
| 140 | - $this->cache->remove($entry['path']); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 131 | + /** |
|
| 132 | + * remove deleted files in $path from the cache |
|
| 133 | + * |
|
| 134 | + * @param string $path |
|
| 135 | + */ |
|
| 136 | + public function cleanFolder($path) { |
|
| 137 | + $cachedContent = $this->cache->getFolderContents($path); |
|
| 138 | + foreach ($cachedContent as $entry) { |
|
| 139 | + if (!$this->storage->file_exists($entry['path'])) { |
|
| 140 | + $this->cache->remove($entry['path']); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | } |