Passed
Push — master ( cdb1d3...2cae54 )
by Morris
12:34 queued 10s
created
lib/private/Template/ResourceLocator.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 				$this->doFind($resource);
76 76
 			} catch (ResourceNotFoundException $e) {
77 77
 				$resourceApp = substr($resource, 0, strpos($resource, '/'));
78
-				$this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
78
+				$this->logger->debug('Could not find resource file "'.$e->getResourcePath().'"', ['app' => $resourceApp]);
79 79
 			}
80 80
 		}
81 81
 		if (!empty($this->theme)) {
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 					$this->doFindTheme($resource);
85 85
 				} catch (ResourceNotFoundException $e) {
86 86
 					$resourceApp = substr($resource, 0, strpos($resource, '/'));
87
-					$this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
87
+					$this->logger->debug('Could not find resource file in theme "'.$e->getResourcePath().'"', ['app' => $resourceApp]);
88 88
 				}
89 89
 			}
90 90
 		}
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 		}
159 159
 		$this->resources[] = [$root, $webRoot, $file];
160 160
 
161
-		if ($throw && !is_file($root . '/' . $file)) {
161
+		if ($throw && !is_file($root.'/'.$file)) {
162 162
 			throw new ResourceNotFoundException($file, $webRoot);
163 163
 		}
164 164
 	}
Please login to merge, or discard this patch.
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -31,172 +31,172 @@
 block discarded – undo
31 31
 namespace OC\Template;
32 32
 
33 33
 abstract class ResourceLocator {
34
-	protected $theme;
35
-
36
-	protected $mapping;
37
-	protected $serverroot;
38
-	protected $thirdpartyroot;
39
-	protected $webroot;
40
-
41
-	protected $resources = [];
42
-
43
-	/** @var \OCP\ILogger */
44
-	protected $logger;
45
-
46
-	/**
47
-	 * @param \OCP\ILogger $logger
48
-	 * @param string $theme
49
-	 * @param array $core_map
50
-	 * @param array $party_map
51
-	 */
52
-	public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) {
53
-		$this->logger = $logger;
54
-		$this->theme = $theme;
55
-		$this->mapping = $core_map + $party_map;
56
-		$this->serverroot = key($core_map);
57
-		$this->thirdpartyroot = key($party_map);
58
-		$this->webroot = $this->mapping[$this->serverroot];
59
-	}
60
-
61
-	/**
62
-	 * @param string $resource
63
-	 */
64
-	abstract public function doFind($resource);
65
-
66
-	/**
67
-	 * @param string $resource
68
-	 */
69
-	abstract public function doFindTheme($resource);
70
-
71
-	/**
72
-	 * Finds the resources and adds them to the list
73
-	 *
74
-	 * @param array $resources
75
-	 */
76
-	public function find($resources) {
77
-		foreach ($resources as $resource) {
78
-			try {
79
-				$this->doFind($resource);
80
-			} catch (ResourceNotFoundException $e) {
81
-				$resourceApp = substr($resource, 0, strpos($resource, '/'));
82
-				$this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
83
-			}
84
-		}
85
-		if (!empty($this->theme)) {
86
-			foreach ($resources as $resource) {
87
-				try {
88
-					$this->doFindTheme($resource);
89
-				} catch (ResourceNotFoundException $e) {
90
-					$resourceApp = substr($resource, 0, strpos($resource, '/'));
91
-					$this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
92
-				}
93
-			}
94
-		}
95
-	}
96
-
97
-	/**
98
-	 * append the $file resource if exist at $root
99
-	 *
100
-	 * @param string $root path to check
101
-	 * @param string $file the filename
102
-	 * @param string|null $webRoot base for path, default map $root to $webRoot
103
-	 * @return bool True if the resource was found, false otherwise
104
-	 */
105
-	protected function appendIfExist($root, $file, $webRoot = null) {
106
-		if (is_file($root.'/'.$file)) {
107
-			$this->append($root, $file, $webRoot, false);
108
-			return true;
109
-		}
110
-		return false;
111
-	}
112
-
113
-	/**
114
-	 * Attempt to find the webRoot
115
-	 *
116
-	 * traverse the potential web roots upwards in the path
117
-	 *
118
-	 * example:
119
-	 *   - root: /srv/www/apps/myapp
120
-	 *   - available mappings: ['/srv/www']
121
-	 *
122
-	 * First we check if a mapping for /srv/www/apps/myapp is available,
123
-	 * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
124
-	 * valid web root
125
-	 *
126
-	 * @param string $root
127
-	 * @return string|null The web root or null on failure
128
-	 */
129
-	protected function findWebRoot($root) {
130
-		$webRoot = null;
131
-		$tmpRoot = $root;
132
-
133
-		while ($webRoot === null) {
134
-			if (isset($this->mapping[$tmpRoot])) {
135
-				$webRoot = $this->mapping[$tmpRoot];
136
-				break;
137
-			}
138
-
139
-			if ($tmpRoot === '/') {
140
-				break;
141
-			}
142
-
143
-			$tmpRoot = dirname($tmpRoot);
144
-		}
145
-
146
-		if ($webRoot === null) {
147
-			$realpath = realpath($root);
148
-
149
-			if ($realpath && ($realpath !== $root)) {
150
-				return $this->findWebRoot($realpath);
151
-			}
152
-		}
153
-
154
-		return $webRoot;
155
-	}
156
-
157
-	/**
158
-	 * append the $file resource at $root
159
-	 *
160
-	 * @param string $root path to check
161
-	 * @param string $file the filename
162
-	 * @param string|null $webRoot base for path, default map $root to $webRoot
163
-	 * @param bool $throw Throw an exception, when the route does not exist
164
-	 * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing
165
-	 */
166
-	protected function append($root, $file, $webRoot = null, $throw = true) {
167
-		if (!is_string($root)) {
168
-			if ($throw) {
169
-				throw new ResourceNotFoundException($file, $webRoot);
170
-			}
171
-			return;
172
-		}
173
-
174
-		if (!$webRoot) {
175
-			$webRoot = $this->findWebRoot($root);
176
-
177
-			if ($webRoot === null) {
178
-				$webRoot = '';
179
-				$this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
180
-					'app' => 'lib',
181
-					'root' => $root,
182
-					'file' => $file,
183
-					'webRoot' => $webRoot,
184
-					'throw' => $throw ? 'true' : 'false'
185
-				]);
186
-			}
187
-		}
188
-		$this->resources[] = [$root, $webRoot, $file];
189
-
190
-		if ($throw && !is_file($root . '/' . $file)) {
191
-			throw new ResourceNotFoundException($file, $webRoot);
192
-		}
193
-	}
194
-
195
-	/**
196
-	 * Returns the list of all resources that should be loaded
197
-	 * @return array
198
-	 */
199
-	public function getResources() {
200
-		return $this->resources;
201
-	}
34
+    protected $theme;
35
+
36
+    protected $mapping;
37
+    protected $serverroot;
38
+    protected $thirdpartyroot;
39
+    protected $webroot;
40
+
41
+    protected $resources = [];
42
+
43
+    /** @var \OCP\ILogger */
44
+    protected $logger;
45
+
46
+    /**
47
+     * @param \OCP\ILogger $logger
48
+     * @param string $theme
49
+     * @param array $core_map
50
+     * @param array $party_map
51
+     */
52
+    public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) {
53
+        $this->logger = $logger;
54
+        $this->theme = $theme;
55
+        $this->mapping = $core_map + $party_map;
56
+        $this->serverroot = key($core_map);
57
+        $this->thirdpartyroot = key($party_map);
58
+        $this->webroot = $this->mapping[$this->serverroot];
59
+    }
60
+
61
+    /**
62
+     * @param string $resource
63
+     */
64
+    abstract public function doFind($resource);
65
+
66
+    /**
67
+     * @param string $resource
68
+     */
69
+    abstract public function doFindTheme($resource);
70
+
71
+    /**
72
+     * Finds the resources and adds them to the list
73
+     *
74
+     * @param array $resources
75
+     */
76
+    public function find($resources) {
77
+        foreach ($resources as $resource) {
78
+            try {
79
+                $this->doFind($resource);
80
+            } catch (ResourceNotFoundException $e) {
81
+                $resourceApp = substr($resource, 0, strpos($resource, '/'));
82
+                $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
83
+            }
84
+        }
85
+        if (!empty($this->theme)) {
86
+            foreach ($resources as $resource) {
87
+                try {
88
+                    $this->doFindTheme($resource);
89
+                } catch (ResourceNotFoundException $e) {
90
+                    $resourceApp = substr($resource, 0, strpos($resource, '/'));
91
+                    $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
92
+                }
93
+            }
94
+        }
95
+    }
96
+
97
+    /**
98
+     * append the $file resource if exist at $root
99
+     *
100
+     * @param string $root path to check
101
+     * @param string $file the filename
102
+     * @param string|null $webRoot base for path, default map $root to $webRoot
103
+     * @return bool True if the resource was found, false otherwise
104
+     */
105
+    protected function appendIfExist($root, $file, $webRoot = null) {
106
+        if (is_file($root.'/'.$file)) {
107
+            $this->append($root, $file, $webRoot, false);
108
+            return true;
109
+        }
110
+        return false;
111
+    }
112
+
113
+    /**
114
+     * Attempt to find the webRoot
115
+     *
116
+     * traverse the potential web roots upwards in the path
117
+     *
118
+     * example:
119
+     *   - root: /srv/www/apps/myapp
120
+     *   - available mappings: ['/srv/www']
121
+     *
122
+     * First we check if a mapping for /srv/www/apps/myapp is available,
123
+     * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
124
+     * valid web root
125
+     *
126
+     * @param string $root
127
+     * @return string|null The web root or null on failure
128
+     */
129
+    protected function findWebRoot($root) {
130
+        $webRoot = null;
131
+        $tmpRoot = $root;
132
+
133
+        while ($webRoot === null) {
134
+            if (isset($this->mapping[$tmpRoot])) {
135
+                $webRoot = $this->mapping[$tmpRoot];
136
+                break;
137
+            }
138
+
139
+            if ($tmpRoot === '/') {
140
+                break;
141
+            }
142
+
143
+            $tmpRoot = dirname($tmpRoot);
144
+        }
145
+
146
+        if ($webRoot === null) {
147
+            $realpath = realpath($root);
148
+
149
+            if ($realpath && ($realpath !== $root)) {
150
+                return $this->findWebRoot($realpath);
151
+            }
152
+        }
153
+
154
+        return $webRoot;
155
+    }
156
+
157
+    /**
158
+     * append the $file resource at $root
159
+     *
160
+     * @param string $root path to check
161
+     * @param string $file the filename
162
+     * @param string|null $webRoot base for path, default map $root to $webRoot
163
+     * @param bool $throw Throw an exception, when the route does not exist
164
+     * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing
165
+     */
166
+    protected function append($root, $file, $webRoot = null, $throw = true) {
167
+        if (!is_string($root)) {
168
+            if ($throw) {
169
+                throw new ResourceNotFoundException($file, $webRoot);
170
+            }
171
+            return;
172
+        }
173
+
174
+        if (!$webRoot) {
175
+            $webRoot = $this->findWebRoot($root);
176
+
177
+            if ($webRoot === null) {
178
+                $webRoot = '';
179
+                $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
180
+                    'app' => 'lib',
181
+                    'root' => $root,
182
+                    'file' => $file,
183
+                    'webRoot' => $webRoot,
184
+                    'throw' => $throw ? 'true' : 'false'
185
+                ]);
186
+            }
187
+        }
188
+        $this->resources[] = [$root, $webRoot, $file];
189
+
190
+        if ($throw && !is_file($root . '/' . $file)) {
191
+            throw new ResourceNotFoundException($file, $webRoot);
192
+        }
193
+    }
194
+
195
+    /**
196
+     * Returns the list of all resources that should be loaded
197
+     * @return array
198
+     */
199
+    public function getResources() {
200
+        return $this->resources;
201
+    }
202 202
 }
