Completed
Pull Request — master (#10075)
by
unknown
27:10
created
apps/sharebymail/lib/Settings/SettingsManager.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -27,35 +27,35 @@
 block discarded – undo
27 27
 
28 28
 class SettingsManager {
29 29
 
30
-	/** @var IConfig */
31
-	private $config;
32
-
33
-	private $sendPasswordByMailDefault = 'yes';
34
-
35
-	private $enforcePasswordProtectionDefault = 'no';
36
-
37
-	public function __construct(IConfig $config) {
38
-		$this->config = $config;
39
-	}
40
-
41
-	/**
42
-	 * should the password for a mail share be send to the recipient
43
-	 *
44
-	 * @return bool
45
-	 */
46
-	public function sendPasswordByMail() {
47
-		$sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault);
48
-		return $sendPasswordByMail === 'yes';
49
-	}
50
-
51
-	/**
52
-	 * do we require a share by mail to be password protected
53
-	 *
54
-	 * @return bool
55
-	 */
56
-	public function enforcePasswordProtection() {
57
-		$enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault);
58
-		return $enforcePassword === 'yes';
59
-	}
30
+    /** @var IConfig */
31
+    private $config;
32
+
33
+    private $sendPasswordByMailDefault = 'yes';
34
+
35
+    private $enforcePasswordProtectionDefault = 'no';
36
+
37
+    public function __construct(IConfig $config) {
38
+        $this->config = $config;
39
+    }
40
+
41
+    /**
42
+     * should the password for a mail share be send to the recipient
43
+     *
44
+     * @return bool
45
+     */
46
+    public function sendPasswordByMail() {
47
+        $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault);
48
+        return $sendPasswordByMail === 'yes';
49
+    }
50
+
51
+    /**
52
+     * do we require a share by mail to be password protected
53
+     *
54
+     * @return bool
55
+     */
56
+    public function enforcePasswordProtection() {
57
+        $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault);
58
+        return $enforcePassword === 'yes';
59
+    }
60 60
 
61 61
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/Settings/Admin.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -27,42 +27,42 @@
 block discarded – undo
27 27
 
