Completed
Pull Request — master (#4617)
by Julius
14:00
created
lib/private/Archive/TAR.php 1 patch
Indentation   +331 added lines, -331 removed lines patch added patch discarded remove patch
@@ -36,355 +36,355 @@
 block discarded – undo
36 36
 use Icewind\Streams\CallbackWrapper;
37 37
 
38 38
 class TAR extends Archive {
39
-	const PLAIN = 0;
40
-	const GZIP = 1;
41
-	const BZIP = 2;
39
+    const PLAIN = 0;
40
+    const GZIP = 1;
41
+    const BZIP = 2;
42 42
 
43
-	private $fileList;
44
-	private $cachedHeaders;
43
+    private $fileList;
44
+    private $cachedHeaders;
45 45
 
46
-	/**
47
-	 * @var \Archive_Tar tar
48
-	 */
49
-	private $tar = null;
50
-	private $path;
46
+    /**
47
+     * @var \Archive_Tar tar
48
+     */
49
+    private $tar = null;
50
+    private $path;
51 51
 
52
-	/**
53
-	 * @param string $source
54
-	 */
55
-	function __construct($source) {
56
-		$types = array(null, 'gz', 'bz2');
57
-		$this->path = $source;
58
-		$this->tar = new \Archive_Tar($source, $types[self::getTarType($source)]);
59
-	}
52
+    /**
53
+     * @param string $source
54
+     */
55
+    function __construct($source) {
56
+        $types = array(null, 'gz', 'bz2');
57
+        $this->path = $source;
58
+        $this->tar = new \Archive_Tar($source, $types[self::getTarType($source)]);
59
+    }
60 60
 
61
-	/**
62
-	 * try to detect the type of tar compression
63
-	 *
64
-	 * @param string $file
65
-	 * @return integer
66
-	 */
67
-	static public function getTarType($file) {
68
-		if (strpos($file, '.')) {
69
-			$extension = substr($file, strrpos($file, '.'));
70
-			switch ($extension) {
71
-				case '.gz':
72
-				case '.tgz':
73
-					return self::GZIP;
74
-				case '.bz':
75
-				case '.bz2':
76
-					return self::BZIP;
77
-				case '.tar':
78
-					return self::PLAIN;
79
-				default:
80
-					return self::PLAIN;
81
-			}
82
-		} else {
83
-			return self::PLAIN;
84
-		}
85
-	}
61
+    /**
62
+     * try to detect the type of tar compression
63
+     *
64
+     * @param string $file
65
+     * @return integer
66
+     */
67
+    static public function getTarType($file) {
68
+        if (strpos($file, '.')) {
69
+            $extension = substr($file, strrpos($file, '.'));
70
+            switch ($extension) {
71
+                case '.gz':
72
+                case '.tgz':
73
+                    return self::GZIP;
74
+                case '.bz':
75
+                case '.bz2':
76
+                    return self::BZIP;
77
+                case '.tar':
78
+                    return self::PLAIN;
79
+                default:
80
+                    return self::PLAIN;
81
+            }
82
+        } else {
83
+            return self::PLAIN;
84
+        }
85
+    }
86 86
 
87
-	/**
88
-	 * add an empty folder to the archive
89
-	 *
90
-	 * @param string $path
91
-	 * @return bool
92
-	 */
93
-	function addFolder($path) {
94
-		$tmpBase = \OC::$server->getTempManager()->getTemporaryFolder();
95
-		if (substr($path, -1, 1) != '/') {
96
-			$path .= '/';
97
-		}
98
-		if ($this->fileExists($path)) {
99
-			return false;
100
-		}
101
-		$parts = explode('/', $path);
102
-		$folder = $tmpBase;
103
-		foreach ($parts as $part) {
104
-			$folder .= '/' . $part;
105
-			if (!is_dir($folder)) {
106
-				mkdir($folder);
107
-			}
108
-		}
109
-		$result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase);
110
-		rmdir($tmpBase . $path);
111
-		$this->fileList = false;
112
-		$this->cachedHeaders = false;
113
-		return $result;
114
-	}
87
+    /**
88
+     * add an empty folder to the archive
89
+     *
90
+     * @param string $path
91
+     * @return bool
92
+     */
93
+    function addFolder($path) {
94
+        $tmpBase = \OC::$server->getTempManager()->getTemporaryFolder();
95
+        if (substr($path, -1, 1) != '/') {
96
+            $path .= '/';
97
+        }
98
+        if ($this->fileExists($path)) {
99
+            return false;
100
+        }
101
+        $parts = explode('/', $path);
102
+        $folder = $tmpBase;
103
+        foreach ($parts as $part) {
104
+            $folder .= '/' . $part;
105
+            if (!is_dir($folder)) {
106
+                mkdir($folder);
107
+            }
108
+        }
109
+        $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase);
110
+        rmdir($tmpBase . $path);
111
+        $this->fileList = false;
112
+        $this->cachedHeaders = false;
113
+        return $result;
114
+    }
115 115
 
116
-	/**
117
-	 * add a file to the archive
118
-	 *
119
-	 * @param string $path
120
-	 * @param string $source either a local file or string data
121
-	 * @return bool
122
-	 */
123
-	function addFile($path, $source = '') {
124
-		if ($this->fileExists($path)) {
125
-			$this->remove($path);
126
-		}
127
-		if ($source and $source[0] == '/' and file_exists($source)) {
128
-			$source = file_get_contents($source);
129
-		}
130
-		$result = $this->tar->addString($path, $source);
131
-		$this->fileList = false;
132
-		$this->cachedHeaders = false;
133
-		return $result;
134
-	}
116
+    /**
117
+     * add a file to the archive
118
+     *
119
+     * @param string $path
120
+     * @param string $source either a local file or string data
121
+     * @return bool
122
+     */
123
+    function addFile($path, $source = '') {
124
+        if ($this->fileExists($path)) {
125
+            $this->remove($path);
126
+        }
127
+        if ($source and $source[0] == '/' and file_exists($source)) {
128
+            $source = file_get_contents($source);
129
+        }
130
+        $result = $this->tar->addString($path, $source);
131
+        $this->fileList = false;
132
+        $this->cachedHeaders = false;
133
+        return $result;
134
+    }
135 135
 
136
-	/**
137
-	 * rename a file or folder in the archive
138
-	 *
139
-	 * @param string $source
140
-	 * @param string $dest
141
-	 * @return bool
142
-	 */
143
-	function rename($source, $dest) {
144
-		//no proper way to delete, rename entire archive, rename file and remake archive
145
-		$tmp = \OCP\Files::tmpFolder();
146
-		$this->tar->extract($tmp);
147
-		rename($tmp . $source, $tmp . $dest);
148
-		$this->tar = null;
149
-		unlink($this->path);
150
-		$types = array(null, 'gz', 'bz');
151
-		$this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
152
-		$this->tar->createModify(array($tmp), '', $tmp . '/');
153
-		$this->fileList = false;
154
-		$this->cachedHeaders = false;
155
-		return true;
156
-	}
136
+    /**
137
+     * rename a file or folder in the archive
138
+     *
139
+     * @param string $source
140
+     * @param string $dest
141
+     * @return bool
142
+     */
143
+    function rename($source, $dest) {
144
+        //no proper way to delete, rename entire archive, rename file and remake archive
145
+        $tmp = \OCP\Files::tmpFolder();
146
+        $this->tar->extract($tmp);
147
+        rename($tmp . $source, $tmp . $dest);
148
+        $this->tar = null;
149
+        unlink($this->path);
150
+        $types = array(null, 'gz', 'bz');
151
+        $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
152
+        $this->tar->createModify(array($tmp), '', $tmp . '/');
153
+        $this->fileList = false;
154
+        $this->cachedHeaders = false;
155
+        return true;
156
+    }
157 157
 
