Completed
Push — master ( 023c8b...8f8ae9 )
by Roeland
12:19
created

CacheMountProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getMountsForUser() 0 15 3
1
<?php
2
/**
3
 * @author Robin Appelman <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2016, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OC\Files\Mount;
23
24
use OCP\Files\Config\IMountProvider;
25
use OCP\Files\Storage\IStorageFactory;
26
use OCP\IConfig;
27
use OCP\IUser;
28
29
/**
30
 * Mount provider for custom cache storages
31
 */
32
class CacheMountProvider implements IMountProvider {
33
	/**
34
	 * @var IConfig
35
	 */
36
	private $config;
37
38
	/**
39
	 * ObjectStoreHomeMountProvider constructor.
40
	 *
41
	 * @param IConfig $config
42
	 */
43
	public function __construct(IConfig $config) {
44
		$this->config = $config;
45
	}
46
47
	/**
48
	 * Get the cache mount for a user
49
	 *
50
	 * @param IUser $user
51
	 * @param IStorageFactory $loader
52
	 * @return \OCP\Files\Mount\IMountPoint[]
53
	 */
54
	public function getMountsForUser(IUser $user, IStorageFactory $loader) {
55
		$cacheBaseDir = $this->config->getSystemValue('cache_path', '');
56
		if ($cacheBaseDir !== '') {
57
			$cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID();
58
			if (!file_exists($cacheDir)) {
59
				mkdir($cacheDir, 0770, true);
60
			}
61
62
			return [
63
				new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir, $loader])
64
			];
65
		} else {
66
			return [];
67
		}
68
	}
69
}
70