diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-04-11 15:13:39 +0200 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2022-04-11 17:49:08 +0200 |
commit | f5004e8f0c75b5aa8c8f603f9d62e371f121f1c2 (patch) | |
tree | fa95567d44bc1ce5e90d19531617d890710b3252 /lib/private/Archive | |
parent | 2c0471176c6c562d43b7c871fba466574da3e630 (diff) | |
download | nextcloud-server-f5004e8f0c75b5aa8c8f603f9d62e371f121f1c2.tar.gz nextcloud-server-f5004e8f0c75b5aa8c8f603f9d62e371f121f1c2.zip |
Expose ZIP stat information
Add getStat to OC\Archive\Zip
Required to be able to read the mtime and other metadata.
To give direct access to mtime
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Co-authored-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/Archive')
-rw-r--r-- | lib/private/Archive/ZIP.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/private/Archive/ZIP.php b/lib/private/Archive/ZIP.php index ca9a046ab83..743d313f951 100644 --- a/lib/private/Archive/ZIP.php +++ b/lib/private/Archive/ZIP.php @@ -110,6 +110,9 @@ class ZIP extends Archive { * get the files in a folder */ public function getFolder(string $path): array { + // FIXME: multiple calls on getFolder would traverse + // the whole file list over and over again + // maybe use a Generator or cache the list ? $files = $this->getFiles(); $folderContent = []; $pathLength = strlen($path); @@ -124,6 +127,32 @@ class ZIP extends Archive { } /** + * Generator that returns metadata of all files + * + * @return \Generator<array> + */ + public function getAllFilesStat() { + $fileCount = $this->zip->numFiles; + for ($i = 0;$i < $fileCount;$i++) { + yield $this->zip->statIndex($i); + } + } + + /** + * Return stat information for the given path + * + * @param string path path to get stat information on + * @return ?array stat information or null if not found + */ + public function getStat(string $path): ?array { + $stat = $this->zip->statName($path); + if (!$stat) { + return null; + } + return $stat; + } + + /** * get all files in the archive */ public function getFiles(): array { |