158
-	/**
159
-	 * @param string $file
160
-	 */
161
-	private function getHeader($file) {
162
-		if (!$this->cachedHeaders) {
163
-			$this->cachedHeaders = $this->tar->listContent();
164
-		}
165
-		foreach ($this->cachedHeaders as $header) {
166
-			if ($file == $header['filename']
167
-				or $file . '/' == $header['filename']
168
-				or '/' . $file . '/' == $header['filename']
169
-				or '/' . $file == $header['filename']
170
-			) {
171
-				return $header;
172
-			}
173
-		}
174
-		return null;
175
-	}
158
+    /**
159
+     * @param string $file
160
+     */
161
+    private function getHeader($file) {
162
+        if (!$this->cachedHeaders) {
163
+            $this->cachedHeaders = $this->tar->listContent();
164
+        }
165
+        foreach ($this->cachedHeaders as $header) {
166
+            if ($file == $header['filename']
167
+                or $file . '/' == $header['filename']
168
+                or '/' . $file . '/' == $header['filename']
169
+                or '/' . $file == $header['filename']
170
+            ) {
171
+                return $header;
172
+            }
173
+        }
174
+        return null;
175
+    }
176 176
 
177
-	/**
178
-	 * get the uncompressed size of a file in the archive
179
-	 *
180
-	 * @param string $path
181
-	 * @return int
182
-	 */
183
-	function filesize($path) {
184
-		$stat = $this->getHeader($path);
185
-		return $stat['size'];
186
-	}
177
+    /**
178
+     * get the uncompressed size of a file in the archive
179
+     *
180
+     * @param string $path
181
+     * @return int
182
+     */
183
+    function filesize($path) {
184
+        $stat = $this->getHeader($path);
185
+        return $stat['size'];
186
+    }
187 187
 
188
-	/**
189
-	 * get the last modified time of a file in the archive
190
-	 *
191
-	 * @param string $path
192
-	 * @return int
193
-	 */
194
-	function mtime($path) {
195
-		$stat = $this->getHeader($path);
196
-		return $stat['mtime'];
197
-	}
188
+    /**
189
+     * get the last modified time of a file in the archive
190
+     *
191
+     * @param string $path
192
+     * @return int
193
+     */
194
+    function mtime($path) {
195
+        $stat = $this->getHeader($path);
196
+        return $stat['mtime'];
197
+    }
198 198
 
199
-	/**
200
-	 * get the files in a folder
201
-	 *
202
-	 * @param string $path
203
-	 * @return array
204
-	 */
205
-	function getFolder($path) {
206
-		$files = $this->getFiles();
207
-		$folderContent = array();
208
-		$pathLength = strlen($path);
209
-		foreach ($files as $file) {
210
-			if ($file[0] == '/') {
211
-				$file = substr($file, 1);
212
-			}
213
-			if (substr($file, 0, $pathLength) == $path and $file != $path) {
214
-				$result = substr($file, $pathLength);
215
-				if ($pos = strpos($result, '/')) {
216
-					$result = substr($result, 0, $pos + 1);
217
-				}
218
-				if (array_search($result, $folderContent) === false) {
219
-					$folderContent[] = $result;
220
-				}
221
-			}
222
-		}
223
-		return $folderContent;
224
-	}
199
+    /**
200
+     * get the files in a folder
201
+     *
202
+     * @param string $path
203
+     * @return array
204
+     */
205
+    function getFolder($path) {
206
+        $files = $this->getFiles();
207
+        $folderContent = array();
208
+        $pathLength = strlen($path);
209
+        foreach ($files as $file) {
210
+            if ($file[0] == '/') {
211
+                $file = substr($file, 1);
212
+            }
213
+            if (substr($file, 0, $pathLength) == $path and $file != $path) {
214
+                $result = substr($file, $pathLength);
215
+                if ($pos = strpos($result, '/')) {
216
+                    $result = substr($result, 0, $pos + 1);
217
+                }
218
+                if (array_search($result, $folderContent) === false) {
219
+                    $folderContent[] = $result;
220
+                }
221
+            }
222
+        }
223
+        return $folderContent;
224
+    }
225 225
 
226
-	/**
227
-	 * get all files in the archive
228
-	 *
229
-	 * @return array
230
-	 */
231
-	function getFiles() {
232
-		if ($this->fileList) {
233
-			return $this->fileList;
234
-		}
235
-		if (!$this->cachedHeaders) {
236
-			$this->cachedHeaders = $this->tar->listContent();
237
-		}
238
-		$files = array();
239
-		foreach ($this->cachedHeaders as $header) {
240
-			$files[] = $header['filename'];
241
-		}
242
-		$this->fileList = $files;
243
-		return $files;
244
-	}
226
+    /**
227
+     * get all files in the archive
228
+     *
229
+     * @return array
230
+     */
231
+    function getFiles() {
232
+        if ($this->fileList) {
233
+            return $this->fileList;
234
+        }
235
+        if (!$this->cachedHeaders) {
236
+            $this->cachedHeaders = $this->tar->listContent();
237
+        }
238
+        $files = array();
239
+        foreach ($this->cachedHeaders as $header) {
240
+            $files[] = $header['filename'];
241
+        }
242
+        $this->fileList = $files;
243
+        return $files;
244
+    }
245 245
 
246
-	/**
247
-	 * get the content of a file
248
-	 *
249
-	 * @param string $path
250
-	 * @return string
251
-	 */
252
-	function getFile($path) {
253
-		return $this->tar->extractInString($path);
254
-	}
246
+    /**
247
+     * get the content of a file
248
+     *
249
+     * @param string $path
250
+     * @return string
251
+     */
252
+    function getFile($path) {
253
+        return $this->tar->extractInString($path);
254
+    }
255 255
 
256
-	/**
257
-	 * extract a single file from the archive
258
-	 *
259
-	 * @param string $path
260
-	 * @param string $dest
261
-	 * @return bool
262
-	 */
263
-	function extractFile($path, $dest) {
264
-		$tmp = \OCP\Files::tmpFolder();
265
-		if (!$this->fileExists($path)) {
266
-			return false;
267
-		}
268
-		if ($this->fileExists('/' . $path)) {
269
-			$success = $this->tar->extractList(array('/' . $path), $tmp);
270
-		} else {
271
-			$success = $this->tar->extractList(array($path), $tmp);
272
-		}
273
-		if ($success) {
274
-			rename($tmp . $path, $dest);
275
-		}
276
-		\OCP\Files::rmdirr($tmp);
277
-		return $success;
278
-	}
256
+    /**
257
+     * extract a single file from the archive
258
+     *
259
+     * @param string $path
260
+     * @param string $dest
261
+     * @return bool
262
+     */
263
+    function extractFile($path, $dest) {
264
+        $tmp = \OCP\Files::tmpFolder();
265
+        if (!$this->fileExists($path)) {
266
+            return false;
267
+        }
268
+        if ($this->fileExists('/' . $path)) {
269
+            $success = $this->tar->extractList(array('/' . $path), $tmp);
270
+        } else {
271
+            $success = $this->tar->extractList(array($path), $tmp);
272
+        }
273
+        if ($success) {
274
+            rename($tmp . $path, $dest);
275
+        }
276
+        \OCP\Files::rmdirr($tmp);
277
+        return $success;
278
+    }
279 279
 