28 28
 class Admin implements ISettings {
29 29
 
30
-	/** @var SettingsManager */
31
-	private $settingsManager;
30
+    /** @var SettingsManager */
31
+    private $settingsManager;
32 32
 
33
-	public function __construct(SettingsManager $settingsManager) {
34
-		$this->settingsManager = $settingsManager;
35
-	}
33
+    public function __construct(SettingsManager $settingsManager) {
34
+        $this->settingsManager = $settingsManager;
35
+    }
36 36
 
37
-	/**
38
-	 * @return TemplateResponse
39
-	 */
40
-	public function getForm() {
37
+    /**
38
+     * @return TemplateResponse
39
+     */
40
+    public function getForm() {
41 41
 
42
-		$parameters = [
43
-			'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(),
44
-			'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection()
45
-		];
42
+        $parameters = [
43
+            'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(),
44
+            'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection()
45
+        ];
46 46
 
47
-		return new TemplateResponse('sharebymail', 'settings-admin', $parameters, '');
48
-	}
47
+        return new TemplateResponse('sharebymail', 'settings-admin', $parameters, '');
48
+    }
49 49
 
50
-	/**
51
-	 * @return string the section ID, e.g. 'sharing'
52
-	 */
53
-	public function getSection() {
54
-		return 'sharing';
55
-	}
50
+    /**
51
+     * @return string the section ID, e.g. 'sharing'
52
+     */
53
+    public function getSection() {
54
+        return 'sharing';
55
+    }
56 56
 
57
-	/**
58
-	 * @return int whether the form should be rather on the top or bottom of
59
-	 * the admin section. The forms are arranged in ascending order of the
60
-	 * priority values. It is required to return a value between 0 and 100.
61
-	 *
62
-	 * E.g.: 70
63
-	 */
64
-	public function getPriority() {
65
-		return 40;
66
-	}
57
+    /**
58
+     * @return int whether the form should be rather on the top or bottom of
59
+     * the admin section. The forms are arranged in ascending order of the
60
+     * priority values. It is required to return a value between 0 and 100.
61
+     *
62
+     * E.g.: 70
63
+     */
64
+    public function getPriority() {
65
+        return 40;
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/Settings.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -27,27 +27,27 @@
 block discarded – undo
27 27
 
28 28
 class Settings {
29 29
 
30
-	/** @var SettingsManager */
31
-	private $settingsManager;
32
-
33
-	public function __construct(SettingsManager $settingsManager) {
34
-		$this->settingsManager = $settingsManager;
35
-	}
36
-
37
-	/**
38
-	 * announce that the share-by-mail share provider is enabled
39
-	 *
40
-	 * @param array $settings
41
-	 */
42
-	public function announceShareProvider(array $settings) {
43
-		$array = json_decode($settings['array']['oc_appconfig'], true);
44
-		$array['shareByMailEnabled'] = true;
45
-		$settings['array']['oc_appconfig'] = json_encode($array);
46
-	}
47
-
48
-	public function announceShareByMailSettings(array $settings) {
49
-		$array = json_decode($settings['array']['oc_appconfig'], true);
50
-		$array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection();
51
-		$settings['array']['oc_appconfig'] = json_encode($array);
52
-	}
30
+    /** @var SettingsManager */
31
+    private $settingsManager;
32
+
33
+    public function __construct(SettingsManager $settingsManager) {
34
+        $this->settingsManager = $settingsManager;
35
+    }
36
+
37
+    /**
38
+     * announce that the share-by-mail share provider is enabled
39
+     *
40
+     * @param array $settings
41
+     */
42
+    public function announceShareProvider(array $settings) {
43
+        $array = json_decode($settings['array']['oc_appconfig'], true);
44
+        $array['shareByMailEnabled'] = true;
45
+        $settings['array']['oc_appconfig'] = json_encode($array);
46
+    }
47
+
48
+    public function announceShareByMailSettings(array $settings) {
49
+        $array = json_decode($settings['array']['oc_appconfig'], true);
50
+        $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection();
51
+        $settings['array']['oc_appconfig'] = json_encode($array);
52
+    }
53 53
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/LogWrapper.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,13 +28,13 @@
 block discarded – undo
28 28
  * @brief wraps around static Nextcloud core methods
29 29
  */
30 30
 class LogWrapper {
31
-	protected $app = 'user_ldap';
31
+    protected $app = 'user_ldap';
32 32
 
33
-	/**
34
-	 * @brief states whether the filesystem was loaded
35
-	 * @return bool
36
-	 */
37
-	public function log($msg, $level) {
38
-		\OCP\Util::writeLog($this->app, $msg, $level);
39
-	}
33
+    /**
34
+     * @brief states whether the filesystem was loaded
35
+     * @return bool
36
+     */
37
+    public function log($msg, $level) {
38
+        \OCP\Util::writeLog($this->app, $msg, $level);
39
+    }
40 40
 }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
 
33 33
 	/**
34 34
 	 * @brief states whether the filesystem was loaded
35
-	 * @return bool
35
+	 * @return boolean|null
36 36
 	 */
37 37
 	public function log($msg, $level) {
38 38
 		\OCP\Util::writeLog($this->app, $msg, $level);
Please login to merge, or discard this patch.
apps/user_ldap/lib/FilesystemHelper.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -29,19 +29,19 @@
 block discarded – undo
29 29
  */
30 30
 class FilesystemHelper {
31 31
 
32
-	/**
33
-	 * @brief states whether the filesystem was loaded
34
-	 * @return bool
35
-	 */
36
-	public function isLoaded() {
37
-		return \OC\Files\Filesystem::$loaded;
38
-	}
32
+    /**
33
+     * @brief states whether the filesystem was loaded
34
+     * @return bool
35
+     */
36
+    public function isLoaded() {
37
+        return \OC\Files\Filesystem::$loaded;
38
+    }
39 39
 
40
-	/**
41
-	 * @brief initializes the filesystem for the given user
42
-	 * @param string $uid the Nextcloud username of the user
43
-	 */
44
-	public function setup($uid) {
45
-		\OC_Util::setupFS($uid);
46
-	}
40
+    /**
41
+     * @brief initializes the filesystem for the given user
42
+     * @param string $uid the Nextcloud username of the user
43
+     */
44
+    public function setup($uid) {
45
+        \OC_Util::setupFS($uid);
46
+    }
47 47
 }
Please login to merge, or discard this patch.
apps/federation/lib/Controller/SettingsController.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -34,91 +34,91 @@
 block discarded – undo
34 34
 
35 35
 class SettingsController extends Controller {
36 36
 
37
-	/** @var IL10N */
38
-	private $l;
39
-
40
-	/** @var  TrustedServers */
41
-	private $trustedServers;
42
-
43
-	/**
44
-	 * @param string $AppName
45
-	 * @param IRequest $request
46
-	 * @param IL10N $l10n
47
-	 * @param TrustedServers $trustedServers
48
-	 */
49
-	public function __construct($AppName,
50
-								IRequest $request,
51
-								IL10N $l10n,
52
-								TrustedServers $trustedServers
53
-	) {
54
-		parent::__construct($AppName, $request);
55
-		$this->l = $l10n;
56
-		$this->trustedServers = $trustedServers;
57
-	}
58
-
59
-
60
-	/**
61
-	 * add server to the list of trusted Nextclouds
62
-	 *
63
-	 * @param string $url
64
-	 * @return DataResponse
65
-	 * @throws HintException
66
-	 */
67
-	public function addServer($url) {
68
-		$this->checkServer($url);
69
-		$id = $this->trustedServers->addServer($url);
70
-
71
-		return new DataResponse(
72
-			[
73
-				'url' => $url,
74
-				'id' => $id,
75
-				'message' => (string) $this->l->t('Added to the list of trusted servers')
76
-			]
77
-		);
78
-	}
79
-
80
-	/**
81
-	 * add server to the list of trusted Nextclouds
82
-	 *
83
-	 * @param int $id
84
-	 * @return DataResponse
85
-	 */
86
-	public function removeServer($id) {
87
-		$this->trustedServers->removeServer($id);
88
-		return new DataResponse();
89
-	}
90
-
91
-	/**
92
-	 * enable/disable to automatically add servers to the list of trusted servers
93
-	 * once a federated share was created and accepted successfully
94
-	 *
95
-	 * @param bool $autoAddServers
96
-	 */
97
-	public function autoAddServers($autoAddServers) {
98
-		$this->trustedServers->setAutoAddServers($autoAddServers);
99
-	}
100
-
101
-	/**
102
-	 * check if the server should be added to the list of trusted servers or not
103
-	 *
104
-	 * @param string $url
105
-	 * @return bool
106
-	 * @throws HintException
107
-	 */
108
-	protected function checkServer($url) {
109
-		if ($this->trustedServers->isTrustedServer($url) === true) {
110
-			$message = 'Server is already in the list of trusted servers.';
111
-			$hint = $this->l->t('Server is already in the list of trusted servers.');
112
-			throw new HintException($message, $hint);
113
-		}
114
-
115
-		if ($this->trustedServers->isOwnCloudServer($url) === false) {
116
-			$message = 'No server to federate with found';
117
-			$hint = $this->l->t('No server to federate with found');
118
-			throw new HintException($message, $hint);
119
-		}
120
-
121
-		return true;
122
-	}
37
+    /** @var IL10N */
38
+    private $l;
39
+
40
+    /** @var  TrustedServers */
41
+    private $trustedServers;
42
+
43
+    /**
44
+     * @param string $AppName
45
+     * @param IRequest $request
46
+     * @param IL10N $l10n
47
+     * @param TrustedServers $trustedServers
48
+     */
49
+    public function __construct($AppName,
50
+                                IRequest $request,
51
+                                IL10N $l10n,
52
+                                TrustedServers $trustedServers
53
+    ) {
54
+        parent::__construct($AppName, $request);
55
+        $this->l = $l10n;
56
+        $this->trustedServers = $trustedServers;
57
+    }
58
+
59
+
60
+    /**
61
+     * add server to the list of trusted Nextclouds
62
+     *
63
+     * @param string $url
64
+     * @return DataResponse
65
+     * @throws HintException
66
+     */
67
+    public function addServer($url) {
68
+        $this->checkServer($url);
69
+        $id = $this->trustedServers->addServer($url);
70
+
71
+        return new DataResponse(
72
+            [
73
+                'url' => $url,
74
+                'id' => $id,
75
+                'message' => (string) $this->l->t('Added to the list of trusted servers')
76
+            ]
77
+        );
78
+    }
79
+
80
+    /**
81
+     * add server to the list of trusted Nextclouds
82
+     *
83
+     * @param int $id
84
+     * @return DataResponse
85
+     */
86
+    public function removeServer($id) {
87
+        $this->trustedServers->removeServer($id);
88
+        return new DataResponse();
89
+    }
90
+
91
+    /**
92
+     * enable/disable to automatically add servers to the list of trusted servers
93
+     * once a federated share was created and accepted successfully
94
+     *
95
+     * @param bool $autoAddServers
96
+     */
97
+    public function autoAddServers($autoAddServers) {
98
+        $this->trustedServers->setAutoAddServers($autoAddServers);
99
+    }
100
+
101
+    /**
102
+     * check if the server should be added to the list of trusted servers or not
103
+     *
104
+     * @param string $url
105
+     * @return bool
106
+     * @throws HintException
107
+     */
108
+    protected function checkServer($url) {
109
+        if ($this->trustedServers->isTrustedServer($url) === true) {
110
+            $message = 'Server is already in the list of trusted servers.';
111
+            $hint = $this->l->t('Server is already in the list of trusted servers.');
112
+            throw new HintException($message, $hint);
113
+        }
114
+
115
+        if ($this->trustedServers->isOwnCloudServer($url) === false) {
116
+            $message = 'No server to federate with found';
117
+            $hint = $this->l->t('No server to federate with found');
118
+            throw new HintException($message, $hint);
119
+        }
120
+
121
+        return true;
122
+    }
123 123
 
124 124
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Migration/StorageMigrator.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -42,97 +42,97 @@
 block discarded – undo
42 42
  * Migrate mount config from mount.json to the database
43 43
  */
44 44
 class StorageMigrator {
45
-	/**
46
-	 * @var BackendService
47
-	 */
48
-	private $backendService;
45
+    /**
46
+     * @var BackendService
47
+     */
48
+    private $backendService;
49 49
 
50
-	/**
51
-	 * @var DBConfigService
52
-	 */
53
-	private $dbConfig;
50
+    /**
51
+     * @var DBConfigService
52
+     */
53
+    private $dbConfig;
54 54
 
55
-	/**
56
-	 * @var IConfig
57
-	 */
58
-	private $config;
55
+    /**
56
+     * @var IConfig
57
+     */
58
+    private $config;
59 59
 
60
-	/**
61
-	 * @var IDBConnection
62
-	 */
63
-	private $connection;
60
+    /**
61
+     * @var IDBConnection
62
+     */
63
+    private $connection;
64 64
 
65
-	/**
66
-	 * @var ILogger
67
-	 */
68
-	private $logger;
65
+    /**
66
+     * @var ILogger
67
+     */
68
+    private $logger;
69 69
 
70
-	/** @var IUserMountCache  */
71
-	private $userMountCache;
70
+    /** @var IUserMountCache  */
71
+    private $userMountCache;
72 72
 
73
-	/**
74
-	 * StorageMigrator constructor.
75
-	 *
76
-	 * @param BackendService $backendService
77
-	 * @param DBConfigService $dbConfig
78
-	 * @param IConfig $config
79
-	 * @param IDBConnection $connection
80
-	 * @param ILogger $logger
81
-	 * @param IUserMountCache $userMountCache
82
-	 */
83
-	public function __construct(
84
-		BackendService $backendService,
85
-		DBConfigService $dbConfig,
86
-		IConfig $config,
87
-		IDBConnection $connection,
88
-		ILogger $logger,
89
-		IUserMountCache $userMountCache
90
-	) {
91
-		$this->backendService = $backendService;
92
-		$this->dbConfig = $dbConfig;
93
-		$this->config = $config;
94
-		$this->connection = $connection;
95
-		$this->logger = $logger;
96
-		$this->userMountCache = $userMountCache;
97
-	}
73
+    /**
74
+     * StorageMigrator constructor.
75
+     *
76
+     * @param BackendService $backendService
77
+     * @param DBConfigService $dbConfig
78
+     * @param IConfig $config
79
+     * @param IDBConnection $connection
80
+     * @param ILogger $logger
81
+     * @param IUserMountCache $userMountCache
82
+     */
83
+    public function __construct(
84
+        BackendService $backendService,
85
+        DBConfigService $dbConfig,
86
+        IConfig $config,
87
+        IDBConnection $connection,
88
+        ILogger $logger,
89
+        IUserMountCache $userMountCache
90
+    ) {
91
+        $this->backendService = $backendService;
92
+        $this->dbConfig = $dbConfig;
93
+        $this->config = $config;
94
+        $this->connection = $connection;
95
+        $this->logger = $logger;
96
+        $this->userMountCache = $userMountCache;
97
+    }
98 98
 
99
-	private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService) {
100
-		$existingStorage = $legacyService->getAllStorages();
99
+    private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService) {
100
+        $existingStorage = $legacyService->getAllStorages();
101 101
 
102
-		$this->connection->beginTransaction();
103
-		try {
104
-			foreach ($existingStorage as $storage) {
105
-				$mountOptions = $storage->getMountOptions();
106
-				if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) {
107
-					// existing mounts must have sharing enabled by default to avoid surprises
108
-					$mountOptions['enable_sharing'] = true;
109
-					$storage->setMountOptions($mountOptions);
110
-				}
111
-				$storageService->addStorage($storage);
112
-			}
113
-			$this->connection->commit();
114
-		} catch (\Exception $e) {
115
-			$this->logger->logException($e);
116
-			$this->connection->rollBack();
117
-		}
118
-	}
102
+        $this->connection->beginTransaction();
103
+        try {
104
+            foreach ($existingStorage as $storage) {
105
+                $mountOptions = $storage->getMountOptions();
106
+                if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) {
107
+                    // existing mounts must have sharing enabled by default to avoid surprises
108
+                    $mountOptions['enable_sharing'] = true;
109
+                    $storage->setMountOptions($mountOptions);
110
+                }
111
+                $storageService->addStorage($storage);
112
+            }
113
+            $this->connection->commit();
114
+        } catch (\Exception $e) {
115
+            $this->logger->logException($e);
116
+            $this->connection->rollBack();
117
+        }
118
+    }
119 119
 
120
-	/**
121
-	 * Migrate personal storages configured by the current user
122
-	 *
123
-	 * @param IUser $user
124
-	 */
125
-	public function migrateUser(IUser $user) {
126
-		$dummySession = new DummyUserSession();
127
-		$dummySession->setUser($user);
128
-		$userId = $user->getUID();
129
-		$userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0');
130
-		if (version_compare($userVersion, '0.5.0', '<')) {
131
-			$this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0');
132
-			$legacyService = new UserLegacyStoragesService($this->backendService, $dummySession);
133
-			$storageService = new UserStoragesService($this->backendService, $this->dbConfig, $dummySession, $this->userMountCache);
120
+    /**
121
+     * Migrate personal storages configured by the current user
122
+     *
123
+     * @param IUser $user
124
+     */
125
+    public function migrateUser(IUser $user) {
126
+        $dummySession = new DummyUserSession();
127
+        $dummySession->setUser($user);
128
+        $userId = $user->getUID();
129
+        $userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0');
130
+        if (version_compare($userVersion, '0.5.0', '<')) {
131
+            $this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0');
132
+            $legacyService = new UserLegacyStoragesService($this->backendService, $dummySession);
133
+            $storageService = new UserStoragesService($this->backendService, $this->dbConfig, $dummySession, $this->userMountCache);
134 134
 
135
-			$this->migrate($legacyService, $storageService);
136
-		}
137
-	}
135
+            $this->migrate($legacyService, $storageService);
136
+        }
137
+    }
138 138
 }
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,6 @@
 block discarded – undo
26 26
 
27 27
 use OCA\Files_External\Service\BackendService;
28 28
 use OCA\Files_External\Service\DBConfigService;
29
-use OCA\Files_External\Service\GlobalLegacyStoragesService;
30 29
 use OCA\Files_External\Service\LegacyStoragesService;
31 30
 use OCA\Files_External\Service\StoragesService;
32 31
 use OCA\Files_External\Service\UserLegacyStoragesService;
Please login to merge, or discard this patch.
apps/files_sharing/lib/Scanner.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -31,52 +31,52 @@
 block discarded – undo
31 31
  * Scanner for SharedStorage
32 32
  */
33 33
 class Scanner extends \OC\Files\Cache\Scanner {
34
-	/**
35
-	 * @var \OCA\Files_Sharing\SharedStorage $storage
36
-	 */
37
-	protected $storage;
34
+    /**
35
+     * @var \OCA\Files_Sharing\SharedStorage $storage
36
+     */
37
+    protected $storage;
38 38
 
39
-	private $sourceScanner;
39
+    private $sourceScanner;
40 40
 
41
-	/**
42
-	 * Returns metadata from the shared storage, but
43
-	 * with permissions from the source storage.
44
-	 *
45
-	 * @param string $path path of the file for which to retrieve metadata
46
-	 *
47
-	 * @return array an array of metadata of the file
48
-	 */
49
-	public function getData($path) {
50
-		$data = parent::getData($path);
51
-		if ($data === null) {
52
-			return null;
53
-		}
54
-		$internalPath = $this->storage->getUnjailedPath($path);
55
-		$data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath);
56
-		return $data;
57
-	}
41
+    /**
42
+     * Returns metadata from the shared storage, but
43
+     * with permissions from the source storage.
44
+     *
45
+     * @param string $path path of the file for which to retrieve metadata
46
+     *
47
+     * @return array an array of metadata of the file
48
+     */
49
+    public function getData($path) {
50
+        $data = parent::getData($path);
51
+        if ($data === null) {
52
+            return null;
53
+        }
54
+        $internalPath = $this->storage->getUnjailedPath($path);
55
+        $data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath);
56
+        return $data;
57
+    }
58 58
 