Please login to merge, or discard this patch.
lib/private/Template/Base.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@
 block discarded – undo
117 117
 		if (array_key_exists($key, $this->vars)) {
118 118
 			$this->vars[$key][] = $value;
119 119
 		} else {
120
-			$this->vars[$key] = [ $value ];
120
+			$this->vars[$key] = [$value];
121 121
 		}
122 122
 	}
123 123
 
Please login to merge, or discard this patch.
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -34,157 +34,157 @@
 block discarded – undo
34 34
 use Throwable;
35 35
 
36 36
 class Base {
37
-	private $template; // The template
38
-	private $vars; // Vars
39
-
40
-	/** @var \OCP\IL10N */
41
-	private $l10n;
42
-
43
-	/** @var Defaults */
44
-	private $theme;
45
-
46
-	/**
47
-	 * @param string $template
48
-	 * @param string $requestToken
49
-	 * @param \OCP\IL10N $l10n
50
-	 * @param Defaults $theme
51
-	 */
52
-	public function __construct($template, $requestToken, $l10n, $theme) {
53
-		$this->vars = [];
54
-		$this->vars['requesttoken'] = $requestToken;
55
-		$this->l10n = $l10n;
56
-		$this->template = $template;
57
-		$this->theme = $theme;
58
-	}
59
-
60
-	/**
61
-	 * @param string $serverRoot
62
-	 * @param string|false $app_dir
63
-	 * @param string $theme
64
-	 * @param string $app
65
-	 * @return string[]
66
-	 */
67
-	protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
68
-		// Check if the app is in the app folder or in the root
69
-		if (file_exists($app_dir.'/templates/')) {
70
-			return [
71
-				$serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
72
-				$app_dir.'/templates/',
73
-			];
74
-		}
75
-		return [
76
-			$serverRoot.'/themes/'.$theme.'/'.$app.'/templates/',
77
-			$serverRoot.'/'.$app.'/templates/',
78
-		];
79
-	}
80
-
81
-	/**
82
-	 * @param string $serverRoot
83
-	 * @param string $theme
84
-	 * @return string[]
85
-	 */
86
-	protected function getCoreTemplateDirs($theme, $serverRoot) {
87
-		return [
88
-			$serverRoot.'/themes/'.$theme.'/core/templates/',
89
-			$serverRoot.'/core/templates/',
90
-		];
91
-	}
92
-
93
-	/**
94
-	 * Assign variables
95
-	 * @param string $key key
96
-	 * @param array|bool|integer|string|Throwable $value value
97
-	 * @return bool
98
-	 *
99
-	 * This function assigns a variable. It can be accessed via $_[$key] in
100
-	 * the template.
101
-	 *
102
-	 * If the key existed before, it will be overwritten
103
-	 */
104
-	public function assign($key, $value) {
105
-		$this->vars[$key] = $value;
106
-		return true;
107
-	}
108
-
109
-	/**
110
-	 * Appends a variable
111
-	 * @param string $key key
112
-	 * @param mixed $value value
113
-	 *
114
-	 * This function assigns a variable in an array context. If the key already
115
-	 * exists, the value will be appended. It can be accessed via
116
-	 * $_[$key][$position] in the template.
117
-	 */
118
-	public function append($key, $value) {
119
-		if (array_key_exists($key, $this->vars)) {
120
-			$this->vars[$key][] = $value;
121
-		} else {
122
-			$this->vars[$key] = [ $value ];
123
-		}
124
-	}
125
-
126
-	/**
127
-	 * Prints the proceeded template
128
-	 * @return bool
129
-	 *
130
-	 * This function proceeds the template and prints its output.
131
-	 */
132
-	public function printPage() {
133
-		$data = $this->fetchPage();
134
-		if ($data === false) {
135
-			return false;
136
-		} else {
137
-			print $data;
138
-			return true;
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * Process the template
144
-	 *
145
-	 * @param array|null $additionalParams
146
-	 * @return string This function processes the template.
147
-	 *
148
-	 * This function processes the template.
149
-	 */
150
-	public function fetchPage($additionalParams = null) {
151
-		return $this->load($this->template, $additionalParams);
152
-	}
153
-
154
-	/**
155
-	 * doing the actual work
156
-	 *
157
-	 * @param string $file
158
-	 * @param array|null $additionalParams
159
-	 * @return string content
160
-	 *
161
-	 * Includes the template file, fetches its output
162
-	 */
163
-	protected function load($file, $additionalParams = null) {
164
-		// Register the variables
165
-		$_ = $this->vars;
166
-		$l = $this->l10n;
167
-		$theme = $this->theme;
168
-
169
-		if (!is_null($additionalParams)) {
170
-			$_ = array_merge($additionalParams, $this->vars);
171
-			foreach ($_ as $var => $value) {
172
-				${$var} = $value;
173
-			}
174
-		}
175
-
176
-		// Include
177
-		ob_start();
178
-		try {
179
-			include $file;
180
-			$data = ob_get_contents();
181
-		} catch (\Exception $e) {
182
-			@ob_end_clean();
183
-			throw $e;
184
-		}
185
-		@ob_end_clean();
186
-
187
-		// Return data
188
-		return $data;
189
-	}
37
+    private $template; // The template
38
+    private $vars; // Vars
39
+
40
+    /** @var \OCP\IL10N */
41
+    private $l10n;
42
+
43
+    /** @var Defaults */
44
+    private $theme;
45
+
46
+    /**
47
+     * @param string $template
48
+     * @param string $requestToken
49
+     * @param \OCP\IL10N $l10n
50
+     * @param Defaults $theme
51
+     */
52
+    public function __construct($template, $requestToken, $l10n, $theme) {
53
+        $this->vars = [];
54
+        $this->vars['requesttoken'] = $requestToken;
55
+        $this->l10n = $l10n;
56
+        $this->template = $template;
57
+        $this->theme = $theme;
58
+    }
59
+
60
+    /**
61
+     * @param string $serverRoot
62
+     * @param string|false $app_dir
63
+     * @param string $theme
64
+     * @param string $app
65
+     * @return string[]
66
+     */
67
+    protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
68
+        // Check if the app is in the app folder or in the root
69
+        if (file_exists($app_dir.'/templates/')) {
70
+            return [
71
+                $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
72
+                $app_dir.'/templates/',
73
+            ];
74
+        }
75
+        return [
76
+            $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/',
77
+            $serverRoot.'/'.$app.'/templates/',
78
+        ];
79
+    }
80
+
81
+    /**
82
+     * @param string $serverRoot
83
+     * @param string $theme
84
+     * @return string[]
85
+     */
86
+    protected function getCoreTemplateDirs($theme, $serverRoot) {
87
+        return [
88
+            $serverRoot.'/themes/'.$theme.'/core/templates/',
89
+            $serverRoot.'/core/templates/',
90
+        ];
91
+    }
92
+
93
+    /**
94
+     * Assign variables
95
+     * @param string $key key
96
+     * @param array|bool|integer|string|Throwable $value value
97
+     * @return bool
98
+     *
99
+     * This function assigns a variable. It can be accessed via $_[$key] in
100
+     * the template.
101
+     *
102
+     * If the key existed before, it will be overwritten
103
+     */
104
+    public function assign($key, $value) {
105
+        $this->vars[$key] = $value;
106
+        return true;
107
+    }
108
+
109
+    /**
110
+     * Appends a variable
111
+     * @param string $key key
112
+     * @param mixed $value value
113
+     *
114
+     * This function assigns a variable in an array context. If the key already
115
+     * exists, the value will be appended. It can be accessed via
116
+     * $_[$key][$position] in the template.
117
+     */
118
+    public function append($key, $value) {
119
+        if (array_key_exists($key, $this->vars)) {
120
+            $this->vars[$key][] = $value;
121
+        } else {
122
+            $this->vars[$key] = [ $value ];
123
+        }
124
+    }
125
+
126
+    /**
127
+     * Prints the proceeded template
128
+     * @return bool
129
+     *
130
+     * This function proceeds the template and prints its output.
131
+     */
132
+    public function printPage() {
133
+        $data = $this->fetchPage();
134
+        if ($data === false) {
135
+            return false;
136
+        } else {
137
+            print $data;
138
+            return true;
139
+        }
140
+    }
141
+
142
+    /**
143
+     * Process the template
144
+     *
145
+     * @param array|null $additionalParams
146
+     * @return string This function processes the template.
147
+     *
148
+     * This function processes the template.
149
+     */
150
+    public function fetchPage($additionalParams = null) {
151
+        return $this->load($this->template, $additionalParams);
152
+    }
153
+
154
+    /**
155
+     * doing the actual work
156
+     *
157
+     * @param string $file
158
+     * @param array|null $additionalParams
159
+     * @return string content
160
+     *
161
+     * Includes the template file, fetches its output
162
+     */
163
+    protected function load($file, $additionalParams = null) {
164
+        // Register the variables
165
+        $_ = $this->vars;
166
+        $l = $this->l10n;
167
+        $theme = $this->theme;
168
+
169
+        if (!is_null($additionalParams)) {
170
+            $_ = array_merge($additionalParams, $this->vars);
171
+            foreach ($_ as $var => $value) {
172
+                ${$var} = $value;
173
+            }
174
+        }
175
+
176
+        // Include
177
+        ob_start();
178
+        try {
179
+            include $file;
180
+            $data = ob_get_contents();
181
+        } catch (\Exception $e) {
182
+            @ob_end_clean();
183
+            throw $e;
184
+        }
185
+        @ob_end_clean();
186
+
187
+        // Return data
188
+        return $data;
189
+    }
190 190
 }