280
-	/**
281
-	 * extract the archive
282
-	 *
283
-	 * @param string $dest
284
-	 * @return bool
285
-	 */
286
-	function extract($dest) {
287
-		return $this->tar->extract($dest);
288
-	}
280
+    /**
281
+     * extract the archive
282
+     *
283
+     * @param string $dest
284
+     * @return bool
285
+     */
286
+    function extract($dest) {
287
+        return $this->tar->extract($dest);
288
+    }
289 289
 
290
-	/**
291
-	 * check if a file or folder exists in the archive
292
-	 *
293
-	 * @param string $path
294
-	 * @return bool
295
-	 */
296
-	function fileExists($path) {
297
-		$files = $this->getFiles();
298
-		if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) {
299
-			return true;
300
-		} else {
301
-			$folderPath = $path;
302
-			if (substr($folderPath, -1, 1) != '/') {
303
-				$folderPath .= '/';
304
-			}
305
-			$pathLength = strlen($folderPath);
306
-			foreach ($files as $file) {
307
-				if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) {
308
-					return true;
309
-				}
310
-			}
311
-		}
312
-		if ($path[0] != '/') { //not all programs agree on the use of a leading /
313
-			return $this->fileExists('/' . $path);
314
-		} else {
315
-			return false;
316
-		}
317
-	}
290
+    /**
291
+     * check if a file or folder exists in the archive
292
+     *
293
+     * @param string $path
294
+     * @return bool
295
+     */
296
+    function fileExists($path) {
297
+        $files = $this->getFiles();
298
+        if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) {
299
+            return true;
300
+        } else {
301
+            $folderPath = $path;
302
+            if (substr($folderPath, -1, 1) != '/') {
303
+                $folderPath .= '/';
304
+            }
305
+            $pathLength = strlen($folderPath);
306
+            foreach ($files as $file) {
307
+                if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) {
308
+                    return true;
309
+                }
310
+            }
311
+        }
312
+        if ($path[0] != '/') { //not all programs agree on the use of a leading /
313
+            return $this->fileExists('/' . $path);
314
+        } else {
315
+            return false;
316
+        }
317
+    }
318 318
 
319
-	/**
320
-	 * remove a file or folder from the archive
321
-	 *
322
-	 * @param string $path
323
-	 * @return bool
324
-	 */
325
-	function remove($path) {
326
-		if (!$this->fileExists($path)) {
327
-			return false;
328
-		}
329
-		$this->fileList = false;
330
-		$this->cachedHeaders = false;
331
-		//no proper way to delete, extract entire archive, delete file and remake archive
332
-		$tmp = \OCP\Files::tmpFolder();
333
-		$this->tar->extract($tmp);
334
-		\OCP\Files::rmdirr($tmp . $path);
335
-		$this->tar = null;
336
-		unlink($this->path);
337
-		$this->reopen();
338
-		$this->tar->createModify(array($tmp), '', $tmp);
339
-		return true;
340
-	}
319
+    /**
320
+     * remove a file or folder from the archive
321
+     *
322
+     * @param string $path
323
+     * @return bool
324
+     */
325
+    function remove($path) {
326
+        if (!$this->fileExists($path)) {
327
+            return false;
328
+        }
329
+        $this->fileList = false;
330
+        $this->cachedHeaders = false;
331
+        //no proper way to delete, extract entire archive, delete file and remake archive
332
+        $tmp = \OCP\Files::tmpFolder();
333
+        $this->tar->extract($tmp);
334
+        \OCP\Files::rmdirr($tmp . $path);
335
+        $this->tar = null;
336
+        unlink($this->path);
337
+        $this->reopen();
338
+        $this->tar->createModify(array($tmp), '', $tmp);
339
+        return true;
340
+    }
341 341
 
342
-	/**
343
-	 * get a file handler
344
-	 *
345
-	 * @param string $path
346
-	 * @param string $mode
347
-	 * @return resource
348
-	 */
349
-	function getStream($path, $mode) {
350
-		if (strrpos($path, '.') !== false) {
351
-			$ext = substr($path, strrpos($path, '.'));
352
-		} else {
353
-			$ext = '';
354
-		}
355
-		$tmpFile = \OCP\Files::tmpFile($ext);
356
-		if ($this->fileExists($path)) {
357
-			$this->extractFile($path, $tmpFile);
358
-		} elseif ($mode == 'r' or $mode == 'rb') {
359
-			return false;
360
-		}
361
-		if ($mode == 'r' or $mode == 'rb') {
362
-			return fopen($tmpFile, $mode);
363
-		} else {
364
-			$handle = fopen($tmpFile, $mode);
365
-			return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
366
-				$this->writeBack($tmpFile, $path);
367
-			});
368
-		}
369
-	}
342
+    /**
343
+     * get a file handler
344
+     *
345
+     * @param string $path
346
+     * @param string $mode
347
+     * @return resource
348
+     */
349
+    function getStream($path, $mode) {
350
+        if (strrpos($path, '.') !== false) {
351
+            $ext = substr($path, strrpos($path, '.'));
352
+        } else {
353
+            $ext = '';
354
+        }
355
+        $tmpFile = \OCP\Files::tmpFile($ext);
356
+        if ($this->fileExists($path)) {
357
+            $this->extractFile($path, $tmpFile);
358
+        } elseif ($mode == 'r' or $mode == 'rb') {
359
+            return false;
360
+        }
361
+        if ($mode == 'r' or $mode == 'rb') {
362
+            return fopen($tmpFile, $mode);
363
+        } else {
364
+            $handle = fopen($tmpFile, $mode);
365
+            return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
366
+                $this->writeBack($tmpFile, $path);
367
+            });
368
+        }
369
+    }
370 370
 
371
-	/**
372
-	 * write back temporary files
373
-	 */
374
-	function writeBack($tmpFile, $path) {
375
-		$this->addFile($path, $tmpFile);
376
-		unlink($tmpFile);
377
-	}
371
+    /**
372
+     * write back temporary files
373
+     */
374
+    function writeBack($tmpFile, $path) {
375
+        $this->addFile($path, $tmpFile);
376
+        unlink($tmpFile);
377
+    }
378 378
 
379
-	/**
380
-	 * reopen the archive to ensure everything is written
381
-	 */
382
-	private function reopen() {
383
-		if ($this->tar) {
384
-			$this->tar->_close();
385
-			$this->tar = null;
386
-		}
387
-		$types = array(null, 'gz', 'bz');
388
-		$this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
389
-	}
379
+    /**
380
+     * reopen the archive to ensure everything is written
381
+     */
382
+    private function reopen() {
383
+        if ($this->tar) {
384
+            $this->tar->_close();
385
+            $this->tar = null;
386
+        }
387
+        $types = array(null, 'gz', 'bz');
388
+        $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
389
+    }
390 390
 }