59
-	private function getSourceScanner() {
60
-		if ($this->sourceScanner) {
61
-			return $this->sourceScanner;
62
-		}
63
-		if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
64
-			/** @var \OC\Files\Storage\Storage $storage */
65
-			list($storage) = $this->storage->resolvePath('');
66
-			$this->sourceScanner = $storage->getScanner();
67
-			return $this->sourceScanner;
68
-		} else {
69
-			return null;
70
-		}
71
-	}
59
+    private function getSourceScanner() {
60
+        if ($this->sourceScanner) {
61
+            return $this->sourceScanner;
62
+        }
63
+        if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
64
+            /** @var \OC\Files\Storage\Storage $storage */
65
+            list($storage) = $this->storage->resolvePath('');
66
+            $this->sourceScanner = $storage->getScanner();
67
+            return $this->sourceScanner;
68
+        } else {
69
+            return null;
70
+        }
71
+    }
72 72
 
73
-	public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) {
74
-		$sourceScanner = $this->getSourceScanner();
75
-		if ($sourceScanner instanceof NoopScanner) {
76
-			return [];
77
-		} else {
78
-			return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock);
79
-		}
80
-	}
73
+    public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) {
74
+        $sourceScanner = $this->getSourceScanner();
75
+        if ($sourceScanner instanceof NoopScanner) {
76
+            return [];
77
+        } else {
78
+            return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock);
79
+        }
80
+    }
81 81
 }