Please login to merge, or discard this patch.
lib/private/Diagnostics/EventLogger.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -28,56 +28,56 @@
 block discarded – undo
28 28
 use OCP\Diagnostics\IEventLogger;
29 29
 
30 30
 class EventLogger implements IEventLogger {
31
-	/**
32
-	 * @var \OC\Diagnostics\Event[]
33
-	 */
34
-	private $events = [];
31
+    /**
32
+     * @var \OC\Diagnostics\Event[]
33
+     */
34
+    private $events = [];
35 35
 	
36
-	/**
37
-	 * @var bool - Module needs to be activated by some app
38
-	 */
39
-	private $activated = false;
36
+    /**
37
+     * @var bool - Module needs to be activated by some app
38
+     */
39
+    private $activated = false;
40 40
 
41
-	/**
42
-	 * @inheritdoc
43
-	 */
44
-	public function start($id, $description) {
45
-		if ($this->activated) {
46
-			$this->events[$id] = new Event($id, $description, microtime(true));
47
-		}
48
-	}
41
+    /**
42
+     * @inheritdoc
43
+     */
44
+    public function start($id, $description) {
45
+        if ($this->activated) {
46
+            $this->events[$id] = new Event($id, $description, microtime(true));
47
+        }
48
+    }
49 49
 
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	public function end($id) {
54
-		if ($this->activated && isset($this->events[$id])) {
55
-			$timing = $this->events[$id];
56
-			$timing->end(microtime(true));
57
-		}
58
-	}
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    public function end($id) {
54
+        if ($this->activated && isset($this->events[$id])) {
55
+            $timing = $this->events[$id];
56
+            $timing->end(microtime(true));
57
+        }
58
+    }
59 59
 
60
-	/**
61
-	 * @inheritdoc
62
-	 */
63
-	public function log($id, $description, $start, $end) {
64
-		if ($this->activated) {
65
-			$this->events[$id] = new Event($id, $description, $start);
66
-			$this->events[$id]->end($end);
67
-		}
68
-	}
60
+    /**
61
+     * @inheritdoc
62
+     */
63
+    public function log($id, $description, $start, $end) {
64
+        if ($this->activated) {
65
+            $this->events[$id] = new Event($id, $description, $start);
66
+            $this->events[$id]->end($end);
67
+        }
68
+    }
69 69
 
70
-	/**
71
-	 * @inheritdoc
72
-	 */
73
-	public function getEvents() {
74
-		return $this->events;
75
-	}
70
+    /**
71
+     * @inheritdoc
72
+     */
73
+    public function getEvents() {
74
+        return $this->events;
75
+    }
76 76
 	
77
-	/**
78
-	 * @inheritdoc
79
-	 */
80
-	public function activate() {
81
-		$this->activated = true;
82
-	}
77
+    /**
78
+     * @inheritdoc
79
+     */
80
+    public function activate() {
81
+        $this->activated = true;
82
+    }
83 83
 }