Please login to merge, or discard this patch.
lib/private/Archive/ZIP.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -34,199 +34,199 @@
 block discarded – undo
34 34
 use Icewind\Streams\CallbackWrapper;
35 35
 
36 36
 class ZIP extends Archive{
37
-	/**
38
-	 * @var \ZipArchive zip
39
-	 */
40
-	private $zip=null;
41
-	private $path;
37
+    /**
38
+     * @var \ZipArchive zip
39
+     */
40
+    private $zip=null;
41
+    private $path;
42 42
 
43
-	/**
44
-	 * @param string $source
45
-	 */
46
-	function __construct($source) {
47
-		$this->path=$source;
48
-		$this->zip=new \ZipArchive();
49
-		if($this->zip->open($source, \ZipArchive::CREATE)) {
50
-		}else{
51
-			\OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN);
52
-		}
53
-	}
54
-	/**
55
-	 * add an empty folder to the archive
56
-	 * @param string $path
57
-	 * @return bool
58
-	 */
59
-	function addFolder($path) {
60
-		return $this->zip->addEmptyDir($path);
61
-	}
62
-	/**
63
-	 * add a file to the archive
64
-	 * @param string $path
65
-	 * @param string $source either a local file or string data
66
-	 * @return bool
67
-	 */
68
-	function addFile($path, $source='') {
69
-		if($source and $source[0]=='/' and file_exists($source)) {
70
-			$result=$this->zip->addFile($source, $path);
71
-		}else{
72
-			$result=$this->zip->addFromString($path, $source);
73
-		}
74
-		if($result) {
75
-			$this->zip->close();//close and reopen to save the zip
76
-			$this->zip->open($this->path);
77
-		}
78
-		return $result;
79
-	}
80
-	/**
81
-	 * rename a file or folder in the archive
82
-	 * @param string $source
83
-	 * @param string $dest
84
-	 * @return boolean|null
85
-	 */
86
-	function rename($source, $dest) {
87
-		$source=$this->stripPath($source);
88
-		$dest=$this->stripPath($dest);
89
-		$this->zip->renameName($source, $dest);
90
-	}
91
-	/**
92
-	 * get the uncompressed size of a file in the archive
93
-	 * @param string $path
94
-	 * @return int
95
-	 */
96
-	function filesize($path) {
97
-		$stat=$this->zip->statName($path);
98
-		return $stat['size'];
99
-	}
100
-	/**
101
-	 * get the last modified time of a file in the archive
102
-	 * @param string $path
103
-	 * @return int
104
-	 */
105
-	function mtime($path) {
106
-		return filemtime($this->path);
107
-	}
108
-	/**
109
-	 * get the files in a folder
110
-	 * @param string $path
111
-	 * @return array
112
-	 */
113
-	function getFolder($path) {
114
-		$files=$this->getFiles();
115
-		$folderContent=array();
116
-		$pathLength=strlen($path);
117
-		foreach($files as $file) {
118
-			if(substr($file, 0, $pathLength)==$path and $file!=$path) {
119
-				if(strrpos(substr($file, 0, -1), '/')<=$pathLength) {
120
-					$folderContent[]=substr($file, $pathLength);
121
-				}
122
-			}
123
-		}
124
-		return $folderContent;
125
-	}
126
-	/**
127
-	 * get all files in the archive
128
-	 * @return array
129
-	 */
130
-	function getFiles() {
131
-		$fileCount=$this->zip->numFiles;
132
-		$files=array();
133
-		for($i=0;$i<$fileCount;$i++) {
134
-			$files[]=$this->zip->getNameIndex($i);
135
-		}
136
-		return $files;
137
-	}
138
-	/**
139
-	 * get the content of a file
140
-	 * @param string $path
141
-	 * @return string
142
-	 */
143
-	function getFile($path) {
144
-		return $this->zip->getFromName($path);
145
-	}
146
-	/**
147
-	 * extract a single file from the archive
148
-	 * @param string $path
149
-	 * @param string $dest
150
-	 * @return boolean|null
151
-	 */
152
-	function extractFile($path, $dest) {
153
-		$fp = $this->zip->getStream($path);
154
-		file_put_contents($dest, $fp);
155
-	}
156
-	/**
157
-	 * extract the archive
158
-	 * @param string $dest
159
-	 * @return bool
160
-	 */
161
-	function extract($dest) {
162
-		return $this->zip->extractTo($dest);
163
-	}
164
-	/**
165
-	 * check if a file or folder exists in the archive
166
-	 * @param string $path
167
-	 * @return bool
168
-	 */
169
-	function fileExists($path) {
170
-		return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false);
171
-	}
172
-	/**
173
-	 * remove a file or folder from the archive
174
-	 * @param string $path
175
-	 * @return bool
176
-	 */
177
-	function remove($path) {
178
-		if($this->fileExists($path.'/')) {
179
-			return $this->zip->deleteName($path.'/');
180
-		}else{
181
-			return $this->zip->deleteName($path);
182
-		}
183
-	}
184
-	/**
185
-	 * get a file handler
186
-	 * @param string $path
187
-	 * @param string $mode
188
-	 * @return resource
189
-	 */
190
-	function getStream($path, $mode) {
191
-		if($mode=='r' or $mode=='rb') {
192
-			return $this->zip->getStream($path);
193
-		} else {
194
-			//since we can't directly get a writable stream,
195
-			//make a temp copy of the file and put it back
196
-			//in the archive when the stream is closed
197
-			if(strrpos($path, '.')!==false) {
198
-				$ext=substr($path, strrpos($path, '.'));
199
-			}else{
200
-				$ext='';
201
-			}
202
-			$tmpFile=\OCP\Files::tmpFile($ext);
203
-			if($this->fileExists($path)) {
204
-				$this->extractFile($path, $tmpFile);
205
-			}
206
-			$handle = fopen($tmpFile, $mode);
207
-			return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
208
-				$this->writeBack($tmpFile, $path);
209
-			});
210
-		}
211
-	}
43
+    /**
44
+     * @param string $source
45
+     */
46
+    function __construct($source) {
47
+        $this->path=$source;
48
+        $this->zip=new \ZipArchive();
49
+        if($this->zip->open($source, \ZipArchive::CREATE)) {
50
+        }else{
51
+            \OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN);
52
+        }
53
+    }
54
+    /**
55
+     * add an empty folder to the archive
56
+     * @param string $path
57
+     * @return bool
58
+     */
59
+    function addFolder($path) {
60
+        return $this->zip->addEmptyDir($path);
61
+    }
62
+    /**
63
+     * add a file to the archive
64
+     * @param string $path
65
+     * @param string $source either a local file or string data
66
+     * @return bool
67
+     */
68
+    function addFile($path, $source='') {
69
+        if($source and $source[0]=='/' and file_exists($source)) {
70
+            $result=$this->zip->addFile($source, $path);
71
+        }else{
72
+            $result=$this->zip->addFromString($path, $source);
73
+        }
74
+        if($result) {
75
+            $this->zip->close();//close and reopen to save the zip
76
+            $this->zip->open($this->path);
77
+        }
78
+        return $result;
79
+    }
80
+    /**
81
+     * rename a file or folder in the archive
82
+     * @param string $source
83
+     * @param string $dest
84
+     * @return boolean|null
85
+     */
86
+    function rename($source, $dest) {
87
+        $source=$this->stripPath($source);
88
+        $dest=$this->stripPath($dest);
89
+        $this->zip->renameName($source, $dest);
90
+    }
91
+    /**
92
+     * get the uncompressed size of a file in the archive
93
+     * @param string $path
94
+     * @return int
95
+     */
96
+    function filesize($path) {
97
+        $stat=$this->zip->statName($path);
98
+        return $stat['size'];
99
+    }
100
+    /**
101
+     * get the last modified time of a file in the archive
102
+     * @param string $path
103
+     * @return int
104
+     */
105
+    function mtime($path) {
106
+        return filemtime($this->path);
107
+    }
108
+    /**
109
+     * get the files in a folder
110
+     * @param string $path
111
+     * @return array
112
+     */
113
+    function getFolder($path) {
114
+        $files=$this->getFiles();
115
+        $folderContent=array();
116
+        $pathLength=strlen($path);
117
+        foreach($files as $file) {
118
+            if(substr($file, 0, $pathLength)==$path and $file!=$path) {
119
+                if(strrpos(substr($file, 0, -1), '/')<=$pathLength) {
120
+                    $folderContent[]=substr($file, $pathLength);
121
+                }
122
+            }
123
+        }
124
+        return $folderContent;
125
+    }
126
+    /**
127
+     * get all files in the archive
128
+     * @return array
129
+     */
130
+    function getFiles() {
131
+        $fileCount=$this->zip->numFiles;
132
+        $files=array();
133
+        for($i=0;$i<$fileCount;$i++) {
134
+            $files[]=$this->zip->getNameIndex($i);
135
+        }
136
+        return $files;
137
+    }
138
+    /**
139
+     * get the content of a file
140
+     * @param string $path
141
+     * @return string
142
+     */
143
+    function getFile($path) {
144
+        return $this->zip->getFromName($path);
145
+    }
146
+    /**
147
+     * extract a single file from the archive
148
+     * @param string $path
149
+     * @param string $dest
150
+     * @return boolean|null
151
+     */
152
+    function extractFile($path, $dest) {
153
+        $fp = $this->zip->getStream($path);
154
+        file_put_contents($dest, $fp);
155
+    }
156
+    /**
157
+     * extract the archive
158
+     * @param string $dest
159
+     * @return bool
160
+     */
161
+    function extract($dest) {
162
+        return $this->zip->extractTo($dest);
163
+    }
164
+    /**
165
+     * check if a file or folder exists in the archive
166
+     * @param string $path
167
+     * @return bool
168
+     */
169
+    function fileExists($path) {
170
+        return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false);
171
+    }
172
+    /**
173
+     * remove a file or folder from the archive
174
+     * @param string $path
175
+     * @return bool
176
+     */
177
+    function remove($path) {
178
+        if($this->fileExists($path.'/')) {
179
+            return $this->zip->deleteName($path.'/');
180
+        }else{
181
+            return $this->zip->deleteName($path);
182
+        }
183
+    }
184
+    /**
185
+     * get a file handler
186
+     * @param string $path
187
+     * @param string $mode
188
+     * @return resource
189
+     */
190
+    function getStream($path, $mode) {
191
+        if($mode=='r' or $mode=='rb') {
192
+            return $this->zip->getStream($path);
193
+        } else {
194
+            //since we can't directly get a writable stream,
195
+            //make a temp copy of the file and put it back
196
+            //in the archive when the stream is closed
197
+            if(strrpos($path, '.')!==false) {
198
+                $ext=substr($path, strrpos($path, '.'));
199
+            }else{
200
+                $ext='';
201
+            }
202
+            $tmpFile=\OCP\Files::tmpFile($ext);
203
+            if($this->fileExists($path)) {
204
+                $this->extractFile($path, $tmpFile);
205
+            }
206
+            $handle = fopen($tmpFile, $mode);
207
+            return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
208
+                $this->writeBack($tmpFile, $path);
209
+            });
210
+        }
211
+    }
212 212
 
