@@ -36,43 +36,43 @@ |
||
36 | 36 | * @package OC\Files\Cache |
37 | 37 | */ |
38 | 38 | class StorageGlobal { |
39 | - /** @var IDBConnection */ |
|
40 | - private $connection; |
|
39 | + /** @var IDBConnection */ |
|
40 | + private $connection; |
|
41 | 41 | |
42 | - /** @var array[] */ |
|
43 | - private $cache = []; |
|
42 | + /** @var array[] */ |
|
43 | + private $cache = []; |
|
44 | 44 | |
45 | - public function __construct(IDBConnection $connection) { |
|
46 | - $this->connection = $connection; |
|
47 | - } |
|
45 | + public function __construct(IDBConnection $connection) { |
|
46 | + $this->connection = $connection; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param string[] $storageIds |
|
51 | - */ |
|
52 | - public function loadForStorageIds(array $storageIds) { |
|
53 | - $builder = $this->connection->getQueryBuilder(); |
|
54 | - $query = $builder->select(['id', 'numeric_id', 'available', 'last_checked']) |
|
55 | - ->from('storages') |
|
56 | - ->where($builder->expr()->in('id', $builder->createNamedParameter(array_values($storageIds), IQueryBuilder::PARAM_STR_ARRAY))); |
|
49 | + /** |
|
50 | + * @param string[] $storageIds |
|
51 | + */ |
|
52 | + public function loadForStorageIds(array $storageIds) { |
|
53 | + $builder = $this->connection->getQueryBuilder(); |
|
54 | + $query = $builder->select(['id', 'numeric_id', 'available', 'last_checked']) |
|
55 | + ->from('storages') |
|
56 | + ->where($builder->expr()->in('id', $builder->createNamedParameter(array_values($storageIds), IQueryBuilder::PARAM_STR_ARRAY))); |
|
57 | 57 | |
58 | - $result = $query->execute(); |
|
59 | - while ($row = $result->fetch()) { |
|
60 | - $this->cache[$row['id']] = $row; |
|
61 | - } |
|
62 | - } |
|
58 | + $result = $query->execute(); |
|
59 | + while ($row = $result->fetch()) { |
|
60 | + $this->cache[$row['id']] = $row; |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $storageId |
|
66 | - * @return array|null |
|
67 | - */ |
|
68 | - public function getStorageInfo($storageId) { |
|
69 | - if (!isset($this->cache[$storageId])) { |
|
70 | - $this->loadForStorageIds([$storageId]); |
|
71 | - } |
|
72 | - return isset($this->cache[$storageId]) ? $this->cache[$storageId] : null; |
|
73 | - } |
|
64 | + /** |
|
65 | + * @param string $storageId |
|
66 | + * @return array|null |
|
67 | + */ |
|
68 | + public function getStorageInfo($storageId) { |
|
69 | + if (!isset($this->cache[$storageId])) { |
|
70 | + $this->loadForStorageIds([$storageId]); |
|
71 | + } |
|
72 | + return isset($this->cache[$storageId]) ? $this->cache[$storageId] : null; |
|
73 | + } |
|
74 | 74 | |
75 | - public function clearCache() { |
|
76 | - $this->cache = []; |
|
77 | - } |
|
75 | + public function clearCache() { |
|
76 | + $this->cache = []; |
|
77 | + } |
|
78 | 78 | } |
@@ -29,60 +29,60 @@ |
||
29 | 29 | * Fallback implementation for moveFromCache |
30 | 30 | */ |
31 | 31 | trait MoveFromCacheTrait { |
32 | - /** |
|
33 | - * store meta data for a file or folder |
|
34 | - * |
|
35 | - * @param string $file |
|
36 | - * @param array $data |
|
37 | - * |
|
38 | - * @return int file id |
|
39 | - * @throws \RuntimeException |
|
40 | - */ |
|
41 | - abstract public function put($file, array $data); |
|
32 | + /** |
|
33 | + * store meta data for a file or folder |
|
34 | + * |
|
35 | + * @param string $file |
|
36 | + * @param array $data |
|
37 | + * |
|
38 | + * @return int file id |
|
39 | + * @throws \RuntimeException |
|
40 | + */ |
|
41 | + abstract public function put($file, array $data); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Move a file or folder in the cache |
|
45 | - * |
|
46 | - * @param \OCP\Files\Cache\ICache $sourceCache |
|
47 | - * @param string $sourcePath |
|
48 | - * @param string $targetPath |
|
49 | - */ |
|
50 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
51 | - $sourceEntry = $sourceCache->get($sourcePath); |
|
43 | + /** |
|
44 | + * Move a file or folder in the cache |
|
45 | + * |
|
46 | + * @param \OCP\Files\Cache\ICache $sourceCache |
|
47 | + * @param string $sourcePath |
|
48 | + * @param string $targetPath |
|
49 | + */ |
|
50 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
51 | + $sourceEntry = $sourceCache->get($sourcePath); |
|
52 | 52 | |
53 | - $this->copyFromCache($sourceCache, $sourceEntry, $targetPath); |
|
53 | + $this->copyFromCache($sourceCache, $sourceEntry, $targetPath); |
|
54 | 54 | |
55 | - $sourceCache->remove($sourcePath); |
|
56 | - } |
|
55 | + $sourceCache->remove($sourcePath); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Copy a file or folder in the cache |
|
60 | - * |
|
61 | - * @param \OCP\Files\Cache\ICache $sourceCache |
|
62 | - * @param ICacheEntry $sourceEntry |
|
63 | - * @param string $targetPath |
|
64 | - */ |
|
65 | - public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath) { |
|
66 | - $this->put($targetPath, $this->cacheEntryToArray($sourceEntry)); |
|
67 | - if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) { |
|
68 | - $folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId()); |
|
69 | - foreach ($folderContent as $subEntry) { |
|
70 | - $subTargetPath = $targetPath . '/' . $subEntry->getName(); |
|
71 | - $this->copyFromCache($sourceCache, $subEntry, $subTargetPath); |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
58 | + /** |
|
59 | + * Copy a file or folder in the cache |
|
60 | + * |
|
61 | + * @param \OCP\Files\Cache\ICache $sourceCache |
|
62 | + * @param ICacheEntry $sourceEntry |
|
63 | + * @param string $targetPath |
|
64 | + */ |
|
65 | + public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath) { |
|
66 | + $this->put($targetPath, $this->cacheEntryToArray($sourceEntry)); |
|
67 | + if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) { |
|
68 | + $folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId()); |
|
69 | + foreach ($folderContent as $subEntry) { |
|
70 | + $subTargetPath = $targetPath . '/' . $subEntry->getName(); |
|
71 | + $this->copyFromCache($sourceCache, $subEntry, $subTargetPath); |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - private function cacheEntryToArray(ICacheEntry $entry) { |
|
77 | - return [ |
|
78 | - 'size' => $entry->getSize(), |
|
79 | - 'mtime' => $entry->getMTime(), |
|
80 | - 'storage_mtime' => $entry->getStorageMTime(), |
|
81 | - 'mimetype' => $entry->getMimeType(), |
|
82 | - 'mimepart' => $entry->getMimePart(), |
|
83 | - 'etag' => $entry->getEtag(), |
|
84 | - 'permissions' => $entry->getPermissions(), |
|
85 | - 'encrypted' => $entry->isEncrypted() |
|
86 | - ]; |
|
87 | - } |
|
76 | + private function cacheEntryToArray(ICacheEntry $entry) { |
|
77 | + return [ |
|
78 | + 'size' => $entry->getSize(), |
|
79 | + 'mtime' => $entry->getMTime(), |
|
80 | + 'storage_mtime' => $entry->getStorageMTime(), |
|
81 | + 'mimetype' => $entry->getMimeType(), |
|
82 | + 'mimepart' => $entry->getMimePart(), |
|
83 | + 'etag' => $entry->getEtag(), |
|
84 | + 'permissions' => $entry->getPermissions(), |
|
85 | + 'encrypted' => $entry->isEncrypted() |
|
86 | + ]; |
|
87 | + } |
|
88 | 88 | } |
@@ -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 ($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 ($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 ($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 ($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 | } |
@@ -35,35 +35,35 @@ |
||
35 | 35 | /** |
36 | 36 | * {@inheritdoc} |
37 | 37 | */ |
38 | - public function isLocked($path, $type) { |
|
39 | - return false; |
|
40 | - } |
|
38 | + public function isLocked($path, $type) { |
|
39 | + return false; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * {@inheritdoc} |
44 | 44 | */ |
45 | - public function acquireLock($path, $type) { |
|
46 | - // do nothing |
|
47 | - } |
|
45 | + public function acquireLock($path, $type) { |
|
46 | + // do nothing |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
49 | + /** |
|
50 | 50 | * {@inheritdoc} |
51 | - */ |
|
52 | - public function releaseLock($path, $type) { |
|
53 | - // do nothing |
|
54 | - } |
|
51 | + */ |
|
52 | + public function releaseLock($path, $type) { |
|
53 | + // do nothing |
|
54 | + } |
|
55 | 55 | |
56 | - /**1 |
|
56 | + /**1 |
|
57 | 57 | * {@inheritdoc} |
58 | 58 | */ |
59 | - public function releaseAll() { |
|
60 | - // do nothing |
|
61 | - } |
|
59 | + public function releaseAll() { |
|
60 | + // do nothing |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - public function changeLock($path, $targetType) { |
|
67 | - // do nothing |
|
68 | - } |
|
63 | + /** |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + public function changeLock($path, $targetType) { |
|
67 | + // do nothing |
|
68 | + } |
|
69 | 69 | } |
@@ -29,99 +29,99 @@ |
||
29 | 29 | * to release any left over locks at the end of the request |
30 | 30 | */ |
31 | 31 | abstract class AbstractLockingProvider implements ILockingProvider { |
32 | - protected $ttl; // how long until we clear stray locks in seconds |
|
32 | + protected $ttl; // how long until we clear stray locks in seconds |
|
33 | 33 | |
34 | - protected $acquiredLocks = [ |
|
35 | - 'shared' => [], |
|
36 | - 'exclusive' => [] |
|
37 | - ]; |
|
34 | + protected $acquiredLocks = [ |
|
35 | + 'shared' => [], |
|
36 | + 'exclusive' => [] |
|
37 | + ]; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Check if we've locally acquired a lock |
|
41 | - * |
|
42 | - * @param string $path |
|
43 | - * @param int $type |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - protected function hasAcquiredLock($path, $type) { |
|
47 | - if ($type === self::LOCK_SHARED) { |
|
48 | - return isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 0; |
|
49 | - } else { |
|
50 | - return isset($this->acquiredLocks['exclusive'][$path]) && $this->acquiredLocks['exclusive'][$path] === true; |
|
51 | - } |
|
52 | - } |
|
39 | + /** |
|
40 | + * Check if we've locally acquired a lock |
|
41 | + * |
|
42 | + * @param string $path |
|
43 | + * @param int $type |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + protected function hasAcquiredLock($path, $type) { |
|
47 | + if ($type === self::LOCK_SHARED) { |
|
48 | + return isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 0; |
|
49 | + } else { |
|
50 | + return isset($this->acquiredLocks['exclusive'][$path]) && $this->acquiredLocks['exclusive'][$path] === true; |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Mark a locally acquired lock |
|
56 | - * |
|
57 | - * @param string $path |
|
58 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
59 | - */ |
|
60 | - protected function markAcquire($path, $type) { |
|
61 | - if ($type === self::LOCK_SHARED) { |
|
62 | - if (!isset($this->acquiredLocks['shared'][$path])) { |
|
63 | - $this->acquiredLocks['shared'][$path] = 0; |
|
64 | - } |
|
65 | - $this->acquiredLocks['shared'][$path]++; |
|
66 | - } else { |
|
67 | - $this->acquiredLocks['exclusive'][$path] = true; |
|
68 | - } |
|
69 | - } |
|
54 | + /** |
|
55 | + * Mark a locally acquired lock |
|
56 | + * |
|
57 | + * @param string $path |
|
58 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
59 | + */ |
|
60 | + protected function markAcquire($path, $type) { |
|
61 | + if ($type === self::LOCK_SHARED) { |
|
62 | + if (!isset($this->acquiredLocks['shared'][$path])) { |
|
63 | + $this->acquiredLocks['shared'][$path] = 0; |
|
64 | + } |
|
65 | + $this->acquiredLocks['shared'][$path]++; |
|
66 | + } else { |
|
67 | + $this->acquiredLocks['exclusive'][$path] = true; |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Mark a release of a locally acquired lock |
|
73 | - * |
|
74 | - * @param string $path |
|
75 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
76 | - */ |
|
77 | - protected function markRelease($path, $type) { |
|
78 | - if ($type === self::LOCK_SHARED) { |
|
79 | - if (isset($this->acquiredLocks['shared'][$path]) and $this->acquiredLocks['shared'][$path] > 0) { |
|
80 | - $this->acquiredLocks['shared'][$path]--; |
|
81 | - if ($this->acquiredLocks['shared'][$path] === 0) { |
|
82 | - unset($this->acquiredLocks['shared'][$path]); |
|
83 | - } |
|
84 | - } |
|
85 | - } else if ($type === self::LOCK_EXCLUSIVE) { |
|
86 | - unset($this->acquiredLocks['exclusive'][$path]); |
|
87 | - } |
|
88 | - } |
|
71 | + /** |
|
72 | + * Mark a release of a locally acquired lock |
|
73 | + * |
|
74 | + * @param string $path |
|
75 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
76 | + */ |
|
77 | + protected function markRelease($path, $type) { |
|
78 | + if ($type === self::LOCK_SHARED) { |
|
79 | + if (isset($this->acquiredLocks['shared'][$path]) and $this->acquiredLocks['shared'][$path] > 0) { |
|
80 | + $this->acquiredLocks['shared'][$path]--; |
|
81 | + if ($this->acquiredLocks['shared'][$path] === 0) { |
|
82 | + unset($this->acquiredLocks['shared'][$path]); |
|
83 | + } |
|
84 | + } |
|
85 | + } else if ($type === self::LOCK_EXCLUSIVE) { |
|
86 | + unset($this->acquiredLocks['exclusive'][$path]); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Change the type of an existing tracked lock |
|
92 | - * |
|
93 | - * @param string $path |
|
94 | - * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
95 | - */ |
|
96 | - protected function markChange($path, $targetType) { |
|
97 | - if ($targetType === self::LOCK_SHARED) { |
|
98 | - unset($this->acquiredLocks['exclusive'][$path]); |
|
99 | - if (!isset($this->acquiredLocks['shared'][$path])) { |
|
100 | - $this->acquiredLocks['shared'][$path] = 0; |
|
101 | - } |
|
102 | - $this->acquiredLocks['shared'][$path]++; |
|
103 | - } else if ($targetType === self::LOCK_EXCLUSIVE) { |
|
104 | - $this->acquiredLocks['exclusive'][$path] = true; |
|
105 | - $this->acquiredLocks['shared'][$path]--; |
|
106 | - } |
|
107 | - } |
|
90 | + /** |
|
91 | + * Change the type of an existing tracked lock |
|
92 | + * |
|
93 | + * @param string $path |
|
94 | + * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
95 | + */ |
|
96 | + protected function markChange($path, $targetType) { |
|
97 | + if ($targetType === self::LOCK_SHARED) { |
|
98 | + unset($this->acquiredLocks['exclusive'][$path]); |
|
99 | + if (!isset($this->acquiredLocks['shared'][$path])) { |
|
100 | + $this->acquiredLocks['shared'][$path] = 0; |
|
101 | + } |
|
102 | + $this->acquiredLocks['shared'][$path]++; |
|
103 | + } else if ($targetType === self::LOCK_EXCLUSIVE) { |
|
104 | + $this->acquiredLocks['exclusive'][$path] = true; |
|
105 | + $this->acquiredLocks['shared'][$path]--; |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * release all lock acquired by this instance which were marked using the mark* methods |
|
111 | - */ |
|
112 | - public function releaseAll() { |
|
113 | - foreach ($this->acquiredLocks['shared'] as $path => $count) { |
|
114 | - for ($i = 0; $i < $count; $i++) { |
|
115 | - $this->releaseLock($path, self::LOCK_SHARED); |
|
116 | - } |
|
117 | - } |
|
109 | + /** |
|
110 | + * release all lock acquired by this instance which were marked using the mark* methods |
|
111 | + */ |
|
112 | + public function releaseAll() { |
|
113 | + foreach ($this->acquiredLocks['shared'] as $path => $count) { |
|
114 | + for ($i = 0; $i < $count; $i++) { |
|
115 | + $this->releaseLock($path, self::LOCK_SHARED); |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - foreach ($this->acquiredLocks['exclusive'] as $path => $hasLock) { |
|
120 | - $this->releaseLock($path, self::LOCK_EXCLUSIVE); |
|
121 | - } |
|
122 | - } |
|
119 | + foreach ($this->acquiredLocks['exclusive'] as $path => $hasLock) { |
|
120 | + $this->releaseLock($path, self::LOCK_EXCLUSIVE); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - protected function getOwnSharedLockCount($path) { |
|
125 | - return isset($this->acquiredLocks['shared'][$path]) ? $this->acquiredLocks['shared'][$path] : 0; |
|
126 | - } |
|
124 | + protected function getOwnSharedLockCount($path) { |
|
125 | + return isset($this->acquiredLocks['shared'][$path]) ? $this->acquiredLocks['shared'][$path] : 0; |
|
126 | + } |
|
127 | 127 | } |
@@ -27,102 +27,102 @@ |
||
27 | 27 | use OCP\IMemcache; |
28 | 28 | |
29 | 29 | class MemcacheLockingProvider extends AbstractLockingProvider { |
30 | - /** |
|
31 | - * @var \OCP\IMemcache |
|
32 | - */ |
|
33 | - private $memcache; |
|
30 | + /** |
|
31 | + * @var \OCP\IMemcache |
|
32 | + */ |
|
33 | + private $memcache; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param \OCP\IMemcache $memcache |
|
37 | - * @param int $ttl |
|
38 | - */ |
|
39 | - public function __construct(IMemcache $memcache, $ttl = 3600) { |
|
40 | - $this->memcache = $memcache; |
|
41 | - $this->ttl = $ttl; |
|
42 | - } |
|
35 | + /** |
|
36 | + * @param \OCP\IMemcache $memcache |
|
37 | + * @param int $ttl |
|
38 | + */ |
|
39 | + public function __construct(IMemcache $memcache, $ttl = 3600) { |
|
40 | + $this->memcache = $memcache; |
|
41 | + $this->ttl = $ttl; |
|
42 | + } |
|
43 | 43 | |
44 | - private function setTTL($path) { |
|
45 | - if ($this->memcache instanceof IMemcacheTTL) { |
|
46 | - $this->memcache->setTTL($path, $this->ttl); |
|
47 | - } |
|
48 | - } |
|
44 | + private function setTTL($path) { |
|
45 | + if ($this->memcache instanceof IMemcacheTTL) { |
|
46 | + $this->memcache->setTTL($path, $this->ttl); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $path |
|
52 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function isLocked($path, $type) { |
|
56 | - $lockValue = $this->memcache->get($path); |
|
57 | - if ($type === self::LOCK_SHARED) { |
|
58 | - return $lockValue > 0; |
|
59 | - } else if ($type === self::LOCK_EXCLUSIVE) { |
|
60 | - return $lockValue === 'exclusive'; |
|
61 | - } else { |
|
62 | - return false; |
|
63 | - } |
|
64 | - } |
|
50 | + /** |
|
51 | + * @param string $path |
|
52 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function isLocked($path, $type) { |
|
56 | + $lockValue = $this->memcache->get($path); |
|
57 | + if ($type === self::LOCK_SHARED) { |
|
58 | + return $lockValue > 0; |
|
59 | + } else if ($type === self::LOCK_EXCLUSIVE) { |
|
60 | + return $lockValue === 'exclusive'; |
|
61 | + } else { |
|
62 | + return false; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $path |
|
68 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
69 | - * @throws \OCP\Lock\LockedException |
|
70 | - */ |
|
71 | - public function acquireLock($path, $type) { |
|
72 | - if ($type === self::LOCK_SHARED) { |
|
73 | - if (!$this->memcache->inc($path)) { |
|
74 | - throw new LockedException($path); |
|
75 | - } |
|
76 | - } else { |
|
77 | - $this->memcache->add($path, 0); |
|
78 | - if (!$this->memcache->cas($path, 0, 'exclusive')) { |
|
79 | - throw new LockedException($path); |
|
80 | - } |
|
81 | - } |
|
82 | - $this->setTTL($path); |
|
83 | - $this->markAcquire($path, $type); |
|
84 | - } |
|
66 | + /** |
|
67 | + * @param string $path |
|
68 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
69 | + * @throws \OCP\Lock\LockedException |
|
70 | + */ |
|
71 | + public function acquireLock($path, $type) { |
|
72 | + if ($type === self::LOCK_SHARED) { |
|
73 | + if (!$this->memcache->inc($path)) { |
|
74 | + throw new LockedException($path); |
|
75 | + } |
|
76 | + } else { |
|
77 | + $this->memcache->add($path, 0); |
|
78 | + if (!$this->memcache->cas($path, 0, 'exclusive')) { |
|
79 | + throw new LockedException($path); |
|
80 | + } |
|
81 | + } |
|
82 | + $this->setTTL($path); |
|
83 | + $this->markAcquire($path, $type); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @param string $path |
|
88 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
89 | - */ |
|
90 | - public function releaseLock($path, $type) { |
|
91 | - if ($type === self::LOCK_SHARED) { |
|
92 | - if ($this->getOwnSharedLockCount($path) === 1) { |
|
93 | - $removed = $this->memcache->cad($path, 1); // if we're the only one having a shared lock we can remove it in one go |
|
94 | - if (!$removed) { //someone else also has a shared lock, decrease only |
|
95 | - $this->memcache->dec($path); |
|
96 | - } |
|
97 | - } else { |
|
98 | - // if we own more than one lock ourselves just decrease |
|
99 | - $this->memcache->dec($path); |
|
100 | - } |
|
101 | - } else if ($type === self::LOCK_EXCLUSIVE) { |
|
102 | - $this->memcache->cad($path, 'exclusive'); |
|
103 | - } |
|
104 | - $this->markRelease($path, $type); |
|
105 | - } |
|
86 | + /** |
|
87 | + * @param string $path |
|
88 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
89 | + */ |
|
90 | + public function releaseLock($path, $type) { |
|
91 | + if ($type === self::LOCK_SHARED) { |
|
92 | + if ($this->getOwnSharedLockCount($path) === 1) { |
|
93 | + $removed = $this->memcache->cad($path, 1); // if we're the only one having a shared lock we can remove it in one go |
|
94 | + if (!$removed) { //someone else also has a shared lock, decrease only |
|
95 | + $this->memcache->dec($path); |
|
96 | + } |
|
97 | + } else { |
|
98 | + // if we own more than one lock ourselves just decrease |
|
99 | + $this->memcache->dec($path); |
|
100 | + } |
|
101 | + } else if ($type === self::LOCK_EXCLUSIVE) { |
|
102 | + $this->memcache->cad($path, 'exclusive'); |
|
103 | + } |
|
104 | + $this->markRelease($path, $type); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Change the type of an existing lock |
|
109 | - * |
|
110 | - * @param string $path |
|
111 | - * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
112 | - * @throws \OCP\Lock\LockedException |
|
113 | - */ |
|
114 | - public function changeLock($path, $targetType) { |
|
115 | - if ($targetType === self::LOCK_SHARED) { |
|
116 | - if (!$this->memcache->cas($path, 'exclusive', 1)) { |
|
117 | - throw new LockedException($path); |
|
118 | - } |
|
119 | - } else if ($targetType === self::LOCK_EXCLUSIVE) { |
|
120 | - // we can only change a shared lock to an exclusive if there's only a single owner of the shared lock |
|
121 | - if (!$this->memcache->cas($path, 1, 'exclusive')) { |
|
122 | - throw new LockedException($path); |
|
123 | - } |
|
124 | - } |
|
125 | - $this->setTTL($path); |
|
126 | - $this->markChange($path, $targetType); |
|
127 | - } |
|
107 | + /** |
|
108 | + * Change the type of an existing lock |
|
109 | + * |
|
110 | + * @param string $path |
|
111 | + * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
112 | + * @throws \OCP\Lock\LockedException |
|
113 | + */ |
|
114 | + public function changeLock($path, $targetType) { |
|
115 | + if ($targetType === self::LOCK_SHARED) { |
|
116 | + if (!$this->memcache->cas($path, 'exclusive', 1)) { |
|
117 | + throw new LockedException($path); |
|
118 | + } |
|
119 | + } else if ($targetType === self::LOCK_EXCLUSIVE) { |
|
120 | + // we can only change a shared lock to an exclusive if there's only a single owner of the shared lock |
|
121 | + if (!$this->memcache->cas($path, 1, 'exclusive')) { |
|
122 | + throw new LockedException($path); |
|
123 | + } |
|
124 | + } |
|
125 | + $this->setTTL($path); |
|
126 | + $this->markChange($path, $targetType); |
|
127 | + } |
|
128 | 128 | } |
@@ -29,13 +29,13 @@ |
||
29 | 29 | */ |
30 | 30 | class Image extends File { |
31 | 31 | |
32 | - /** |
|
33 | - * Type name; translated in templates |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $type = 'image'; |
|
32 | + /** |
|
33 | + * Type name; translated in templates |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $type = 'image'; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @TODO add EXIF information |
|
40 | - */ |
|
38 | + /** |
|
39 | + * @TODO add EXIF information |
|
40 | + */ |
|
41 | 41 | } |
@@ -29,13 +29,13 @@ |
||
29 | 29 | */ |
30 | 30 | class Audio extends File { |
31 | 31 | |
32 | - /** |
|
33 | - * Type name; translated in templates |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $type = 'audio'; |
|
32 | + /** |
|
33 | + * Type name; translated in templates |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $type = 'audio'; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @TODO add ID3 information |
|
40 | - */ |
|
38 | + /** |
|
39 | + * @TODO add ID3 information |
|
40 | + */ |
|
41 | 41 | } |
@@ -29,10 +29,10 @@ |
||
29 | 29 | */ |
30 | 30 | class Folder extends File { |
31 | 31 | |
32 | - /** |
|
33 | - * Type name; translated in templates |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $type = 'folder'; |
|
32 | + /** |
|
33 | + * Type name; translated in templates |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $type = 'folder'; |
|
37 | 37 | |
38 | 38 | } |