82 82
 
Please login to merge, or discard this patch.
apps/files_sharing/lib/SharedStorage.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	 * @return string
174 174
 	 */
175 175
 	public function getId() {
176
-		return 'shared::' . $this->getMountPoint();
176
+		return 'shared::'.$this->getMountPoint();
177 177
 	}
178 178
 
179 179
 	/**
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 					}
270 270
 			}
271 271
 			$info = array(
272
-				'target' => $this->getMountPoint() . $path,
272
+				'target' => $this->getMountPoint().$path,
273 273
 				'source' => $source,
274 274
 				'mode' => $mode,
275 275
 			);
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 
479 479
 	public function file_get_contents($path) {
480 480
 		$info = [
481
-			'target' => $this->getMountPoint() . '/' . $path,
481
+			'target' => $this->getMountPoint().'/'.$path,
482 482
 			'source' => $this->getUnjailedPath($path),
483 483
 		];
484 484
 		\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 
488 488
 	public function file_put_contents($path, $data) {
489 489
 		$info = [
490
-			'target' => $this->getMountPoint() . '/' . $path,
490
+			'target' => $this->getMountPoint().'/'.$path,
491 491
 			'source' => $this->getUnjailedPath($path),
492 492
 		];
493 493
 		\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
Please login to merge, or discard this patch.
Indentation   +438 added lines, -438 removed lines patch added patch discarded remove patch
@@ -47,442 +47,442 @@
 block discarded – undo
47 47
  */