Please login to merge, or discard this patch.
lib/private/Cache/CappedMemoryCache.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -30,66 +30,66 @@
 block discarded – undo
30 30
  * Uses a simple FIFO expiry mechanism
31 31
  */
32 32
 class CappedMemoryCache implements ICache, \ArrayAccess {
33
-	private $capacity;
34
-	private $cache = [];
35
-
36
-	public function __construct($capacity = 512) {
37
-		$this->capacity = $capacity;
38
-	}
39
-
40
-	public function hasKey($key) {
41
-		return isset($this->cache[$key]);
42
-	}
43
-
44
-	public function get($key) {
45
-		return isset($this->cache[$key]) ? $this->cache[$key] : null;
46
-	}
47
-
48
-	public function set($key, $value, $ttl = 0) {
49
-		if (is_null($key)) {
50
-			$this->cache[] = $value;
51
-		} else {
52
-			$this->cache[$key] = $value;
53
-		}
54
-		$this->garbageCollect();
55
-	}
56
-
57
-	public function remove($key) {
58
-		unset($this->cache[$key]);
59
-		return true;
60
-	}
61
-
62
-	public function clear($prefix = '') {
63
-		$this->cache = [];
64
-		return true;
65
-	}
66
-
67
-	public function offsetExists($offset) {
68
-		return $this->hasKey($offset);
69
-	}
70
-
71
-	public function &offsetGet($offset) {
72
-		return $this->cache[$offset];
73
-	}
74
-
75
-	public function offsetSet($offset, $value) {
76
-		$this->set($offset, $value);
77
-	}
78
-
79
-	public function offsetUnset($offset) {
80
-		$this->remove($offset);
81
-	}
82
-
83
-	public function getData() {
84
-		return $this->cache;
85
-	}
86
-
87
-
88
-	private function garbageCollect() {
89
-		while (count($this->cache) > $this->capacity) {
90
-			reset($this->cache);
91
-			$key = key($this->cache);
92
-			$this->remove($key);
93
-		}
94
-	}
33
+    private $capacity;
34
+    private $cache = [];
35
+
36
+    public function __construct($capacity = 512) {
37
+        $this->capacity = $capacity;
38
+    }
39
+
40
+    public function hasKey($key) {
41
+        return isset($this->cache[$key]);
42
+    }
43
+
44
+    public function get($key) {
45
+        return isset($this->cache[$key]) ? $this->cache[$key] : null;
46
+    }
47
+
48
+    public function set($key, $value, $ttl = 0) {
49
+        if (is_null($key)) {
50
+            $this->cache[] = $value;
51
+        } else {
52
+            $this->cache[$key] = $value;
53
+        }
54
+        $this->garbageCollect();
55
+    }
56
+
57
+    public function remove($key) {
58
+        unset($this->cache[$key]);
59
+        return true;
60
+    }
61
+
62
+    public function clear($prefix = '') {
63
+        $this->cache = [];
64
+        return true;
65
+    }
66
+
67
+    public function offsetExists($offset) {
68
+        return $this->hasKey($offset);
69
+    }
70
+
71
+    public function &offsetGet($offset) {
72
+        return $this->cache[$offset];
73
+    }
74
+
75
+    public function offsetSet($offset, $value) {
76
+        $this->set($offset, $value);
77
+    }
78
+
79
+    public function offsetUnset($offset) {
80
+        $this->remove($offset);
81
+    }
82
+
83
+    public function getData() {
84
+        return $this->cache;
85
+    }
86
+
87
+
88
+    private function garbageCollect() {
89
+        while (count($this->cache) > $this->capacity) {
90
+            reset($this->cache);
91
+            $key = key($this->cache);
92
+            $this->remove($key);
93
+        }
94
+    }
95 95
 }
Please login to merge, or discard this patch.
lib/private/Security/Certificate.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -27,104 +27,104 @@
 block discarded – undo
27 27
 use OCP\ICertificate;
28 28
 
29 29
 class Certificate implements ICertificate {
30
-	protected $name;
31
-
32
-	protected $commonName;
33
-
34
-	protected $organization;
35
-
36
-	protected $serial;
37
-
38
-	protected $issueDate;
39
-
40
-	protected $expireDate;
41
-
42
-	protected $issuerName;
43
-
44
-	protected $issuerOrganization;
45
-
46
-	/**
47
-	 * @param string $data base64 encoded certificate
48
-	 * @param string $name
49
-	 * @throws \Exception If the certificate could not get parsed
50
-	 */
51
-	public function __construct($data, $name) {
52
-		$this->name = $name;
53
-		$gmt = new \DateTimeZone('GMT');
54
-
55
-		// If string starts with "file://" ignore the certificate
56
-		$query = 'file://';
57
-		if (strtolower(substr($data, 0, strlen($query))) === $query) {
58
-			throw new \Exception('Certificate could not get parsed.');
59
-		}
60
-
61
-		$info = openssl_x509_parse($data);
62
-		if (!is_array($info)) {
63
-			throw new \Exception('Certificate could not get parsed.');
64
-		}
65
-
66
-		$this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
67
-		$this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
68
-		$this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
69
-		$this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
70
-		$this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
71
-		$this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
72
-	}
73
-
74
-	/**
75
-	 * @return string
76
-	 */
77
-	public function getName() {
78
-		return $this->name;
79
-	}
80
-
81
-	/**
82
-	 * @return string|null
83
-	 */
84
-	public function getCommonName() {
85
-		return $this->commonName;
86
-	}
87
-
88
-	/**
89
-	 * @return string
90
-	 */
91
-	public function getOrganization() {
92
-		return $this->organization;
93
-	}
94
-
95
-	/**
96
-	 * @return \DateTime
97
-	 */
98
-	public function getIssueDate() {
99
-		return $this->issueDate;
100
-	}
101
-
102
-	/**
103
-	 * @return \DateTime
104
-	 */
105
-	public function getExpireDate() {
106
-		return $this->expireDate;
107
-	}
108
-
109
-	/**
110
-	 * @return bool
111
-	 */
112
-	public function isExpired() {
113
-		$now = new \DateTime();
114
-		return $this->issueDate > $now or $now > $this->expireDate;
115
-	}
116
-
117
-	/**
118
-	 * @return string|null
119
-	 */
120
-	public function getIssuerName() {
121
-		return $this->issuerName;
122
-	}
123
-
124
-	/**
125
-	 * @return string|null
126
-	 */
127
-	public function getIssuerOrganization() {
128
-		return $this->issuerOrganization;
129
-	}
30
+    protected $name;
31
+
32
+    protected $commonName;
33
+
34
+    protected $organization;
35
+
36
+    protected $serial;
37
+
38
+    protected $issueDate;
39
+
40
+    protected $expireDate;
41
+
42
+    protected $issuerName;
43
+
44
+    protected $issuerOrganization;
45
+
46
+    /**
47
+     * @param string $data base64 encoded certificate
48
+     * @param string $name
49
+     * @throws \Exception If the certificate could not get parsed
50
+     */
51
+    public function __construct($data, $name) {
52
+        $this->name = $name;
53
+        $gmt = new \DateTimeZone('GMT');
54
+
55
+        // If string starts with "file://" ignore the certificate
56
+        $query = 'file://';
57
+        if (strtolower(substr($data, 0, strlen($query))) === $query) {
58
+            throw new \Exception('Certificate could not get parsed.');
59
+        }
60
+
61
+        $info = openssl_x509_parse($data);
62
+        if (!is_array($info)) {
63
+            throw new \Exception('Certificate could not get parsed.');
64
+        }
65
+
66
+        $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
67
+        $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
68
+        $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
69
+        $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
70
+        $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
71
+        $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
72
+    }
73
+
74
+    /**
75
+     * @return string
76
+     */
77
+    public function getName() {
78
+        return $this->name;
79
+    }
80
+
81
+    /**
82
+     * @return string|null
83
+     */
84
+    public function getCommonName() {
85
+        return $this->commonName;
86
+    }
87
+
88
+    /**
89
+     * @return string
90
+     */
91
+    public function getOrganization() {
92
+        return $this->organization;
93
+    }
94
+
95
+    /**
96
+     * @return \DateTime
97
+     */
98
+    public function getIssueDate() {
99
+        return $this->issueDate;
100
+    }
101
+
102
+    /**
103
+     * @return \DateTime
104
+     */
105
+    public function getExpireDate() {
106
+        return $this->expireDate;
107
+    }
108
+
109
+    /**
110
+     * @return bool
111
+     */
112
+    public function isExpired() {
113
+        $now = new \DateTime();
114
+        return $this->issueDate > $now or $now > $this->expireDate;
115
+    }
116
+
117
+    /**
118
+     * @return string|null
119
+     */
120
+    public function getIssuerName() {
121
+        return $this->issuerName;
122
+    }
123
+
124
+    /**
125
+     * @return string|null
126
+     */
127
+    public function getIssuerOrganization() {
128
+        return $this->issuerOrganization;
129
+    }
130 130
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,8 +65,8 @@
 block discarded – undo
65 65
 
66 66
 		$this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
67 67
 		$this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
68
-		$this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
69
-		$this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
68
+		$this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt);
69
+		$this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt);
70 70
 		$this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
