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