48 48
 class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage {
49 49
 
50
-	/** @var \OCP\Share\IShare */
51
-	private $superShare;
52
-
53
-	/** @var \OCP\Share\IShare[] */
54
-	private $groupedShares;
55
-
56
-	/**
57
-	 * @var \OC\Files\View
58
-	 */
59
-	private $ownerView;
60
-
61
-	private $initialized = false;
62
-
63
-	/**
64
-	 * @var ICacheEntry
65
-	 */
66
-	private $sourceRootInfo;
67
-
68
-	/** @var string */
69
-	private $user;
70
-
71
-	/**
72
-	 * @var \OCP\ILogger
73
-	 */
74
-	private $logger;
75
-
76
-	/** @var  IStorage */
77
-	private $nonMaskedStorage;
78
-
79
-	private $options;
80
-
81
-	public function __construct($arguments) {
82
-		$this->ownerView = $arguments['ownerView'];
83
-		$this->logger = \OC::$server->getLogger();
84
-
85
-		$this->superShare = $arguments['superShare'];
86
-		$this->groupedShares = $arguments['groupedShares'];
87
-
88
-		$this->user = $arguments['user'];
89
-
90
-		parent::__construct([
91
-			'storage' => null,
92
-			'root' => null,
93
-		]);
94
-	}
95
-
96
-	/**
97
-	 * @return ICacheEntry
98
-	 */
99
-	private function getSourceRootInfo() {
100
-		if (is_null($this->sourceRootInfo)) {
101
-			if (is_null($this->superShare->getNodeCacheEntry())) {
102
-				$this->init();
103
-				$this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath);
104
-			} else {
105
-				$this->sourceRootInfo = $this->superShare->getNodeCacheEntry();
106
-			}
107
-		}
108
-		return $this->sourceRootInfo;
109
-	}
110
-
111
-	private function init() {
112
-		if ($this->initialized) {
113
-			return;
114
-		}
115
-		$this->initialized = true;
116
-		try {
117
-			Filesystem::initMountPoints($this->superShare->getShareOwner());
118
-			$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
119
-			list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath);
120
-			$this->storage = new PermissionsMask([
121
-				'storage' => $this->nonMaskedStorage,
122
-				'mask' => $this->superShare->getPermissions()
123
-			]);
124
-		} catch (NotFoundException $e) {
125
-			// original file not accessible or deleted, set FailedStorage
126
-			$this->storage = new FailedStorage(['exception' => $e]);
127
-			$this->cache = new FailedCache();
128
-			$this->rootPath = '';
129
-		} catch (NoUserException $e) {
130
-			// sharer user deleted, set FailedStorage
131
-			$this->storage = new FailedStorage(['exception' => $e]);
132
-			$this->cache = new FailedCache();
133
-			$this->rootPath = '';
134
-		} catch (\Exception $e) {
135
-			$this->storage = new FailedStorage(['exception' => $e]);
136
-			$this->cache = new FailedCache();
137
-			$this->rootPath = '';
138
-			$this->logger->logException($e);
139
-		}
140
-
141
-		if (!$this->nonMaskedStorage) {
142
-			$this->nonMaskedStorage = $this->storage;
143
-		}
144
-	}
145
-
146
-	/**
147
-	 * @inheritdoc
148
-	 */
149
-	public function instanceOfStorage($class) {
150
-		if ($class === '\OC\Files\Storage\Common') {
151
-			return true;
152
-		}
153
-		if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) {
154
-			return false;
155
-		}
156
-		return parent::instanceOfStorage($class);
157
-	}
158
-
159
-	/**
160
-	 * @return string
161
-	 */
162
-	public function getShareId() {
163
-		return $this->superShare->getId();
164
-	}
165
-
166
-	private function isValid() {
167
-		return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE;
168
-	}
169
-
170
-	/**
171
-	 * get id of the mount point
172
-	 *
173
-	 * @return string
174
-	 */
175
-	public function getId() {
176
-		return 'shared::' . $this->getMountPoint();
177
-	}
178
-
179
-	/**
180
-	 * Get the permissions granted for a shared file
181
-	 *
182
-	 * @param string $target Shared target file path
183
-	 * @return int CRUDS permissions granted
184
-	 */
185
-	public function getPermissions($target = '') {
186
-		if (!$this->isValid()) {
187
-			return 0;
188
-		}
189
-		$permissions = $this->superShare->getPermissions();
190
-		// part files and the mount point always have delete permissions
191
-		if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') {
192
-			$permissions |= \OCP\Constants::PERMISSION_DELETE;
193
-		}
194
-
195
-		if (\OCP\Util::isSharingDisabledForUser()) {
196
-			$permissions &= ~\OCP\Constants::PERMISSION_SHARE;
197
-		}
198
-
199
-		return $permissions;
200
-	}
201
-
202
-	public function isCreatable($path) {
203
-		return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
204
-	}
205
-
206
-	public function isReadable($path) {
207
-		if (!$this->isValid()) {
208
-			return false;
209
-		}
210
-		if (!$this->file_exists($path)) {
211
-			return false;
212
-		}
213
-		/** @var IStorage $storage */
214
-		/** @var string $internalPath */
215
-		list($storage, $internalPath) = $this->resolvePath($path);
216
-		return $storage->isReadable($internalPath);
217
-	}
218
-
219
-	public function isUpdatable($path) {
220
-		return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE);
221
-	}
222
-
223
-	public function isDeletable($path) {
224
-		return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE);
225
-	}
226
-
227
-	public function isSharable($path) {
228
-		if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
229
-			return false;
230
-		}
231
-		return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
232
-	}
233
-
234
-	public function fopen($path, $mode) {
235
-		if ($source = $this->getUnjailedPath($path)) {
236
-			switch ($mode) {
237
-				case 'r+':
238
-				case 'rb+':
239
-				case 'w+':
240
-				case 'wb+':
241
-				case 'x+':
242
-				case 'xb+':
243
-				case 'a+':
244
-				case 'ab+':
245
-				case 'w':
246
-				case 'wb':
247
-				case 'x':
248
-				case 'xb':
249
-				case 'a':
250
-				case 'ab':
251
-					$creatable = $this->isCreatable($path);
252
-					$updatable = $this->isUpdatable($path);
253
-					// if neither permissions given, no need to continue
254
-					if (!$creatable && !$updatable) {
255
-						return false;
256
-					}
257
-
258
-					$exists = $this->file_exists($path);
259
-					// if a file exists, updatable permissions are required
260
-					if ($exists && !$updatable) {
261
-						return false;
262
-					}
263
-
264
-					// part file is allowed if !$creatable but the final file is $updatable
265
-					if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') {
266
-						if (!$exists && !$creatable) {
267
-							return false;
268
-						}
269
-					}
270
-			}
271
-			$info = array(
272
-				'target' => $this->getMountPoint() . $path,
273
-				'source' => $source,
274
-				'mode' => $mode,
275
-			);
276
-			\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
277
-			return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode);
278
-		}
279
-		return false;
280
-	}
281
-
282
-	/**
283
-	 * see http://php.net/manual/en/function.rename.php
284
-	 *
285
-	 * @param string $path1
286
-	 * @param string $path2
287
-	 * @return bool
288
-	 */
289
-	public function rename($path1, $path2) {
290
-		$this->init();
291
-		$isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
292
-		$targetExists = $this->file_exists($path2);
293
-		$sameFodler = dirname($path1) === dirname($path2);
294
-
295
-		if ($targetExists || ($sameFodler && !$isPartFile)) {
296
-			if (!$this->isUpdatable('')) {
297
-				return false;
298
-			}
299
-		} else {
300
-			if (!$this->isCreatable('')) {
301
-				return false;
302
-			}
303
-		}
304
-
305
-		return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
306
-	}
307
-
308
-	/**
309
-	 * return mount point of share, relative to data/user/files
310
-	 *
311
-	 * @return string
312
-	 */
313
-	public function getMountPoint() {
314
-		return $this->superShare->getTarget();
315
-	}
316
-
317
-	/**
318
-	 * @param string $path
319
-	 */
320
-	public function setMountPoint($path) {
321
-		$this->superShare->setTarget($path);
322
-
323
-		foreach ($this->groupedShares as $share) {
324
-			$share->setTarget($path);
325
-		}
326
-	}
327
-
328
-	/**
329
-	 * get the user who shared the file
330
-	 *
331
-	 * @return string
332
-	 */
333
-	public function getSharedFrom() {
334
-		return $this->superShare->getShareOwner();
335
-	}
336
-
337
-	/**
338
-	 * @return \OCP\Share\IShare
339
-	 */
340
-	public function getShare() {
341
-		return $this->superShare;
342
-	}
343
-
344
-	/**
345
-	 * return share type, can be "file" or "folder"
346
-	 *
347
-	 * @return string
348
-	 */
349
-	public function getItemType() {
350
-		return $this->superShare->getNodeType();
351
-	}
352
-
353
-	/**
354
-	 * @param string $path
355
-	 * @param null $storage
356
-	 * @return Cache
357
-	 */
358
-	public function getCache($path = '', $storage = null) {
359
-		if ($this->cache) {
360
-			return $this->cache;
361
-		}
362
-		if (!$storage) {
363
-			$storage = $this;
364
-		}
365
-		if ($this->storage instanceof FailedStorage) {
366
-			return new FailedCache();
367
-		}
368
-		$this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare);
369
-		return $this->cache;
370
-	}
371
-
372
-	public function getScanner($path = '', $storage = null) {
373
-		if (!$storage) {
374
-			$storage = $this;
375
-		}
376
-		return new \OCA\Files_Sharing\Scanner($storage);
377
-	}
378
-
379
-	public function getOwner($path) {
380
-		return $this->superShare->getShareOwner();
381
-	}
382
-
383
-	/**
384
-	 * unshare complete storage, also the grouped shares
385
-	 *
386
-	 * @return bool
387
-	 */
388
-	public function unshareStorage() {
389
-		foreach ($this->groupedShares as $share) {
390
-			\OC::$server->getShareManager()->deleteFromSelf($share, $this->user);
391
-		}
392
-		return true;
393
-	}
394
-
395
-	/**
396
-	 * @param string $path
397
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
398
-	 * @param \OCP\Lock\ILockingProvider $provider
399
-	 * @throws \OCP\Lock\LockedException
400
-	 */
401
-	public function acquireLock($path, $type, ILockingProvider $provider) {
402
-		/** @var \OCP\Files\Storage $targetStorage */
403
-		list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
404
-		$targetStorage->acquireLock($targetInternalPath, $type, $provider);
405
-		// lock the parent folders of the owner when locking the share as recipient
406
-		if ($path === '') {
407
-			$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
408
-			$this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
409
-		}
410
-	}
411
-
412
-	/**
413
-	 * @param string $path
414
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
415
-	 * @param \OCP\Lock\ILockingProvider $provider
416
-	 */
417
-	public function releaseLock($path, $type, ILockingProvider $provider) {
418
-		/** @var \OCP\Files\Storage $targetStorage */
419
-		list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
420
-		$targetStorage->releaseLock($targetInternalPath, $type, $provider);
421
-		// unlock the parent folders of the owner when unlocking the share as recipient
422
-		if ($path === '') {
423
-			$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
424
-			$this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
425
-		}
426
-	}
427
-
428
-	/**
429
-	 * @param string $path
430
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
431
-	 * @param \OCP\Lock\ILockingProvider $provider
432
-	 */
433
-	public function changeLock($path, $type, ILockingProvider $provider) {
434
-		/** @var \OCP\Files\Storage $targetStorage */
435
-		list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
436
-		$targetStorage->changeLock($targetInternalPath, $type, $provider);
437
-	}
438
-
439
-	/**
440
-	 * @return array [ available, last_checked ]
441
-	 */
442
-	public function getAvailability() {
443
-		// shares do not participate in availability logic
444
-		return [
445
-			'available' => true,
446
-			'last_checked' => 0
447
-		];
448
-	}
449
-
450
-	/**
451
-	 * @param bool $available
452
-	 */
453
-	public function setAvailability($available) {
454
-		// shares do not participate in availability logic
455
-	}
456
-
457
-	public function getSourceStorage() {
458
-		$this->init();
459
-		return $this->nonMaskedStorage;
460
-	}
461
-
462
-	public function getWrapperStorage() {
463
-		$this->init();
464
-		return $this->storage;
465
-	}
466
-
467
-	public function file_get_contents($path) {
468
-		$info = [
469
-			'target' => $this->getMountPoint() . '/' . $path,
470
-			'source' => $this->getUnjailedPath($path),
471
-		];
472
-		\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
473
-		return parent::file_get_contents($path);
474
-	}
475
-
476
-	public function file_put_contents($path, $data) {
477
-		$info = [
478
-			'target' => $this->getMountPoint() . '/' . $path,
479
-			'source' => $this->getUnjailedPath($path),
480
-		];
481
-		\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
482
-		return parent::file_put_contents($path, $data);
483
-	}
484
-
485
-	public function setMountOptions(array $options) {
486
-		$this->mountOptions = $options;
487
-	}
50
+    /** @var \OCP\Share\IShare */
51
+    private $superShare;
52
+
53
+    /** @var \OCP\Share\IShare[] */
54
+    private $groupedShares;
55
+
56
+    /**
57
+     * @var \OC\Files\View
58
+     */
59
+    private $ownerView;
60
+
61
+    private $initialized = false;
62
+
63
+    /**
64
+     * @var ICacheEntry
65
+     */
66
+    private $sourceRootInfo;
67
+
68
+    /** @var string */
69
+    private $user;
70
+
71
+    /**
72
+     * @var \OCP\ILogger
73
+     */
74
+    private $logger;
75
+
76
+    /** @var  IStorage */
77
+    private $nonMaskedStorage;
78
+
79
+    private $options;
80
+
81
+    public function __construct($arguments) {
82
+        $this->ownerView = $arguments['ownerView'];
83
+        $this->logger = \OC::$server->getLogger();
84
+
85
+        $this->superShare = $arguments['superShare'];
86
+        $this->groupedShares = $arguments['groupedShares'];
87
+
88
+        $this->user = $arguments['user'];
89
+
90
+        parent::__construct([
91
+            'storage' => null,
92
+            'root' => null,
93
+        ]);
94
+    }
95
+
96
+    /**
97
+     * @return ICacheEntry
98
+     */
99
+    private function getSourceRootInfo() {
100
+        if (is_null($this->sourceRootInfo)) {
101
+            if (is_null($this->superShare->getNodeCacheEntry())) {
102
+                $this->init();
103
+                $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath);
104
+            } else {
105
+                $this->sourceRootInfo = $this->superShare->getNodeCacheEntry();
106
+            }
107
+        }
108
+        return $this->sourceRootInfo;
109
+    }
110
+
111
+    private function init() {
112
+        if ($this->initialized) {
113
+            return;
114
+        }
115
+        $this->initialized = true;
116
+        try {
117
+            Filesystem::initMountPoints($this->superShare->getShareOwner());
118
+            $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
119
+            list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath);
120
+            $this->storage = new PermissionsMask([
121
+                'storage' => $this->nonMaskedStorage,
122
+                'mask' => $this->superShare->getPermissions()
123
+            ]);
124
+        } catch (NotFoundException $e) {
125
+            // original file not accessible or deleted, set FailedStorage
126
+            $this->storage = new FailedStorage(['exception' => $e]);
127
+            $this->cache = new FailedCache();
128
+            $this->rootPath = '';
129
+        } catch (NoUserException $e) {
130
+            // sharer user deleted, set FailedStorage
131
+            $this->storage = new FailedStorage(['exception' => $e]);
132
+            $this->cache = new FailedCache();
133
+            $this->rootPath = '';
134
+        } catch (\Exception $e) {
135
+            $this->storage = new FailedStorage(['exception' => $e]);
136
+            $this->cache = new FailedCache();
137
+            $this->rootPath = '';
138
+            $this->logger->logException($e);
139
+        }
140
+
141
+        if (!$this->nonMaskedStorage) {
142
+            $this->nonMaskedStorage = $this->storage;
143
+        }
144
+    }
145
+
146
+    /**
147
+     * @inheritdoc
148
+     */
149
+    public function instanceOfStorage($class) {
150
+        if ($class === '\OC\Files\Storage\Common') {
151
+            return true;
152
+        }
153
+        if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) {
154
+            return false;
155
+        }
156
+        return parent::instanceOfStorage($class);
157
+    }
158
+
159
+    /**
160
+     * @return string
161
+     */
162
+    public function getShareId() {
163
+        return $this->superShare->getId();
164
+    }
165
+
166
+    private function isValid() {
167
+        return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE;
168
+    }
169
+
170
+    /**
171
+     * get id of the mount point
172
+     *
173
+     * @return string
174
+     */
175
+    public function getId() {
176
+        return 'shared::' . $this->getMountPoint();
177
+    }
178
+
179
+    /**
180
+     * Get the permissions granted for a shared file
181
+     *
182
+     * @param string $target Shared target file path
183
+     * @return int CRUDS permissions granted
184
+     */
185
+    public function getPermissions($target = '') {
186
+        if (!$this->isValid()) {
187
+            return 0;
188
+        }
189
+        $permissions = $this->superShare->getPermissions();
190
+        // part files and the mount point always have delete permissions
191
+        if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') {
192
+            $permissions |= \OCP\Constants::PERMISSION_DELETE;
193
+        }
194
+
195
+        if (\OCP\Util::isSharingDisabledForUser()) {
196
+            $permissions &= ~\OCP\Constants::PERMISSION_SHARE;
197
+        }
198
+
199
+        return $permissions;
200
+    }
201
+
202
+    public function isCreatable($path) {
203
+        return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
204
+    }
205
+
206
+    public function isReadable($path) {
207
+        if (!$this->isValid()) {
208
+            return false;
209
+        }
210
+        if (!$this->file_exists($path)) {
211
+            return false;
212
+        }
213
+        /** @var IStorage $storage */
214
+        /** @var string $internalPath */
215
+        list($storage, $internalPath) = $this->resolvePath($path);
216
+        return $storage->isReadable($internalPath);
217
+    }
218
+
219
+    public function isUpdatable($path) {
220
+        return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE);
221
+    }
222
+
223
+    public function isDeletable($path) {
224
+        return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE);
225
+    }
226
+
227
+    public function isSharable($path) {
228
+        if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
229
+            return false;
230
+        }
231
+        return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
232
+    }
233
+
234
+    public function fopen($path, $mode) {
235
+        if ($source = $this->getUnjailedPath($path)) {
236
+            switch ($mode) {
237
+                case 'r+':
238
+                case 'rb+':
239
+                case 'w+':
240
+                case 'wb+':
241
+                case 'x+':
242
+                case 'xb+':
243
+                case 'a+':
244
+                case 'ab+':
245
+                case 'w':
246
+                case 'wb':
247
+                case 'x':
248
+                case 'xb':
249
+                case 'a':
250
+                case 'ab':
251
+                    $creatable = $this->isCreatable($path);
252
+                    $updatable = $this->isUpdatable($path);
253
+                    // if neither permissions given, no need to continue
254
+                    if (!$creatable && !$updatable) {
255
+                        return false;
256
+                    }
257
+
258
+                    $exists = $this->file_exists($path);
259
+                    // if a file exists, updatable permissions are required
260
+                    if ($exists && !$updatable) {
261
+                        return false;
262
+                    }
263
+
264
+                    // part file is allowed if !$creatable but the final file is $updatable
265
+                    if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') {
266
+                        if (!$exists && !$creatable) {
267
+                            return false;
268
+                        }
269
+                    }
270
+            }
271
+            $info = array(
272
+                'target' => $this->getMountPoint() . $path,
273
+                'source' => $source,
274
+                'mode' => $mode,
275
+            );
276
+            \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
277
+            return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode);
278
+        }
279
+        return false;
280
+    }
281
+
282
+    /**
283
+     * see http://php.net/manual/en/function.rename.php
284
+     *
285
+     * @param string $path1
286
+     * @param string $path2
287
+     * @return bool
288
+     */
289
+    public function rename($path1, $path2) {
290
+        $this->init();
291
+        $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
292
+        $targetExists = $this->file_exists($path2);
293
+        $sameFodler = dirname($path1) === dirname($path2);
294
+
295
+        if ($targetExists || ($sameFodler && !$isPartFile)) {
296
+            if (!$this->isUpdatable('')) {
297
+                return false;
298
+            }
299
+        } else {
300
+            if (!$this->isCreatable('')) {
301
+                return false;
302
+            }
303
+        }
304
+
305
+        return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
306
+    }
307
+
308
+    /**
309
+     * return mount point of share, relative to data/user/files
310
+     *
311
+     * @return string
312
+     */
313
+    public function getMountPoint() {
314
+        return $this->superShare->getTarget();
315
+    }
316
+
317
+    /**
318
+     * @param string $path
319
+     */
320
+    public function setMountPoint($path) {
321
+        $this->superShare->setTarget($path);
322
+
323
+        foreach ($this->groupedShares as $share) {
324
+            $share->setTarget($path);
325
+        }
326
+    }
327
+
328
+    /**
329
+     * get the user who shared the file
330
+     *
331
+     * @return string
332
+     */
333
+    public function getSharedFrom() {
334
+        return $this->superShare->getShareOwner();
335
+    }
336
+
337
+    /**
338
+     * @return \OCP\Share\IShare
339
+     */
340
+    public function getShare() {
341
+        return $this->superShare;
342
+    }
343
+
344
+    /**
345
+     * return share type, can be "file" or "folder"
346
+     *
347
+     * @return string
348
+     */
349
+    public function getItemType() {
350
+        return $this->superShare->getNodeType();
351
+    }
352
+
353
+    /**
354
+     * @param string $path
355
+     * @param null $storage
356
+     * @return Cache
357
+     */
358
+    public function getCache($path = '', $storage = null) {
359
+        if ($this->cache) {
360
+            return $this->cache;
361
+        }
362
+        if (!$storage) {
363
+            $storage = $this;
364
+        }
365
+        if ($this->storage instanceof FailedStorage) {
366
+            return new FailedCache();
367
+        }
368
+        $this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare);
369
+        return $this->cache;
370
+    }
371
+
372
+    public function getScanner($path = '', $storage = null) {
373
+        if (!$storage) {
374
+            $storage = $this;
375
+        }
376
+        return new \OCA\Files_Sharing\Scanner($storage);
377
+    }
378
+
379
+    public function getOwner($path) {
380
+        return $this->superShare->getShareOwner();
381
+    }
382
+
383
+    /**
384
+     * unshare complete storage, also the grouped shares
385
+     *
386
+     * @return bool
387
+     */
388
+    public function unshareStorage() {
389
+        foreach ($this->groupedShares as $share) {
390
+            \OC::$server->getShareManager()->deleteFromSelf($share, $this->user);
391
+        }
392
+        return true;
393
+    }
394
+
395
+    /**
396
+     * @param string $path
397
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
398
+     * @param \OCP\Lock\ILockingProvider $provider
399
+     * @throws \OCP\Lock\LockedException
400
+     */
401
+    public function acquireLock($path, $type, ILockingProvider $provider) {
402
+        /** @var \OCP\Files\Storage $targetStorage */
403
+        list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
404
+        $targetStorage->acquireLock($targetInternalPath, $type, $provider);
405
+        // lock the parent folders of the owner when locking the share as recipient
406
+        if ($path === '') {
407
+            $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
408
+            $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
409
+        }
410
+    }
411
+
412
+    /**
413
+     * @param string $path
414
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
415
+     * @param \OCP\Lock\ILockingProvider $provider
416
+     */
417
+    public function releaseLock($path, $type, ILockingProvider $provider) {
418
+        /** @var \OCP\Files\Storage $targetStorage */
419
+        list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
420
+        $targetStorage->releaseLock($targetInternalPath, $type, $provider);
421
+        // unlock the parent folders of the owner when unlocking the share as recipient
422
+        if ($path === '') {
423
+            $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
424
+            $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
425
+        }
426
+    }
427
+
428
+    /**
429
+     * @param string $path
430
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
431
+     * @param \OCP\Lock\ILockingProvider $provider
432
+     */
433
+    public function changeLock($path, $type, ILockingProvider $provider) {
434
+        /** @var \OCP\Files\Storage $targetStorage */
435
+        list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
436
+        $targetStorage->changeLock($targetInternalPath, $type, $provider);
437
+    }
438
+
439
+    /**
440
+     * @return array [ available, last_checked ]
441
+     */
442
+    public function getAvailability() {
443
+        // shares do not participate in availability logic
444
+        return [
445
+            'available' => true,
446
+            'last_checked' => 0
447
+        ];
448
+    }
449
+
450
+    /**
451
+     * @param bool $available
452
+     */
453
+    public function setAvailability($available) {
454
+        // shares do not participate in availability logic
455
+    }
456
+
457
+    public function getSourceStorage() {
458
+        $this->init();
459
+        return $this->nonMaskedStorage;
460
+    }
461
+
462
+    public function getWrapperStorage() {
463
+        $this->init();
464
+        return $this->storage;
465
+    }
466
+
467
+    public function file_get_contents($path) {
468
+        $info = [
469
+            'target' => $this->getMountPoint() . '/' . $path,
470
+            'source' => $this->getUnjailedPath($path),
471
+        ];
472
+        \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
473
+        return parent::file_get_contents($path);
474
+    }
475
+
476
+    public function file_put_contents($path, $data) {
477
+        $info = [
478
+            'target' => $this->getMountPoint() . '/' . $path,
479
+            'source' => $this->getUnjailedPath($path),
480
+        ];
481
+        \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
482
+        return parent::file_put_contents($path, $data);
483
+    }
484
+
485
+    public function setMountOptions(array $options) {
486
+        $this->mountOptions = $options;
487
+    }
488 488
 }
Please login to merge, or discard this patch.