71 71
 		$this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
72 72
 	}
Please login to merge, or discard this patch.
lib/private/Security/IdentityProof/Signer.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
 			$user = $this->userManager->get($userId);
90 90
 			if ($user !== null) {
91 91
 				$key = $this->keyManager->getKey($user);
92
-				return (bool)openssl_verify(
92
+				return (bool) openssl_verify(
93 93
 					json_encode($data['message']),
94 94
 					base64_decode($data['signature']),
95 95
 					$key->getPublic(),
Please login to merge, or discard this patch.
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -32,76 +32,76 @@
 block discarded – undo
32 32
 use OCP\IUserManager;
33 33
 
34 34
 class Signer {
35
-	/** @var Manager */
36
-	private $keyManager;
37
-	/** @var ITimeFactory */
38
-	private $timeFactory;
39
-	/** @var IUserManager */
40
-	private $userManager;
35
+    /** @var Manager */
36
+    private $keyManager;
37
+    /** @var ITimeFactory */
38
+    private $timeFactory;
39
+    /** @var IUserManager */
40
+    private $userManager;
41 41
 
42
-	/**
43
-	 * @param Manager $keyManager
44
-	 * @param ITimeFactory $timeFactory
45
-	 * @param IUserManager $userManager
46
-	 */
47
-	public function __construct(Manager $keyManager,
48
-								ITimeFactory $timeFactory,
49
-								IUserManager $userManager) {
50
-		$this->keyManager = $keyManager;
51
-		$this->timeFactory = $timeFactory;
52
-		$this->userManager = $userManager;
53
-	}
42
+    /**
43
+     * @param Manager $keyManager
44
+     * @param ITimeFactory $timeFactory
45
+     * @param IUserManager $userManager
46
+     */
47
+    public function __construct(Manager $keyManager,
48
+                                ITimeFactory $timeFactory,
49
+                                IUserManager $userManager) {
50
+        $this->keyManager = $keyManager;
51
+        $this->timeFactory = $timeFactory;
52
+        $this->userManager = $userManager;
53
+    }
54 54
 
55
-	/**
56
-	 * Returns a signed blob for $data
57
-	 *
58
-	 * @param string $type
59
-	 * @param array $data
60
-	 * @param IUser $user
61
-	 * @return array ['message', 'signature']
62
-	 */
63
-	public function sign(string $type, array $data, IUser $user): array {
64
-		$privateKey = $this->keyManager->getKey($user)->getPrivate();
65
-		$data = [
66
-			'data' => $data,
67
-			'type' => $type,
68
-			'signer' => $user->getCloudId(),
69
-			'timestamp' => $this->timeFactory->getTime(),
70
-		];
71
-		openssl_sign(json_encode($data), $signature, $privateKey, OPENSSL_ALGO_SHA512);
55
+    /**
56
+     * Returns a signed blob for $data
57
+     *
58
+     * @param string $type
59
+     * @param array $data
60
+     * @param IUser $user
61
+     * @return array ['message', 'signature']
62
+     */
63
+    public function sign(string $type, array $data, IUser $user): array {
64
+        $privateKey = $this->keyManager->getKey($user)->getPrivate();
65
+        $data = [
66
+            'data' => $data,
67
+            'type' => $type,
68
+            'signer' => $user->getCloudId(),
69
+            'timestamp' => $this->timeFactory->getTime(),
70
+        ];
71
+        openssl_sign(json_encode($data), $signature, $privateKey, OPENSSL_ALGO_SHA512);
72 72
 
73
-		return [
74
-			'message' => $data,
75
-			'signature' => base64_encode($signature),
76
-		];
77
-	}
73
+        return [
74
+            'message' => $data,
75
+            'signature' => base64_encode($signature),
76
+        ];
77
+    }
78 78
 
79
-	/**
80
-	 * Whether the data is signed properly
81
-	 *
82
-	 * @param array $data
83
-	 * @return bool
84
-	 */
85
-	public function verify(array $data): bool {
86
-		if (isset($data['message'])
87
-			&& isset($data['signature'])
88
-			&& isset($data['message']['signer'])
89
-		) {
90
-			$location = strrpos($data['message']['signer'], '@');
91
-			$userId = substr($data['message']['signer'], 0, $location);
79
+    /**
80
+     * Whether the data is signed properly
81
+     *
82
+     * @param array $data
83
+     * @return bool
84
+     */
85
+    public function verify(array $data): bool {
86
+        if (isset($data['message'])
87
+            && isset($data['signature'])
88
+            && isset($data['message']['signer'])
89
+        ) {
90
+            $location = strrpos($data['message']['signer'], '@');
91
+            $userId = substr($data['message']['signer'], 0, $location);
92 92
 
93
-			$user = $this->userManager->get($userId);
94
-			if ($user !== null) {
95
-				$key = $this->keyManager->getKey($user);
96
-				return (bool)openssl_verify(
97
-					json_encode($data['message']),
98
-					base64_decode($data['signature']),
99
-					$key->getPublic(),
100
-					OPENSSL_ALGO_SHA512
101
-				);
102
-			}
103
-		}
93
+            $user = $this->userManager->get($userId);
94
+            if ($user !== null) {
95
+                $key = $this->keyManager->getKey($user);
96
+                return (bool)openssl_verify(
97
+                    json_encode($data['message']),
98
+                    base64_decode($data['signature']),
99
+                    $key->getPublic(),
100
+                    OPENSSL_ALGO_SHA512
101
+                );
102
+            }
103
+        }
104 104
 
105
-		return false;
106
-	}
105
+        return false;
106
+    }
107 107
 }
Please login to merge, or discard this patch.
lib/private/Encryption/Exceptions/EncryptionHeaderToLargeException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 use OCP\Encryption\Exceptions\GenericEncryptionException;
28 28
 
29 29
 class EncryptionHeaderToLargeException extends GenericEncryptionException {
30
-	public function __construct() {
31
-		parent::__construct('max header size exceeded');
32
-	}
30
+    public function __construct() {
31
+        parent::__construct('max header size exceeded');
32
+    }
33 33
 }
Please login to merge, or discard this patch.
lib/private/Encryption/File.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
 		// always add owner to the list of users with access to the file
74 74
 		$userIds = [$owner];
75 75
 
76
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
76
+		if (!$this->util->isFile($owner.'/'.$ownerPath)) {
77 77
 			return ['users' => $userIds, 'public' => false];
78 78
 		}
79 79
 
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -35,94 +35,94 @@
 block discarded – undo
35 35
 
36 36
 class File implements \OCP\Encryption\IFile {
37 37
 
38
-	/** @var Util */
39
-	protected $util;
40
-
41
-	/** @var IRootFolder */
42
-	private $rootFolder;
43
-
44
-	/** @var IManager */
45
-	private $shareManager;
46
-
47
-	/**
48
-	 * cache results of already checked folders
49
-	 *
50
-	 * @var array
51
-	 */
52
-	protected $cache;
53
-
54
-	public function __construct(Util $util,
55
-								IRootFolder $rootFolder,
56
-								IManager $shareManager) {
57
-		$this->util = $util;
58
-		$this->cache = new CappedMemoryCache();
59
-		$this->rootFolder = $rootFolder;
60
-		$this->shareManager = $shareManager;
61
-	}
62
-
63
-
64
-	/**
65
-	 * get list of users with access to the file
66
-	 *
67
-	 * @param string $path to the file
68
-	 * @return array  ['users' => $uniqueUserIds, 'public' => $public]
69
-	 */
70
-	public function getAccessList($path) {
71
-
72
-		// Make sure that a share key is generated for the owner too
73
-		[$owner, $ownerPath] = $this->util->getUidAndFilename($path);
74
-
75
-		// always add owner to the list of users with access to the file
76
-		$userIds = [$owner];
77
-
78
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
79
-			return ['users' => $userIds, 'public' => false];
80
-		}
81
-
82
-		$ownerPath = substr($ownerPath, strlen('/files'));
83
-		$userFolder = $this->rootFolder->getUserFolder($owner);
84
-		try {
85
-			$file = $userFolder->get($ownerPath);
86
-		} catch (NotFoundException $e) {
87
-			$file = null;
88
-		}
89
-		$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
90
-
91
-		// first get the shares for the parent and cache the result so that we don't
92
-		// need to check all parents for every file
93
-		$parent = dirname($ownerPath);
94
-		$parentNode = $userFolder->get($parent);
95
-		if (isset($this->cache[$parent])) {
96
-			$resultForParents = $this->cache[$parent];
97
-		} else {
98
-			$resultForParents = $this->shareManager->getAccessList($parentNode);
99
-			$this->cache[$parent] = $resultForParents;
100
-		}
101
-		$userIds = array_merge($userIds, $resultForParents['users']);
102
-		$public = $resultForParents['public'] || $resultForParents['remote'];
103
-
104
-
105
-		// Find out who, if anyone, is sharing the file
106
-		if ($file !== null) {
107
-			$resultForFile = $this->shareManager->getAccessList($file, false);
108
-			$userIds = array_merge($userIds, $resultForFile['users']);
109
-			$public = $resultForFile['public'] || $resultForFile['remote'] || $public;
110
-		}
111
-
112
-		// check if it is a group mount
113
-		if (\OCP\App::isEnabled("files_external")) {
114
-			$mounts = \OCA\Files_External\MountConfig::getSystemMountPoints();
115
-			foreach ($mounts as $mount) {
116
-				if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
117
-					$mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
118
-					$userIds = array_merge($userIds, $mountedFor);
119
-				}
120
-			}
121
-		}
122
-
123
-		// Remove duplicate UIDs
124
-		$uniqueUserIds = array_unique($userIds);
125
-
126
-		return ['users' => $uniqueUserIds, 'public' => $public];
127
-	}
38
+    /** @var Util */
39
+    protected $util;
40
+
41
+    /** @var IRootFolder */
42
+    private $rootFolder;
43
+
44
+    /** @var IManager */
45
+    private $shareManager;
46
+
47
+    /**
48
+     * cache results of already checked folders
49
+     *
50
+     * @var array
51
+     */
52
+    protected $cache;
53
+
54
+    public function __construct(Util $util,
55
+                                IRootFolder $rootFolder,
56
+                                IManager $shareManager) {
57
+        $this->util = $util;
58
+        $this->cache = new CappedMemoryCache();
59
+        $this->rootFolder = $rootFolder;
60
+        $this->shareManager = $shareManager;
61
+    }
62
+
63
+
64
+    /**
65
+     * get list of users with access to the file
66
+     *
67
+     * @param string $path to the file
68
+     * @return array  ['users' => $uniqueUserIds, 'public' => $public]
69
+     */
70
+    public function getAccessList($path) {
71
+
72
+        // Make sure that a share key is generated for the owner too
73
+        [$owner, $ownerPath] = $this->util->getUidAndFilename($path);
74
+
75
+        // always add owner to the list of users with access to the file
76
+        $userIds = [$owner];
77
+
78
+        if (!$this->util->isFile($owner . '/' . $ownerPath)) {
79
+            return ['users' => $userIds, 'public' => false];
80
+        }
81
+
82
+        $ownerPath = substr($ownerPath, strlen('/files'));
83
+        $userFolder = $this->rootFolder->getUserFolder($owner);
84
+        try {
85
+            $file = $userFolder->get($ownerPath);
86
+        } catch (NotFoundException $e) {
87
+            $file = null;
88
+        }
89
+        $ownerPath = $this->util->stripPartialFileExtension($ownerPath);
90
+
91
+        // first get the shares for the parent and cache the result so that we don't
92
+        // need to check all parents for every file
93
+        $parent = dirname($ownerPath);
94
+        $parentNode = $userFolder->get($parent);
95
+        if (isset($this->cache[$parent])) {
96
+            $resultForParents = $this->cache[$parent];
97
+        } else {
98
+            $resultForParents = $this->shareManager->getAccessList($parentNode);
99
+            $this->cache[$parent] = $resultForParents;
100
+        }
101
+        $userIds = array_merge($userIds, $resultForParents['users']);
102
+        $public = $resultForParents['public'] || $resultForParents['remote'];
103
+
104
+
105
+        // Find out who, if anyone, is sharing the file
106
+        if ($file !== null) {
107
+            $resultForFile = $this->shareManager->getAccessList($file, false);
108
+            $userIds = array_merge($userIds, $resultForFile['users']);
109
+            $public = $resultForFile['public'] || $resultForFile['remote'] || $public;
110
+        }
111
+
112
+        // check if it is a group mount
113
+        if (\OCP\App::isEnabled("files_external")) {
114
+            $mounts = \OCA\Files_External\MountConfig::getSystemMountPoints();
115
+            foreach ($mounts as $mount) {
116
+                if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
117
+                    $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
118
+                    $userIds = array_merge($userIds, $mountedFor);
119
+                }
120
+            }
121
+        }
122
+
123
+        // Remove duplicate UIDs
124
+        $uniqueUserIds = array_unique($userIds);
125
+
126
+        return ['users' => $uniqueUserIds, 'public' => $public];
127
+    }
128 128
 }
