Completed
Pull Request — master (#32337)
by Piotr
09:51
created

NoopScanner::updateChecksums()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 * @author Jörn Friedrich Dreyer <[email protected]>
5
 * @author Morris Jobke <[email protected]>
6
 * @author Robin Appelman <[email protected]>
7
 * @author Thomas Müller <[email protected]>
8
 *
9
 * @copyright Copyright (c) 2018, ownCloud GmbH
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
26
namespace OC\Files\ObjectStore;
27
use \OC\Files\Cache\Scanner;
28
use \OC\Files\Storage\Storage;
29
30
class NoopScanner extends Scanner {
31
	public function __construct(Storage $storage) {
32
		$this->storage = $storage;
33
		//we don't need the storage, so do nothing here
34
	}
35
36
	/**
37
	 * scan a single file and store it in the cache
38
	 *
39
	 * @param string $file
40
	 * @param int $reuseExisting
41
	 * @param int $parentId
42
	 * @param array|null $cacheData existing data in the cache for the file to be scanned
43
	 * @return array an array of metadata of the scanned file
44
	 */
45
	public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) {
46
		$this->updateChecksums($file);
47
		return [];
48
	}
49
50
	/**
51
	 * scan a folder and all it's children
52
	 *
53
	 * @param string $path
54
	 * @param bool $recursive
55
	 * @param int $reuse
56
	 * @return array with the meta data of the scanned file or folder
57
	 */
58
	public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
59
		// we only update the checksums - still returning no data
60
		$this->updateChecksums($path);
61
		return [];
62
	}
63
64
	/**
65
	 * walk over any folders that are not fully scanned yet and scan them
66
	 */
67
	public function backgroundScan() {
68
		//noop
69
	}
70
71
	/**
72
	 * scan all the files and folders in a folder
73
	 *
74
	 * @param string $path
75
	 * @param bool $recursive
76
	 * @param int $reuse
77
	 * @param array $folderData existing cache data for the folder to be scanned
78
	 * @return int the size of the scanned folder or -1 if the size is unknown at this stage
79
	 */
80
	protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderData = null, $lock = true) {
81
		return 0;
82
	}
83
84
	/**
85
	 * Update file checksums
86
	 *
87
	 * @param string $path
88
	 */
89
	private function updateChecksums($path) {
90
		$meta = $this->storage->getMetaData($path);
91
		if (!empty($meta['checksum'])) {
92
			$this->storage->getCache()->put(
93
				$path,
94
				['checksum' => $meta['checksum']]
95
			);
96
		}
97
	}
98
}
99