Skip to content

Commit 1ef465f

Browse files
Merge pull request #56251 from nextcloud/carl/template-manager-cleanup
refactor(template-manager): Modernize template manager API
2 parents aeed32c + 9522dde commit 1ef465f

File tree

15 files changed

+268
-120
lines changed

15 files changed

+268
-120
lines changed

apps/files/lib/ResponseDefinitions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
* filename: ?string,
1818
* lastmod: int,
1919
* mime: string,
20-
* size: int,
20+
* size: int|float,
2121
* type: string,
2222
* hasPreview: bool,
23+
* permissions: int,
2324
* }
2425
*
2526
* @psalm-type FilesTemplateField = array{

apps/files/openapi.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@
323323
"mime",
324324
"size",
325325
"type",
326-
"hasPreview"
326+
"hasPreview",
327+
"permissions"
327328
],
328329
"properties": {
329330
"basename": {
@@ -348,14 +349,26 @@
348349
"type": "string"
349350
},
350351
"size": {
351-
"type": "integer",
352-
"format": "int64"
352+
"anyOf": [
353+
{
354+
"type": "integer",
355+
"format": "int64"
356+
},
357+
{
358+
"type": "number",
359+
"format": "double"
360+
}
361+
]
353362
},
354363
"type": {
355364
"type": "string"
356365
},
357366
"hasPreview": {
358367
"type": "boolean"
368+
},
369+
"permissions": {
370+
"type": "integer",
371+
"format": "int64"
359372
}
360373
}
361374
},

lib/composer/composer/InstalledVersions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public static function getRawData()
277277
if (null === self::$installed) {
278278
// only require the installed.php file if this file is loaded from its dumped location,
279279
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
280-
if (substr(__DIR__, -8, 1) !== 'C') {
280+
if (substr(__DIR__, -8, 1) !== 'C' && is_file(__DIR__ . '/installed.php')) {
281281
self::$installed = include __DIR__ . '/installed.php';
282282
} else {
283283
self::$installed = array();
@@ -378,7 +378,7 @@ private static function getInstalled()
378378
if (null === self::$installed) {
379379
// only require the installed.php file if this file is loaded from its dumped location,
380380
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
381-
if (substr(__DIR__, -8, 1) !== 'C') {
381+
if (substr(__DIR__, -8, 1) !== 'C' && is_file(__DIR__ . '/installed.php')) {
382382
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
383383
$required = require __DIR__ . '/installed.php';
384384
self::$installed = $required;

lib/composer/composer/LICENSE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Copyright (c) Nils Adermann, Jordi Boggiano
32

43
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -18,4 +17,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1817
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1918
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2019
THE SOFTWARE.
21-

lib/composer/composer/installed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => '__root__',
44
'pretty_version' => 'dev-master',
55
'version' => 'dev-master',
6-
'reference' => '3fce359f4c606737b21b1b4213efd5bc5536e867',
6+
'reference' => '8c12590cf6f93ce7aa41f17817b3791e524da39e',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../../../',
99
'aliases' => array(),
@@ -13,7 +13,7 @@
1313
'__root__' => array(
1414
'pretty_version' => 'dev-master',
1515
'version' => 'dev-master',
16-
'reference' => '3fce359f4c606737b21b1b4213efd5bc5536e867',
16+
'reference' => '8c12590cf6f93ce7aa41f17817b3791e524da39e',
1717
'type' => 'library',
1818
'install_path' => __DIR__ . '/../../../',
1919
'aliases' => array(),

lib/private/Files/Node/Folder.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OC\User\LazyUser;
1717
use OCP\Files\Cache\ICacheEntry;
1818
use OCP\Files\FileInfo;
19+
use OCP\Files\Folder as IFolder;
1920
use OCP\Files\Mount\IMountPoint;
2021
use OCP\Files\Node as INode;
2122
use OCP\Files\NotFoundException;
@@ -26,8 +27,9 @@
2627
use OCP\Files\Search\ISearchOrder;
2728
use OCP\Files\Search\ISearchQuery;
2829
use OCP\IUserManager;
30+
use Override;
2931

30-
class Folder extends Node implements \OCP\Files\Folder {
32+
class Folder extends Node implements IFolder {
3133

3234
private ?IUserManager $userManager = null;
3335

@@ -480,4 +482,28 @@ private function recreateIfNeeded(): void {
480482
$this->wasDeleted = false;
481483
}
482484
}
485+
486+
#[Override]
487+
public function getOrCreateFolder(string $path, int $maxRetries = 5): IFolder {
488+
$i = 0;
489+
while (true) {
490+
$path = $i === 0 ? $path : $path . ' (' . $i . ')';
491+
try {
492+
$folder = $this->get($path);
493+
if ($folder instanceof IFolder) {
494+
return $folder;
495+
}
496+
} catch (NotFoundException) {
497+
$folder = dirname($path) === '.' ? $this : $this->get(dirname($path));
498+
if (!($folder instanceof Folder)) {
499+
throw new NotPermittedException("Unable to create folder $path. Parent is not a directory.");
500+
}
501+
return $folder->newFolder(basename($path));
502+
}
503+
$i++;
504+
if ($i === $maxRetries) {
505+
throw new NotPermittedException('Unable to load or create folder.');
506+
}
507+
}
508+
}
483509
}

lib/private/Files/Node/LazyFolder.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\Files\IRootFolder;
1515
use OCP\Files\Mount\IMountPoint;
1616
use OCP\Files\NotPermittedException;
17+
use Override;
1718

1819
/**
1920
* Class LazyFolder
@@ -138,6 +139,11 @@ public function get($path) {
138139
return $this->getRootFolder()->get($this->getFullPath($path));
139140
}
140141

142+
#[Override]
143+
public function getOrCreateFolder(string $path, int $maxRetries = 5): Folder {
144+
return $this->getRootFolder()->getOrCreateFolder($this->getFullPath($path), $maxRetries);
145+
}
146+
141147
/**
142148
* @inheritDoc
143149
*/

0 commit comments

Comments
 (0)