213
-	/**
214
-	 * write back temporary files
215
-	 */
216
-	function writeBack($tmpFile, $path) {
217
-		$this->addFile($path, $tmpFile);
218
-		unlink($tmpFile);
219
-	}
213
+    /**
214
+     * write back temporary files
215
+     */
216
+    function writeBack($tmpFile, $path) {
217
+        $this->addFile($path, $tmpFile);
218
+        unlink($tmpFile);
219
+    }
220 220
 
221
-	/**
222
-	 * @param string $path
223
-	 * @return string
224
-	 */
225
-	private function stripPath($path) {
226
-		if(!$path || $path[0]=='/') {
227
-			return substr($path, 1);
228
-		}else{
229
-			return $path;
230
-		}
231
-	}
221
+    /**
222
+     * @param string $path
223
+     * @return string
224
+     */
225
+    private function stripPath($path) {
226
+        if(!$path || $path[0]=='/') {
227
+            return substr($path, 1);
228
+        }else{
229
+            return $path;
230
+        }
231
+    }
232 232
 }
Please login to merge, or discard this patch.
lib/private/Archive/Archive.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -33,111 +33,111 @@
 block discarded – undo
33 33
 namespace OC\Archive;
34 34
 
35 35
 abstract class Archive {
36
-	/**
37
-	 * @param $source
38
-	 */
39
-	abstract function __construct($source);
40
-	/**
41
-	 * add an empty folder to the archive
42
-	 * @param string $path
43
-	 * @return bool
44
-	 */
45
-	abstract function addFolder($path);
46
-	/**
47
-	 * add a file to the archive
48
-	 * @param string $path
49
-	 * @param string $source either a local file or string data
50
-	 * @return bool
51
-	 */
52
-	abstract function addFile($path, $source='');
53
-	/**
54
-	 * rename a file or folder in the archive
55
-	 * @param string $source
56
-	 * @param string $dest
57
-	 * @return bool
58
-	 */
59
-	abstract function rename($source, $dest);
60
-	/**
61
-	 * get the uncompressed size of a file in the archive
62
-	 * @param string $path
63
-	 * @return int
64
-	 */
65
-	abstract function filesize($path);
66
-	/**
67
-	 * get the last modified time of a file in the archive
68
-	 * @param string $path
69
-	 * @return int
70
-	 */
71
-	abstract function mtime($path);
72
-	/**
73
-	 * get the files in a folder
74
-	 * @param string $path
75
-	 * @return array
76
-	 */
77
-	abstract function getFolder($path);
78
-	/**
79
-	 * get all files in the archive
80
-	 * @return array
81
-	 */
82
-	abstract function getFiles();
83
-	/**
84
-	 * get the content of a file
85
-	 * @param string $path
86
-	 * @return string
87
-	 */
88
-	abstract function getFile($path);
89
-	/**
90
-	 * extract a single file from the archive
91
-	 * @param string $path
92
-	 * @param string $dest
93
-	 * @return bool
94
-	 */
95
-	abstract function extractFile($path, $dest);
96
-	/**
97
-	 * extract the archive
98
-	 * @param string $dest
99
-	 * @return bool
100
-	 */
101
-	abstract function extract($dest);
102
-	/**
103
-	 * check if a file or folder exists in the archive
104
-	 * @param string $path
105
-	 * @return bool
106
-	 */
107
-	abstract function fileExists($path);
108
-	/**
109
-	 * remove a file or folder from the archive
110
-	 * @param string $path
111
-	 * @return bool
112
-	 */
113
-	abstract function remove($path);
114
-	/**
115
-	 * get a file handler
116
-	 * @param string $path
117
-	 * @param string $mode
118
-	 * @return resource
119
-	 */
120
-	abstract function getStream($path, $mode);
121
-	/**
122
-	 * add a folder and all its content
123
-	 * @param string $path
124
-	 * @param string $source
125
-	 * @return boolean|null
126
-	 */
127
-	function addRecursive($path, $source) {
128
-		$dh = opendir($source);
129
-		if(is_resource($dh)) {
130
-			$this->addFolder($path);
131
-			while (($file = readdir($dh)) !== false) {
132
-				if($file=='.' or $file=='..') {
133
-					continue;
134
-				}
135
-				if(is_dir($source.'/'.$file)) {
136
-					$this->addRecursive($path.'/'.$file, $source.'/'.$file);
137
-				}else{
138
-					$this->addFile($path.'/'.$file, $source.'/'.$file);
139
-				}
140
-			}
141
-		}
142
-	}
36
+    /**
37
+     * @param $source
38
+     */
39
+    abstract function __construct($source);
40
+    /**
41
+     * add an empty folder to the archive
42
+     * @param string $path
43
+     * @return bool
44
+     */
45
+    abstract function addFolder($path);
46
+    /**
47
+     * add a file to the archive
48
+     * @param string $path
49
+     * @param string $source either a local file or string data
50
+     * @return bool
51
+     */
52
+    abstract function addFile($path, $source='');
53
+    /**
54
+     * rename a file or folder in the archive
55
+     * @param string $source
56
+     * @param string $dest
57
+     * @return bool
58
+     */
59
+    abstract function rename($source, $dest);
60
+    /**
61
+     * get the uncompressed size of a file in the archive
62
+     * @param string $path
63
+     * @return int
64
+     */
65
+    abstract function filesize($path);
66
+    /**
67
+     * get the last modified time of a file in the archive
68
+     * @param string $path
69
+     * @return int
70
+     */
71
+    abstract function mtime($path);
72
+    /**
73
+     * get the files in a folder
74
+     * @param string $path
75
+     * @return array
76
+     */
77
+    abstract function getFolder($path);
78
+    /**
79
+     * get all files in the archive
80
+     * @return array
81
+     */
82
+    abstract function getFiles();
83
+    /**
84
+     * get the content of a file
85
+     * @param string $path
86
+     * @return string
87
+     */
88
+    abstract function getFile($path);
89
+    /**
90
+     * extract a single file from the archive
91
+     * @param string $path
92
+     * @param string $dest
93
+     * @return bool
94
+     */
95
+    abstract function extractFile($path, $dest);
96
+    /**
97
+     * extract the archive
98
+     * @param string $dest
99
+     * @return bool
100
+     */
101
+    abstract function extract($dest);
102
+    /**
103
+     * check if a file or folder exists in the archive
104
+     * @param string $path
105
+     * @return bool
106
+     */
107
+    abstract function fileExists($path);
108
+    /**
109
+     * remove a file or folder from the archive
110
+     * @param string $path
111
+     * @return bool
112
+     */
113
+    abstract function remove($path);
114
+    /**
115
+     * get a file handler
116
+     * @param string $path
117
+     * @param string $mode
118
+     * @return resource
119
+     */
120
+    abstract function getStream($path, $mode);
121
+    /**
122
+     * add a folder and all its content
123
+     * @param string $path
124
+     * @param string $source
125
+     * @return boolean|null
126
+     */
127
+    function addRecursive($path, $source) {
128
+        $dh = opendir($source);
129
+        if(is_resource($dh)) {
130
+            $this->addFolder($path);
131
+            while (($file = readdir($dh)) !== false) {
132
+                if($file=='.' or $file=='..') {
133
+                    continue;
134
+                }
135
+                if(is_dir($source.'/'.$file)) {
136
+                    $this->addRecursive($path.'/'.$file, $source.'/'.$file);
137
+                }else{
138
+                    $this->addFile($path.'/'.$file, $source.'/'.$file);
139
+                }
140
+            }
141
+        }
142
+    }
143 143
 }