Please login to merge, or discard this patch.
lib/private/TempManager.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
68 68
 		if ($postFix !== '') {
69
-			$postFix = '.' . ltrim($postFix, '.');
69
+			$postFix = '.'.ltrim($postFix, '.');
70 70
 			$postFix = str_replace(['\\', '/'], '', $postFix);
71 71
 			$absolutePath .= '-';
72 72
 		}
73 73
 
74
-		return $absolutePath . $postFix;
74
+		return $absolutePath.$postFix;
75 75
 	}
76 76
 
77 77
 	/**
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
 			$this->current[] = $uniqueFileName;
128 128
 
129 129
 			// Build a name without postfix
130
-			$path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
130
+			$path = $this->buildFileNameWithSuffix($uniqueFileName.'-folder', $postFix);
131 131
 			mkdir($path, 0700);
132 132
 			$this->current[] = $path;
133 133
 
134
-			return $path . '/';
134
+			return $path.'/';
135 135
 		} else {
136 136
 			$this->log->warning(
137 137
 				'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		if ($dh) {
191 191
 			while (($file = readdir($dh)) !== false) {
192 192
 				if (substr($file, 0, 7) === self::TMP_PREFIX) {
193
-					$path = $this->tmpBaseDir . '/' . $file;
193
+					$path = $this->tmpBaseDir.'/'.$file;
194 194
 					$mtime = filemtime($path);
195 195
 					if ($mtime < $cutOfTime) {
196 196
 						$files[] = $path;
Please login to merge, or discard this patch.
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -37,244 +37,244 @@
 block discarded – undo
37 37
 use Psr\Log\LoggerInterface;
38 38
 
39 39
 class TempManager implements ITempManager {
40
-	/** @var string[] Current temporary files and folders, used for cleanup */
41
-	protected $current = [];
42
-	/** @var string i.e. /tmp on linux systems */
43
-	protected $tmpBaseDir;
44
-	/** @var LoggerInterface */
45
-	protected $log;
46
-	/** @var IConfig */
47
-	protected $config;
48
-	/** @var IniGetWrapper */
49
-	protected $iniGetWrapper;
40
+    /** @var string[] Current temporary files and folders, used for cleanup */
41
+    protected $current = [];
42
+    /** @var string i.e. /tmp on linux systems */
43
+    protected $tmpBaseDir;
44
+    /** @var LoggerInterface */
45
+    protected $log;
46
+    /** @var IConfig */
47
+    protected $config;
48
+    /** @var IniGetWrapper */
49
+    protected $iniGetWrapper;
50 50
 
