1 | <?php |
||
34 | class ReadOnlyCachePermissionsMask extends CacheWrapper { |
||
35 | /** |
||
36 | * @var int |
||
37 | */ |
||
38 | protected $mask; |
||
39 | |||
40 | /** |
||
41 | * System internal paths which should not be protected |
||
42 | * @var array |
||
43 | */ |
||
44 | private $whitelist = [ |
||
45 | 'uploads', |
||
46 | 'cache', |
||
47 | 'files_zsync' |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * @param \OCP\Files\Cache\ICache $cache |
||
52 | * @param int $mask |
||
53 | */ |
||
54 | public function __construct($cache, $mask) { |
||
55 | parent::__construct($cache); |
||
56 | $this->mask = $mask; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param \OCP\Files\Cache\ICacheEntry $entry |
||
61 | * @return \OCP\Files\Cache\ICacheEntry |
||
62 | */ |
||
63 | protected function formatCacheEntry($entry) { |
||
64 | $storageId = $entry->getStorageId(); |
||
65 | |||
66 | // Give all permissions to whitelisted "internal" paths and their |
||
67 | // subdirectories |
||
68 | if ($this->isHomeStorage($storageId)) { |
||
69 | foreach ($this->whitelist as $path) { |
||
70 | if ($this->startsWith($entry->getPath(), $path)) { |
||
71 | $entry['permissions'] = Constants::PERMISSION_ALL; |
||
72 | return $entry; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | // Allow creation of skeleton files |
||
78 | if ($this->isHomeStorage($storageId) && $entry->getPath() === '') { |
||
79 | $entry['permissions'] = Constants::PERMISSION_CREATE; |
||
80 | $this->mask = Constants::PERMISSION_CREATE; |
||
81 | } |
||
82 | |||
83 | $entry['permissions'] &= $this->mask; |
||
84 | return $entry; |
||
85 | } |
||
86 | |||
87 | private function isHomeStorage($storageId) { |
||
90 | |||
91 | private function startsWith($haystack, $needle) { |
||
94 | } |
||
95 |