Please login to merge, or discard this patch.
lib/private/NaturalSort_DefaultCollator.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -25,14 +25,14 @@
 block discarded – undo
25 25
 namespace OC;
26 26
 
27 27
 class NaturalSort_DefaultCollator {
28
-	public function compare($a, $b) {
29
-		$result = strcasecmp($a, $b);
30
-		if ($result === 0) {
31
-			if ($a === $b) {
32
-				return 0;
33
-			}
34
-			return ($a > $b) ? -1 : 1;
35
-		}
36
-		return ($result < 0) ? -1 : 1;
37
-	}
28
+    public function compare($a, $b) {
29
+        $result = strcasecmp($a, $b);
30
+        if ($result === 0) {
31
+            if ($a === $b) {
32
+                return 0;
33
+            }
34
+            return ($a > $b) ? -1 : 1;
35
+        }
36
+        return ($result < 0) ? -1 : 1;
37
+    }
38 38
 }
Please login to merge, or discard this patch.
lib/private/Migration/BackgroundRepair.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -37,81 +37,81 @@
 block discarded – undo
37 37
  */
38 38
 class BackgroundRepair extends TimedJob {
39 39
 
40
-	/** @var IJobList */
41
-	private $jobList;
40
+    /** @var IJobList */
41
+    private $jobList;
42 42
 
43
-	/** @var ILogger */
44
-	private $logger;
43
+    /** @var ILogger */
44
+    private $logger;
45 45
 
46
-	/** @var EventDispatcher */
47
-	private $dispatcher;
46
+    /** @var EventDispatcher */
47
+    private $dispatcher;
48 48
 
49
-	public function setDispatcher(EventDispatcher $dispatcher) {
50
-		$this->dispatcher = $dispatcher;
51
-	}
52
-	/**
53
-	 * run the job, then remove it from the job list
54
-	 *
55
-	 * @param JobList $jobList
56
-	 * @param ILogger $logger
57
-	 */
58
-	public function execute($jobList, ILogger $logger = null) {
59
-		// add an interval of 15 mins
60
-		$this->setInterval(15*60);
49
+    public function setDispatcher(EventDispatcher $dispatcher) {
50
+        $this->dispatcher = $dispatcher;
51
+    }
52
+    /**
53
+     * run the job, then remove it from the job list
54
+     *
55
+     * @param JobList $jobList
56
+     * @param ILogger $logger
57
+     */
58
+    public function execute($jobList, ILogger $logger = null) {
59
+        // add an interval of 15 mins
60
+        $this->setInterval(15*60);
61 61
 
62
-		$this->jobList = $jobList;
63
-		$this->logger = $logger;
64
-		parent::execute($jobList, $logger);
65
-	}
62
+        $this->jobList = $jobList;
63
+        $this->logger = $logger;
64
+        parent::execute($jobList, $logger);
65
+    }
66 66
 
67
-	/**
68
-	 * @param array $argument
69
-	 * @throws \Exception
70
-	 * @throws \OC\NeedsUpdateException
71
-	 */
72
-	protected function run($argument) {
73
-		if (!isset($argument['app']) || !isset($argument['step'])) {
74
-			// remove the job - we can never execute it
75
-			$this->jobList->remove($this, $this->argument);
76
-			return;
77
-		}
78
-		$app = $argument['app'];
67
+    /**
68
+     * @param array $argument
69
+     * @throws \Exception
70
+     * @throws \OC\NeedsUpdateException
71
+     */
72
+    protected function run($argument) {
73
+        if (!isset($argument['app']) || !isset($argument['step'])) {
74
+            // remove the job - we can never execute it
75
+            $this->jobList->remove($this, $this->argument);
76
+            return;
77
+        }
78
+        $app = $argument['app'];
79 79
 
80
-		try {
81
-			$this->loadApp($app);
82
-		} catch (NeedsUpdateException $ex) {
83
-			// as long as the app is not yet done with it's offline migration
84
-			// we better not start with the live migration
85
-			return;
86
-		}
80
+        try {
81
+            $this->loadApp($app);
82
+        } catch (NeedsUpdateException $ex) {
83
+            // as long as the app is not yet done with it's offline migration
84
+            // we better not start with the live migration
85
+            return;
86
+        }
87 87
 
88
-		$step = $argument['step'];
89
-		$repair = new Repair([], $this->dispatcher);
90
-		try {
91
-			$repair->addStep($step);
92
-		} catch (\Exception $ex) {
93
-			$this->logger->logException($ex,[
94
-				'app' => 'migration'
95
-			]);
88
+        $step = $argument['step'];
89
+        $repair = new Repair([], $this->dispatcher);
90
+        try {
91
+            $repair->addStep($step);
92
+        } catch (\Exception $ex) {
93
+            $this->logger->logException($ex,[
94
+                'app' => 'migration'
95
+            ]);
96 96
 
97
-			// remove the job - we can never execute it
98
-			$this->jobList->remove($this, $this->argument);
99
-			return;
100
-		}
97
+            // remove the job - we can never execute it
98
+            $this->jobList->remove($this, $this->argument);
99
+            return;
100
+        }
101 101
 
102
-		// execute the repair step
103
-		$repair->run();
102
+        // execute the repair step
103
+        $repair->run();
104 104
 
105
-		// remove the job once executed successfully
106
-		$this->jobList->remove($this, $this->argument);
107
-	}
105
+        // remove the job once executed successfully
106
+        $this->jobList->remove($this, $this->argument);
107
+    }
108 108
 
109
-	/**
110
-	 * @codeCoverageIgnore
111
-	 * @param $app
112
-	 * @throws NeedsUpdateException
113
-	 */
114
-	protected function loadApp($app) {
115
-		OC_App::loadApp($app);
116
-	}
109
+    /**
110
+     * @codeCoverageIgnore
111
+     * @param $app
112
+     * @throws NeedsUpdateException
113
+     */
114
+    protected function loadApp($app) {
115
+        OC_App::loadApp($app);
116
+    }
117 117
 }