51
-	/** Prefix */
52
-	public const TMP_PREFIX = 'oc_tmp_';
51
+    /** Prefix */
52
+    public const TMP_PREFIX = 'oc_tmp_';
53 53
 
54
-	public function __construct(LoggerInterface $logger, IConfig $config, IniGetWrapper $iniGetWrapper) {
55
-		$this->log = $logger;
56
-		$this->config = $config;
57
-		$this->iniGetWrapper = $iniGetWrapper;
58
-		$this->tmpBaseDir = $this->getTempBaseDir();
59
-	}
54
+    public function __construct(LoggerInterface $logger, IConfig $config, IniGetWrapper $iniGetWrapper) {
55
+        $this->log = $logger;
56
+        $this->config = $config;
57
+        $this->iniGetWrapper = $iniGetWrapper;
58
+        $this->tmpBaseDir = $this->getTempBaseDir();
59
+    }
60 60
 
61
-	/**
62
-	 * Builds the filename with suffix and removes potential dangerous characters
63
-	 * such as directory separators.
64
-	 *
65
-	 * @param string $absolutePath Absolute path to the file / folder
66
-	 * @param string $postFix Postfix appended to the temporary file name, may be user controlled
67
-	 * @return string
68
-	 */
69
-	private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
70
-		if ($postFix !== '') {
71
-			$postFix = '.' . ltrim($postFix, '.');
72
-			$postFix = str_replace(['\\', '/'], '', $postFix);
73
-			$absolutePath .= '-';
74
-		}
61
+    /**
62
+     * Builds the filename with suffix and removes potential dangerous characters
63
+     * such as directory separators.
64
+     *
65
+     * @param string $absolutePath Absolute path to the file / folder
66
+     * @param string $postFix Postfix appended to the temporary file name, may be user controlled
67
+     * @return string
68
+     */
69
+    private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
70
+        if ($postFix !== '') {
71
+            $postFix = '.' . ltrim($postFix, '.');
72
+            $postFix = str_replace(['\\', '/'], '', $postFix);
73
+            $absolutePath .= '-';
74
+        }
75 75
 
76
-		return $absolutePath . $postFix;
77
-	}
76
+        return $absolutePath . $postFix;
77
+    }
78 78
 
79
-	/**
80
-	 * Create a temporary file and return the path
81
-	 *
82
-	 * @param string $postFix Postfix appended to the temporary file name
83
-	 * @return string
84
-	 */
85
-	public function getTemporaryFile($postFix = '') {
86
-		if (is_writable($this->tmpBaseDir)) {
87
-			// To create an unique file and prevent the risk of race conditions
88
-			// or duplicated temporary files by other means such as collisions
89
-			// we need to create the file using `tempnam` and append a possible
90
-			// postfix to it later
91
-			$file = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
92
-			$this->current[] = $file;
79
+    /**
80
+     * Create a temporary file and return the path
81
+     *
82
+     * @param string $postFix Postfix appended to the temporary file name
83
+     * @return string
84
+     */
85
+    public function getTemporaryFile($postFix = '') {
86
+        if (is_writable($this->tmpBaseDir)) {
87
+            // To create an unique file and prevent the risk of race conditions
88
+            // or duplicated temporary files by other means such as collisions
89
+            // we need to create the file using `tempnam` and append a possible
90
+            // postfix to it later
91
+            $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
92
+            $this->current[] = $file;
93 93
 
94
-			// If a postfix got specified sanitize it and create a postfixed
95
-			// temporary file
96
-			if ($postFix !== '') {
97
-				$fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
98
-				touch($fileNameWithPostfix);
99
-				chmod($fileNameWithPostfix, 0600);
100
-				$this->current[] = $fileNameWithPostfix;
101
-				return $fileNameWithPostfix;
102
-			}
94
+            // If a postfix got specified sanitize it and create a postfixed
95
+            // temporary file
96
+            if ($postFix !== '') {
97
+                $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
98
+                touch($fileNameWithPostfix);
99
+                chmod($fileNameWithPostfix, 0600);
100
+                $this->current[] = $fileNameWithPostfix;
101
+                return $fileNameWithPostfix;
102
+            }
103 103
 
104
-			return $file;
105
-		} else {
106
-			$this->log->warning(
107
-				'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions',
108
-				[
109
-					'dir' => $this->tmpBaseDir,
110
-				]
111
-			);
112
-			return false;
113
-		}
114
-	}
104
+            return $file;
105
+        } else {
106
+            $this->log->warning(
107
+                'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions',
108
+                [
109
+                    'dir' => $this->tmpBaseDir,
110
+                ]
111
+            );
112
+            return false;
113
+        }
114
+    }
115 115
 
116
-	/**
117
-	 * Create a temporary folder and return the path
118
-	 *
119
-	 * @param string $postFix Postfix appended to the temporary folder name
120
-	 * @return string
121
-	 */
122
-	public function getTemporaryFolder($postFix = '') {
123
-		if (is_writable($this->tmpBaseDir)) {
124
-			// To create an unique directory and prevent the risk of race conditions
125
-			// or duplicated temporary files by other means such as collisions
126
-			// we need to create the file using `tempnam` and append a possible
127
-			// postfix to it later
128
-			$uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
129
-			$this->current[] = $uniqueFileName;
116
+    /**
117
+     * Create a temporary folder and return the path
118
+     *
119
+     * @param string $postFix Postfix appended to the temporary folder name
120
+     * @return string
121
+     */
122
+    public function getTemporaryFolder($postFix = '') {
123
+        if (is_writable($this->tmpBaseDir)) {
124
+            // To create an unique directory and prevent the risk of race conditions
125
+            // or duplicated temporary files by other means such as collisions
126
+            // we need to create the file using `tempnam` and append a possible
127
+            // postfix to it later
128
+            $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
129
+            $this->current[] = $uniqueFileName;
130 130
 
131
-			// Build a name without postfix
132
-			$path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
133
-			mkdir($path, 0700);
134
-			$this->current[] = $path;
131
+            // Build a name without postfix
132
+            $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
133
+            mkdir($path, 0700);
134
+            $this->current[] = $path;
135 135
 
136
-			return $path . '/';
137
-		} else {
138
-			$this->log->warning(
139
-				'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
140
-				[
141
-					'dir' => $this->tmpBaseDir,
142
-				]
143
-			);
144
-			return false;
145
-		}
146
-	}
136
+            return $path . '/';
137
+        } else {
138
+            $this->log->warning(
139
+                'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
140
+                [
141
+                    'dir' => $this->tmpBaseDir,
142
+                ]
143
+            );
144
+            return false;
145
+        }
146
+    }
147 147
 
148
-	/**
149
-	 * Remove the temporary files and folders generated during this request
150
-	 */
151
-	public function clean() {
152
-		$this->cleanFiles($this->current);
153
-	}
148
+    /**
149
+     * Remove the temporary files and folders generated during this request
150
+     */
151
+    public function clean() {
152
+        $this->cleanFiles($this->current);
153
+    }
154 154
 
