Completed
Push — master ( cc6284...4d23a9 )
by Daniel
33:37
created
core/Command/Info/File.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -30,182 +30,182 @@
 block discarded – undo
30 30
 use Symfony\Component\Console\Output\OutputInterface;
31 31
 
32 32
 class File extends Command {
33
-	private IL10N $l10n;
33
+    private IL10N $l10n;
34 34
 
35
-	public function __construct(
36
-		IFactory $l10nFactory,
37
-		private FileUtils $fileUtils,
38
-		private \OC\Encryption\Util $encryptionUtil,
39
-		private PrimaryObjectStoreConfig $objectStoreConfig,
40
-		private IRootFolder $rootFolder,
41
-	) {
42
-		$this->l10n = $l10nFactory->get('core');
43
-		parent::__construct();
44
-	}
35
+    public function __construct(
36
+        IFactory $l10nFactory,
37
+        private FileUtils $fileUtils,
38
+        private \OC\Encryption\Util $encryptionUtil,
39
+        private PrimaryObjectStoreConfig $objectStoreConfig,
40
+        private IRootFolder $rootFolder,
41
+    ) {
42
+        $this->l10n = $l10nFactory->get('core');
43
+        parent::__construct();
44
+    }
45 45
 
46
-	protected function configure(): void {
47
-		$this
48
-			->setName('info:file')
49
-			->setDescription('get information for a file')
50
-			->addArgument('file', InputArgument::REQUIRED, 'File id or path')
51
-			->addOption('children', 'c', InputOption::VALUE_NONE, 'List children of folders')
52
-			->addOption('storage-tree', null, InputOption::VALUE_NONE, 'Show storage and cache wrapping tree');
53
-	}
46
+    protected function configure(): void {
47
+        $this
48
+            ->setName('info:file')
49
+            ->setDescription('get information for a file')
50
+            ->addArgument('file', InputArgument::REQUIRED, 'File id or path')
51
+            ->addOption('children', 'c', InputOption::VALUE_NONE, 'List children of folders')
52
+            ->addOption('storage-tree', null, InputOption::VALUE_NONE, 'Show storage and cache wrapping tree');
53
+    }
54 54
 
55
-	public function execute(InputInterface $input, OutputInterface $output): int {
56
-		$fileInput = $input->getArgument('file');
57
-		$showChildren = $input->getOption('children');
58
-		$node = $this->fileUtils->getNode($fileInput);
59
-		if (!$node) {
60
-			$output->writeln("<error>file $fileInput not found</error>");
61
-			return 1;
62
-		}
55
+    public function execute(InputInterface $input, OutputInterface $output): int {
56
+        $fileInput = $input->getArgument('file');
57
+        $showChildren = $input->getOption('children');
58
+        $node = $this->fileUtils->getNode($fileInput);
59
+        if (!$node) {
60
+            $output->writeln("<error>file $fileInput not found</error>");
61
+            return 1;
62
+        }
63 63
 
64
-		$output->writeln($node->getName());
65
-		$output->writeln('  fileid: ' . $node->getId());
66
-		$output->writeln('  mimetype: ' . $node->getMimetype());
67
-		$output->writeln('  modified: ' . (string)$this->l10n->l('datetime', $node->getMTime()));
64
+        $output->writeln($node->getName());
65
+        $output->writeln('  fileid: ' . $node->getId());
66
+        $output->writeln('  mimetype: ' . $node->getMimetype());
67
+        $output->writeln('  modified: ' . (string)$this->l10n->l('datetime', $node->getMTime()));
68 68
 
69
-		if ($node instanceof OCPFile && $node->isEncrypted()) {
70
-			$output->writeln('  ' . 'server-side encrypted: yes');
71
-			$keyPath = $this->encryptionUtil->getFileKeyDir('', $node->getPath());
72
-			try {
73
-				$this->rootFolder->get($keyPath);
74
-				$output->writeln('    encryption key at: ' . $keyPath);
75
-			} catch (NotFoundException $e) {
76
-				$output->writeln('    <error>encryption key not found</error> should be located at: ' . $keyPath);
77
-			}
78
-			$storage = $node->getStorage();
79
-			if ($storage->instanceOfStorage(Encryption::class)) {
80
-				/** @var Encryption $storage */
81
-				if (!$storage->hasValidHeader($node->getInternalPath())) {
82
-					$output->writeln('    <error>file doesn\'t have a valid encryption header</error>');
83
-				}
84
-			} else {
85
-				$output->writeln('    <error>file is marked as encrypted, but encryption doesn\'t seem to be setup</error>');
86
-			}
87
-		}
69
+        if ($node instanceof OCPFile && $node->isEncrypted()) {
70
+            $output->writeln('  ' . 'server-side encrypted: yes');
71
+            $keyPath = $this->encryptionUtil->getFileKeyDir('', $node->getPath());
72
+            try {
73
+                $this->rootFolder->get($keyPath);
74
+                $output->writeln('    encryption key at: ' . $keyPath);
75
+            } catch (NotFoundException $e) {
76
+                $output->writeln('    <error>encryption key not found</error> should be located at: ' . $keyPath);
77
+            }
78
+            $storage = $node->getStorage();
79
+            if ($storage->instanceOfStorage(Encryption::class)) {
80
+                /** @var Encryption $storage */
81
+                if (!$storage->hasValidHeader($node->getInternalPath())) {
82
+                    $output->writeln('    <error>file doesn\'t have a valid encryption header</error>');
83
+                }
84
+            } else {
85
+                $output->writeln('    <error>file is marked as encrypted, but encryption doesn\'t seem to be setup</error>');
86
+            }
87
+        }
88 88
 
89
-		if ($node instanceof Folder && $node->isEncrypted() || $node instanceof OCPFile && $node->getParent()->isEncrypted()) {
90
-			$output->writeln('  ' . 'end-to-end encrypted: yes');
91
-		}
89
+        if ($node instanceof Folder && $node->isEncrypted() || $node instanceof OCPFile && $node->getParent()->isEncrypted()) {
90
+            $output->writeln('  ' . 'end-to-end encrypted: yes');
91
+        }
92 92
 
93
-		$output->writeln('  size: ' . Util::humanFileSize($node->getSize()));
94
-		$output->writeln('  etag: ' . $node->getEtag());
95
-		$output->writeln('  permissions: ' . $this->fileUtils->formatPermissions($node->getType(), $node->getPermissions()));
96
-		if ($node instanceof Folder) {
97
-			$children = $node->getDirectoryListing();
98
-			$childSize = array_sum(array_map(function (Node $node) {
99
-				return $node->getSize();
100
-			}, $children));
101
-			if ($childSize != $node->getSize()) {
102
-				$output->writeln('    <error>warning: folder has a size of ' . Util::humanFileSize($node->getSize()) . " but it's children sum up to " . Util::humanFileSize($childSize) . '</error>.');
103
-				if (!$node->getStorage()->instanceOfStorage(ObjectStoreStorage::class)) {
104
-					$output->writeln('    Run <info>occ files:scan --path ' . $node->getPath() . '</info> to attempt to resolve this.');
105
-				}
106
-			}
107
-			if ($showChildren) {
108
-				$output->writeln('  children: ' . count($children) . ':');
109
-				foreach ($children as $child) {
110
-					$output->writeln('  - ' . $child->getName());
111
-				}
112
-			} else {
113
-				$output->writeln('  children: ' . count($children) . ' (use <info>--children</info> option to list)');
114
-			}
115
-		}
116
-		$this->outputStorageDetails($node->getMountPoint(), $node, $input, $output);
93
+        $output->writeln('  size: ' . Util::humanFileSize($node->getSize()));
94
+        $output->writeln('  etag: ' . $node->getEtag());
95
+        $output->writeln('  permissions: ' . $this->fileUtils->formatPermissions($node->getType(), $node->getPermissions()));
96
+        if ($node instanceof Folder) {
97
+            $children = $node->getDirectoryListing();
98
+            $childSize = array_sum(array_map(function (Node $node) {
99
+                return $node->getSize();
100
+            }, $children));
101
+            if ($childSize != $node->getSize()) {
102
+                $output->writeln('    <error>warning: folder has a size of ' . Util::humanFileSize($node->getSize()) . " but it's children sum up to " . Util::humanFileSize($childSize) . '</error>.');
103
+                if (!$node->getStorage()->instanceOfStorage(ObjectStoreStorage::class)) {
104
+                    $output->writeln('    Run <info>occ files:scan --path ' . $node->getPath() . '</info> to attempt to resolve this.');
105
+                }
106
+            }
107
+            if ($showChildren) {
108
+                $output->writeln('  children: ' . count($children) . ':');
109
+                foreach ($children as $child) {
110
+                    $output->writeln('  - ' . $child->getName());
111
+                }
112
+            } else {
113
+                $output->writeln('  children: ' . count($children) . ' (use <info>--children</info> option to list)');
114
+            }
115
+        }
116
+        $this->outputStorageDetails($node->getMountPoint(), $node, $input, $output);
117 117
 
118
-		$filesPerUser = $this->fileUtils->getFilesByUser($node);
119
-		$output->writeln('');
120
-		$output->writeln('The following users have access to the file');
121
-		$output->writeln('');
122
-		foreach ($filesPerUser as $user => $files) {
123
-			$output->writeln("$user:");
124
-			foreach ($files as $userFile) {
125
-				$output->writeln('  ' . $userFile->getPath() . ': ' . $this->fileUtils->formatPermissions($userFile->getType(), $userFile->getPermissions()));
126
-				$mount = $userFile->getMountPoint();
127
-				$output->writeln('    ' . $this->fileUtils->formatMountType($mount));
128
-			}
129
-		}
118
+        $filesPerUser = $this->fileUtils->getFilesByUser($node);
119
+        $output->writeln('');
120
+        $output->writeln('The following users have access to the file');
121
+        $output->writeln('');
122
+        foreach ($filesPerUser as $user => $files) {
123
+            $output->writeln("$user:");
124
+            foreach ($files as $userFile) {
125
+                $output->writeln('  ' . $userFile->getPath() . ': ' . $this->fileUtils->formatPermissions($userFile->getType(), $userFile->getPermissions()));
126
+                $mount = $userFile->getMountPoint();
127
+                $output->writeln('    ' . $this->fileUtils->formatMountType($mount));
128
+            }
129
+        }
130 130
 
131
-		return 0;
132
-	}
131
+        return 0;
132
+    }
133 133
 
134
-	/**
135
-	 * @psalm-suppress UndefinedClass
136
-	 * @psalm-suppress UndefinedInterfaceMethod
137
-	 */
138
-	private function outputStorageDetails(IMountPoint $mountPoint, Node $node, InputInterface $input, OutputInterface $output): void {
139
-		$storage = $mountPoint->getStorage();
140
-		if (!$storage) {
141
-			return;
142
-		}
143
-		if (!$storage->instanceOfStorage(IHomeStorage::class)) {
144
-			$output->writeln('  mounted at: ' . $mountPoint->getMountPoint());
145
-		}
146
-		if ($storage->instanceOfStorage(ObjectStoreStorage::class)) {
147
-			/** @var ObjectStoreStorage $storage */
148
-			$objectStoreId = $storage->getObjectStore()->getStorageId();
149
-			$parts = explode(':', $objectStoreId);
150
-			/** @var string $bucket */
151
-			$bucket = array_pop($parts);
152
-			if ($this->objectStoreConfig->hasMultipleObjectStorages()) {
153
-				$configs = $this->objectStoreConfig->getObjectStoreConfigs();
154
-				foreach ($configs as $instance => $config) {
155
-					if (is_array($config)) {
156
-						if ($config['arguments']['multibucket']) {
157
-							if (str_starts_with($bucket, $config['arguments']['bucket'])) {
158
-								$postfix = substr($bucket, strlen($config['arguments']['bucket']));
159
-								if (is_numeric($postfix)) {
160
-									$output->writeln('  object store instance: ' . $instance);
161
-								}
162
-							}
163
-						} else {
164
-							if ($config['arguments']['bucket'] === $bucket) {
165
-								$output->writeln('  object store instance: ' . $instance);
166
-							}
167
-						}
168
-					}
169
-				}
170
-			}
171
-			$output->writeln('  bucket: ' . $bucket);
172
-			if ($node instanceof \OC\Files\Node\File) {
173
-				$output->writeln('  object id: ' . $storage->getURN($node->getId()));
174
-				try {
175
-					$fh = $node->fopen('r');
176
-					if (!$fh) {
177
-						throw new NotFoundException();
178
-					}
179
-					$stat = fstat($fh);
180
-					fclose($fh);
181
-					if (isset($stat['size']) && $stat['size'] !== $node->getSize()) {
182
-						$output->writeln('  <error>warning: object had a size of ' . $stat['size'] . ' but cache entry has a size of ' . $node->getSize() . '</error>. This should have been automatically repaired');
183
-					}
184
-				} catch (\Exception $e) {
185
-					$output->writeln('  <error>warning: object not found in bucket</error>');
186
-				}
187
-			}
188
-		} else {
189
-			if (!$storage->file_exists($node->getInternalPath())) {
190
-				$output->writeln('  <error>warning: file not found in storage</error>');
191
-			}
192
-		}
193
-		if ($mountPoint instanceof ExternalMountPoint) {
194
-			$storageConfig = $mountPoint->getStorageConfig();
195
-			$output->writeln('  external storage id: ' . $storageConfig->getId());
196
-			$output->writeln('  external type: ' . $storageConfig->getBackend()->getText());
197
-		} elseif ($mountPoint instanceof GroupMountPoint) {
198
-			$output->writeln('  groupfolder id: ' . $mountPoint->getFolderId());
199
-		}
200
-		if ($input->getOption('storage-tree')) {
201
-			$storageTmp = $storage;
202
-			$storageClass = get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')';
203
-			while ($storageTmp instanceof Wrapper) {
204
-				$storageTmp = $storageTmp->getWrapperStorage();
205
-				$storageClass .= "\n\t" . '> ' . get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')';
206
-			}
207
-			$output->writeln('  storage wrapping: ' . $storageClass);
208
-		}
134
+    /**
135
+     * @psalm-suppress UndefinedClass
136
+     * @psalm-suppress UndefinedInterfaceMethod
137
+     */
138
+    private function outputStorageDetails(IMountPoint $mountPoint, Node $node, InputInterface $input, OutputInterface $output): void {
139
+        $storage = $mountPoint->getStorage();
140
+        if (!$storage) {
141
+            return;
142
+        }
143
+        if (!$storage->instanceOfStorage(IHomeStorage::class)) {
144
+            $output->writeln('  mounted at: ' . $mountPoint->getMountPoint());
145
+        }
146
+        if ($storage->instanceOfStorage(ObjectStoreStorage::class)) {
147
+            /** @var ObjectStoreStorage $storage */
148
+            $objectStoreId = $storage->getObjectStore()->getStorageId();
149
+            $parts = explode(':', $objectStoreId);
150
+            /** @var string $bucket */
151
+            $bucket = array_pop($parts);
152
+            if ($this->objectStoreConfig->hasMultipleObjectStorages()) {
153
+                $configs = $this->objectStoreConfig->getObjectStoreConfigs();
154
+                foreach ($configs as $instance => $config) {
155
+                    if (is_array($config)) {
156
+                        if ($config['arguments']['multibucket']) {
157
+                            if (str_starts_with($bucket, $config['arguments']['bucket'])) {
158
+                                $postfix = substr($bucket, strlen($config['arguments']['bucket']));
159
+                                if (is_numeric($postfix)) {
160
+                                    $output->writeln('  object store instance: ' . $instance);
161
+                                }
162
+                            }
163
+                        } else {
164
+                            if ($config['arguments']['bucket'] === $bucket) {
165
+                                $output->writeln('  object store instance: ' . $instance);
166
+                            }
167
+                        }
168
+                    }
169
+                }
170
+            }
171
+            $output->writeln('  bucket: ' . $bucket);
172
+            if ($node instanceof \OC\Files\Node\File) {
173
+                $output->writeln('  object id: ' . $storage->getURN($node->getId()));
174
+                try {
175
+                    $fh = $node->fopen('r');
176
+                    if (!$fh) {
177
+                        throw new NotFoundException();
178
+                    }
179
+                    $stat = fstat($fh);
180
+                    fclose($fh);
181
+                    if (isset($stat['size']) && $stat['size'] !== $node->getSize()) {
182
+                        $output->writeln('  <error>warning: object had a size of ' . $stat['size'] . ' but cache entry has a size of ' . $node->getSize() . '</error>. This should have been automatically repaired');
183
+                    }
184
+                } catch (\Exception $e) {
185
+                    $output->writeln('  <error>warning: object not found in bucket</error>');
186
+                }
187
+            }
188
+        } else {
189
+            if (!$storage->file_exists($node->getInternalPath())) {
190
+                $output->writeln('  <error>warning: file not found in storage</error>');
191
+            }
192
+        }
193
+        if ($mountPoint instanceof ExternalMountPoint) {
194
+            $storageConfig = $mountPoint->getStorageConfig();
195
+            $output->writeln('  external storage id: ' . $storageConfig->getId());
196
+            $output->writeln('  external type: ' . $storageConfig->getBackend()->getText());
197
+        } elseif ($mountPoint instanceof GroupMountPoint) {
198
+            $output->writeln('  groupfolder id: ' . $mountPoint->getFolderId());
199
+        }
200
+        if ($input->getOption('storage-tree')) {
201
+            $storageTmp = $storage;
202
+            $storageClass = get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')';
203
+            while ($storageTmp instanceof Wrapper) {
204
+                $storageTmp = $storageTmp->getWrapperStorage();
205
+                $storageClass .= "\n\t" . '> ' . get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')';
206
+            }
207
+            $output->writeln('  storage wrapping: ' . $storageClass);
208
+        }
209 209
 
210
-	}
210
+    }
211 211
 }
Please login to merge, or discard this patch.