Please login to merge, or discard this patch.
lib/private/Command/AsyncBus.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -30,112 +30,112 @@
 block discarded – undo
30 30
  * Asynchronous command bus that uses the background job system as backend
31 31
  */
32 32
 class AsyncBus implements IBus {
33
-	/**
34
-	 * @var \OCP\BackgroundJob\IJobList
35
-	 */
36
-	private $jobList;
33
+    /**
34
+     * @var \OCP\BackgroundJob\IJobList
35
+     */
36
+    private $jobList;
37 37
 
38
-	/**
39
-	 * List of traits for command which require sync execution
40
-	 *
41
-	 * @var string[]
42
-	 */
43
-	private $syncTraits = [];
38
+    /**
39
+     * List of traits for command which require sync execution
40
+     *
41
+     * @var string[]
42
+     */
43
+    private $syncTraits = [];
44 44
 
45
-	/**
46
-	 * @param \OCP\BackgroundJob\IJobList $jobList
47
-	 */
48
-	function __construct($jobList) {
49
-		$this->jobList = $jobList;
50
-	}
45
+    /**
46
+     * @param \OCP\BackgroundJob\IJobList $jobList
47
+     */
48
+    function __construct($jobList) {
49
+        $this->jobList = $jobList;
50
+    }
51 51
 
52
-	/**
53
-	 * Schedule a command to be fired
54
-	 *
55
-	 * @param \OCP\Command\ICommand | callable $command
56
-	 */
57
-	public function push($command) {
58
-		if ($this->canRunAsync($command)) {
59
-			$this->jobList->add($this->getJobClass($command), $this->serializeCommand($command));
60
-		} else {
61
-			$this->runCommand($command);
62
-		}
63
-	}
52
+    /**
53
+     * Schedule a command to be fired
54
+     *
55
+     * @param \OCP\Command\ICommand | callable $command
56
+     */
57
+    public function push($command) {
58
+        if ($this->canRunAsync($command)) {
59
+            $this->jobList->add($this->getJobClass($command), $this->serializeCommand($command));
60
+        } else {
61
+            $this->runCommand($command);
62
+        }
63
+    }
64 64
 
65
-	/**
66
-	 * Require all commands using a trait to be run synchronous
67
-	 *
68
-	 * @param string $trait
69
-	 */
70
-	public function requireSync($trait) {
71
-		$this->syncTraits[] = trim($trait, '\\');
72
-	}
65
+    /**
66
+     * Require all commands using a trait to be run synchronous
67
+     *
68
+     * @param string $trait
69
+     */
70
+    public function requireSync($trait) {
71
+        $this->syncTraits[] = trim($trait, '\\');
72
+    }
73 73
 
74
-	/**
75
-	 * @param \OCP\Command\ICommand | callable $command
76
-	 */
77
-	private function runCommand($command) {
78
-		if ($command instanceof ICommand) {
79
-			$command->handle();
80
-		} else {
81
-			$command();
82
-		}
83
-	}
74
+    /**
75
+     * @param \OCP\Command\ICommand | callable $command
76
+     */
77
+    private function runCommand($command) {
78
+        if ($command instanceof ICommand) {
79
+            $command->handle();
80
+        } else {
81
+            $command();
82
+        }
83
+    }
84 84
 
85
-	/**
86
-	 * @param \OCP\Command\ICommand | callable $command
87
-	 * @return string
88
-	 */
89
-	private function getJobClass($command) {
90
-		if ($command instanceof \Closure) {
91
-			return 'OC\Command\ClosureJob';
92
-		} else if (is_callable($command)) {
93
-			return 'OC\Command\CallableJob';
94
-		} else if ($command instanceof ICommand) {
95
-			return 'OC\Command\CommandJob';
96
-		} else {
97
-			throw new \InvalidArgumentException('Invalid command');
98
-		}
99
-	}
85
+    /**
86
+     * @param \OCP\Command\ICommand | callable $command
87
+     * @return string
88
+     */
89
+    private function getJobClass($command) {
90
+        if ($command instanceof \Closure) {
91
+            return 'OC\Command\ClosureJob';
92
+        } else if (is_callable($command)) {
93
+            return 'OC\Command\CallableJob';
94
+        } else if ($command instanceof ICommand) {
95
+            return 'OC\Command\CommandJob';
96
+        } else {
97
+            throw new \InvalidArgumentException('Invalid command');
98
+        }
99
+    }
100 100
 
101
-	/**
102
-	 * @param \OCP\Command\ICommand | callable $command
103
-	 * @return string
104
-	 */
105
-	private function serializeCommand($command) {
106
-		if ($command instanceof \Closure) {
107
-			$serializer = new Serializer();
108
-			return $serializer->serialize($command);
109
-		} else if (is_callable($command) or $command instanceof ICommand) {
110
-			return serialize($command);
111
-		} else {
112
-			throw new \InvalidArgumentException('Invalid command');
113
-		}
114
-	}
101
+    /**
102
+     * @param \OCP\Command\ICommand | callable $command
103
+     * @return string
104
+     */
105
+    private function serializeCommand($command) {
106
+        if ($command instanceof \Closure) {
107
+            $serializer = new Serializer();
108
+            return $serializer->serialize($command);
109
+        } else if (is_callable($command) or $command instanceof ICommand) {
110
+            return serialize($command);
111
+        } else {
112
+            throw new \InvalidArgumentException('Invalid command');
113
+        }
114
+    }
115 115
 
116
-	/**
117
-	 * @param \OCP\Command\ICommand | callable $command
118
-	 * @return bool
119
-	 */
120
-	private function canRunAsync($command) {
121
-		$traits = $this->getTraits($command);
122
-		foreach ($traits as $trait) {
123
-			if (array_search($trait, $this->syncTraits) !== false) {
124
-				return false;
125
-			}
126
-		}
127
-		return true;
128
-	}
116
+    /**
117
+     * @param \OCP\Command\ICommand | callable $command
118
+     * @return bool
119
+     */
120
+    private function canRunAsync($command) {
121
+        $traits = $this->getTraits($command);
122
+        foreach ($traits as $trait) {
123
+            if (array_search($trait, $this->syncTraits) !== false) {
124
+                return false;
125
+            }
126
+        }
127
+        return true;
128
+    }
129 129
 
130
-	/**
131
-	 * @param \OCP\Command\ICommand | callable $command
132
-	 * @return string[]
133
-	 */
134
-	private function getTraits($command) {
135
-		if ($command instanceof ICommand) {
136
-			return class_uses($command);
137
-		} else {
138
-			return [];
139
-		}
140
-	}
130
+    /**
131
+     * @param \OCP\Command\ICommand | callable $command
132
+     * @return string[]
133
+     */
134
+    private function getTraits($command) {
135
+        if ($command instanceof ICommand) {
136
+            return class_uses($command);
137
+        } else {
138
+            return [];
139
+        }
140
+    }
141 141
 }