155
-	/**
156
-	 * @param string[] $files
157
-	 */
158
-	protected function cleanFiles($files) {
159
-		foreach ($files as $file) {
160
-			if (file_exists($file)) {
161
-				try {
162
-					\OC_Helper::rmdirr($file);
163
-				} catch (\UnexpectedValueException $ex) {
164
-					$this->log->warning(
165
-						"Error deleting temporary file/folder: {file} - Reason: {error}",
166
-						[
167
-							'file' => $file,
168
-							'error' => $ex->getMessage(),
169
-						]
170
-					);
171
-				}
172
-			}
173
-		}
174
-	}
155
+    /**
156
+     * @param string[] $files
157
+     */
158
+    protected function cleanFiles($files) {
159
+        foreach ($files as $file) {
160
+            if (file_exists($file)) {
161
+                try {
162
+                    \OC_Helper::rmdirr($file);
163
+                } catch (\UnexpectedValueException $ex) {
164
+                    $this->log->warning(
165
+                        "Error deleting temporary file/folder: {file} - Reason: {error}",
166
+                        [
167
+                            'file' => $file,
168
+                            'error' => $ex->getMessage(),
169
+                        ]
170
+                    );
171
+                }
172
+            }
173
+        }
174
+    }
175 175
 
176
-	/**
177
-	 * Remove old temporary files and folders that were failed to be cleaned
178
-	 */
179
-	public function cleanOld() {
180
-		$this->cleanFiles($this->getOldFiles());
181
-	}
176
+    /**
177
+     * Remove old temporary files and folders that were failed to be cleaned
178
+     */
179
+    public function cleanOld() {
180
+        $this->cleanFiles($this->getOldFiles());
181
+    }
182 182
 
183
-	/**
184
-	 * Get all temporary files and folders generated by oc older than an hour
185
-	 *
186
-	 * @return string[]
187
-	 */
188
-	protected function getOldFiles() {
189
-		$cutOfTime = time() - 3600;
190
-		$files = [];
191
-		$dh = opendir($this->tmpBaseDir);
192
-		if ($dh) {
193
-			while (($file = readdir($dh)) !== false) {
194
-				if (substr($file, 0, 7) === self::TMP_PREFIX) {
195
-					$path = $this->tmpBaseDir . '/' . $file;
196
-					$mtime = filemtime($path);
197
-					if ($mtime < $cutOfTime) {
198
-						$files[] = $path;
199
-					}
200
-				}
201
-			}
202
-		}
203
-		return $files;
204
-	}
183
+    /**
184
+     * Get all temporary files and folders generated by oc older than an hour
185
+     *
186
+     * @return string[]
187
+     */
188
+    protected function getOldFiles() {
189
+        $cutOfTime = time() - 3600;
190
+        $files = [];
191
+        $dh = opendir($this->tmpBaseDir);
192
+        if ($dh) {
193
+            while (($file = readdir($dh)) !== false) {
194
+                if (substr($file, 0, 7) === self::TMP_PREFIX) {
195
+                    $path = $this->tmpBaseDir . '/' . $file;
196
+                    $mtime = filemtime($path);
197
+                    if ($mtime < $cutOfTime) {
198
+                        $files[] = $path;
199
+                    }
200
+                }
201
+            }
202
+        }
203
+        return $files;
204
+    }
205 205
 
206
-	/**
207
-	 * Get the temporary base directory configured on the server
208
-	 *
209
-	 * @return string Path to the temporary directory or null
210
-	 * @throws \UnexpectedValueException
211
-	 */
212
-	public function getTempBaseDir() {
213
-		if ($this->tmpBaseDir) {
214
-			return $this->tmpBaseDir;
215
-		}
206
+    /**
207
+     * Get the temporary base directory configured on the server
208
+     *
209
+     * @return string Path to the temporary directory or null
210
+     * @throws \UnexpectedValueException
211
+     */
212
+    public function getTempBaseDir() {
213
+        if ($this->tmpBaseDir) {
214
+            return $this->tmpBaseDir;
215
+        }
216 216
 
217
-		$directories = [];
218
-		if ($temp = $this->config->getSystemValue('tempdirectory', null)) {
219
-			$directories[] = $temp;
220
-		}
221
-		if ($temp = $this->iniGetWrapper->get('upload_tmp_dir')) {
222
-			$directories[] = $temp;
223
-		}
224
-		if ($temp = getenv('TMP')) {
225
-			$directories[] = $temp;
226
-		}
227
-		if ($temp = getenv('TEMP')) {
228
-			$directories[] = $temp;
229
-		}
230
-		if ($temp = getenv('TMPDIR')) {
231
-			$directories[] = $temp;
232
-		}
233
-		if ($temp = sys_get_temp_dir()) {
234
-			$directories[] = $temp;
235
-		}
217
+        $directories = [];
218
+        if ($temp = $this->config->getSystemValue('tempdirectory', null)) {
219
+            $directories[] = $temp;
220
+        }
221
+        if ($temp = $this->iniGetWrapper->get('upload_tmp_dir')) {
222
+            $directories[] = $temp;
223
+        }
224
+        if ($temp = getenv('TMP')) {
225
+            $directories[] = $temp;
226
+        }
227
+        if ($temp = getenv('TEMP')) {
228
+            $directories[] = $temp;
229
+        }
230
+        if ($temp = getenv('TMPDIR')) {
231
+            $directories[] = $temp;
232
+        }
233
+        if ($temp = sys_get_temp_dir()) {
234
+            $directories[] = $temp;
235
+        }
236 236
 
237
-		foreach ($directories as $dir) {
238
-			if ($this->checkTemporaryDirectory($dir)) {
239
-				return $dir;
240
-			}
241
-		}
237
+        foreach ($directories as $dir) {
238
+            if ($this->checkTemporaryDirectory($dir)) {
239
+                return $dir;
240
+            }
241
+        }
242 242
 
243
-		$temp = tempnam(dirname(__FILE__), '');
244
-		if (file_exists($temp)) {
245
-			unlink($temp);
246
-			return dirname($temp);
247
-		}
248
-		throw new \UnexpectedValueException('Unable to detect system temporary directory');
249
-	}
243
+        $temp = tempnam(dirname(__FILE__), '');
244
+        if (file_exists($temp)) {
245
+            unlink($temp);
246
+            return dirname($temp);
247
+        }
248
+        throw new \UnexpectedValueException('Unable to detect system temporary directory');
249
+    }
250 250
 
251
-	/**
252
-	 * Check if a temporary directory is ready for use
253
-	 *
254
-	 * @param mixed $directory
255
-	 * @return bool
256
-	 */
257
-	private function checkTemporaryDirectory($directory) {
258
-		// suppress any possible errors caused by is_writable
259
-		// checks missing or invalid path or characters, wrong permissions etc
260
-		try {
261
-			if (is_writable($directory)) {
262
-				return true;
263
-			}
264
-		} catch (\Exception $e) {
265
-		}
266
-		$this->log->warning('Temporary directory {dir} is not present or writable',
267
-			['dir' => $directory]
268
-		);
269
-		return false;
270
-	}
251
+    /**
252
+     * Check if a temporary directory is ready for use
253
+     *
254
+     * @param mixed $directory
255
+     * @return bool
256
+     */
257
+    private function checkTemporaryDirectory($directory) {
258
+        // suppress any possible errors caused by is_writable
259
+        // checks missing or invalid path or characters, wrong permissions etc
260
+        try {
261
+            if (is_writable($directory)) {
262
+                return true;
263
+            }
264
+        } catch (\Exception $e) {
265
+        }
266
+        $this->log->warning('Temporary directory {dir} is not present or writable',
267
+            ['dir' => $directory]
268
+        );
269
+        return false;
270
+    }
271 271
 
272
-	/**
273
-	 * Override the temporary base directory
274
-	 *
275
-	 * @param string $directory
276
-	 */
277
-	public function overrideTempBaseDir($directory) {
278
-		$this->tmpBaseDir = $directory;
279
-	}
272
+    /**
273
+     * Override the temporary base directory
274
+     *
275
+     * @param string $directory
276
+     */
277
+    public function overrideTempBaseDir($directory) {
278
+        $this->tmpBaseDir = $directory;
279
+    }
280 280
 }
Please login to merge, or discard this patch.