Please login to merge, or discard this patch.
lib/private/Command/QueueBus.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -26,48 +26,48 @@
 block discarded – undo
26 26
 use OCP\Command\ICommand;
27 27
 
28 28
 class QueueBus implements IBus {
29
-	/**
30
-	 * @var (ICommand|callable)[]
31
-	 */
32
-	private $queue = [];
29
+    /**
30
+     * @var (ICommand|callable)[]
31
+     */
32
+    private $queue = [];
33 33
 
34
-	/**
35
-	 * Schedule a command to be fired
36
-	 *
37
-	 * @param \OCP\Command\ICommand | callable $command
38
-	 */
39
-	public function push($command) {
40
-		$this->queue[] = $command;
41
-	}
34
+    /**
35
+     * Schedule a command to be fired
36
+     *
37
+     * @param \OCP\Command\ICommand | callable $command
38
+     */
39
+    public function push($command) {
40
+        $this->queue[] = $command;
41
+    }
42 42
 
43
-	/**
44
-	 * Require all commands using a trait to be run synchronous
45
-	 *
46
-	 * @param string $trait
47
-	 */
48
-	public function requireSync($trait) {
49
-	}
43
+    /**
44
+     * Require all commands using a trait to be run synchronous
45
+     *
46
+     * @param string $trait
47
+     */
48
+    public function requireSync($trait) {
49
+    }
50 50
 
51
-	/**
52
-	 * @param \OCP\Command\ICommand | callable $command
53
-	 */
54
-	private function runCommand($command) {
55
-		if ($command instanceof ICommand) {
56
-			// ensure the command can be serialized
57
-			$serialized = serialize($command);
58
-			if(strlen($serialized) > 4000) {
59
-				throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)');
60
-			}
61
-			$unserialized = unserialize($serialized);
62
-			$unserialized->handle();
63
-		} else {
64
-			$command();
65
-		}
66
-	}
51
+    /**
52
+     * @param \OCP\Command\ICommand | callable $command
53
+     */
54
+    private function runCommand($command) {
55
+        if ($command instanceof ICommand) {
56
+            // ensure the command can be serialized
57
+            $serialized = serialize($command);
58
+            if(strlen($serialized) > 4000) {
59
+                throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)');
60
+            }
61
+            $unserialized = unserialize($serialized);
62
+            $unserialized->handle();
63
+        } else {
64
+            $command();
65
+        }
66
+    }
67 67
 
68
-	public function run() {
69
-		while ($command = array_shift($this->queue)) {
70
-			$this->runCommand($command);
71
-		}
72
-	}
68
+    public function run() {
69
+        while ($command = array_shift($this->queue)) {
70
+            $this->runCommand($command);
71
+        }
72
+    }
73 73
 }
Please login to merge, or discard this patch.
lib/private/Command/CallableJob.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,12 +25,12 @@
 block discarded – undo
25 25
 use OC\BackgroundJob\QueuedJob;
26 26
 
27 27
 class CallableJob extends QueuedJob {
28
-	protected function run($serializedCallable) {
29
-		$callable = unserialize($serializedCallable);
30
-		if (is_callable($callable)) {
31
-			$callable();
32
-		} else {
33
-			throw new \InvalidArgumentException('Invalid serialized callable');
34
-		}
35
-	}
28
+    protected function run($serializedCallable) {
29
+        $callable = unserialize($serializedCallable);
30
+        if (is_callable($callable)) {
31
+            $callable();
32
+        } else {
33
+            throw new \InvalidArgumentException('Invalid serialized callable');
34
+        }
35
+    }
36 36
 }
Please login to merge, or discard this patch.
lib/private/Command/ClosureJob.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@
 block discarded – undo
26 26
 use SuperClosure\Serializer;
27 27
 
28 28
 class ClosureJob extends QueuedJob {
29
-	protected function run($serializedCallable) {
30
-		$serializer = new Serializer();
31
-		$callable = $serializer->unserialize($serializedCallable);
32
-		if (is_callable($callable)) {
33
-			$callable();
34
-		} else {
35
-			throw new \InvalidArgumentException('Invalid serialized callable');
36
-		}
37
-	}
29
+    protected function run($serializedCallable) {
30
+        $serializer = new Serializer();
31
+        $callable = $serializer->unserialize($serializedCallable);
32
+        if (is_callable($callable)) {
33
+            $callable();
34
+        } else {
35
+            throw new \InvalidArgumentException('Invalid serialized callable');
36
+        }
37
+    }
38 38
 }
Please login to merge, or discard this patch.