Skip to content

Commit aba79a2

Browse files
committed
[stable25] Fix 32bit support and add workflow for 32bits testing
This backports most changes from: #36120 Excludes union type, supported by PHP 8.x only replaced with phpdoc in case. Signed-off-by: MichaIng <[email protected]>
1 parent f5a8b31 commit aba79a2

57 files changed

Lines changed: 224 additions & 95 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function __construct(View $view, FileInfo $info, IManager $shareManager =
138138
public function put($data) {
139139
try {
140140
$exists = $this->fileView->file_exists($this->path);
141-
if ($this->info && $exists && !$this->info->isUpdateable()) {
141+
if ($exists && !$this->info->isUpdateable()) {
142142
throw new Forbidden();
143143
}
144144
} catch (StorageNotAvailableException $e) {
@@ -747,9 +747,6 @@ private function convertToSabreException(\Exception $e) {
747747
* @return string|null
748748
*/
749749
public function getChecksum() {
750-
if (!$this->info) {
751-
return null;
752-
}
753750
return $this->info->getChecksum();
754751
}
755752

apps/dav/lib/Connector/Sabre/Node.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@
4444
use OCP\Files\FileInfo;
4545
use OCP\Files\IRootFolder;
4646
use OCP\Files\StorageNotAvailableException;
47-
use OCP\Share\IShare;
4847
use OCP\Share\Exceptions\ShareNotFound;
4948
use OCP\Share\IManager;
5049

5150
abstract class Node implements \Sabre\DAV\INode {
5251

5352
/**
54-
* @var \OC\Files\View
53+
* @var View
5554
*/
5655
protected $fileView;
5756

@@ -70,7 +69,7 @@ abstract class Node implements \Sabre\DAV\INode {
7069
protected $property_cache = null;
7170

7271
/**
73-
* @var \OCP\Files\FileInfo
72+
* @var FileInfo
7473
*/
7574
protected $info;
7675

@@ -84,8 +83,8 @@ abstract class Node implements \Sabre\DAV\INode {
8483
/**
8584
* Sets up the node, expects a full path name
8685
*
87-
* @param \OC\Files\View $view
88-
* @param \OCP\Files\FileInfo $info
86+
* @param View $view
87+
* @param FileInfo $info
8988
* @param IManager $shareManager
9089
*/
9190
public function __construct(View $view, FileInfo $info, IManager $shareManager = null) {
@@ -109,8 +108,12 @@ public function __construct(View $view, FileInfo $info, IManager $shareManager =
109108
}
110109
}
111110

112-
protected function refreshInfo() {
113-
$this->info = $this->fileView->getFileInfo($this->path);
111+
protected function refreshInfo(): void {
112+
$info = $this->fileView->getFileInfo($this->path);
113+
if ($info === false) {
114+
throw new \Sabre\DAV\Exception('Failed to get fileinfo for '. $this->path);
115+
}
116+
$this->info = $info;
114117
$root = \OC::$server->get(IRootFolder::class);
115118
if ($this->info->getType() === FileInfo::TYPE_FOLDER) {
116119
$this->node = new Folder($root, $this->fileView, $this->path, $this->info);
@@ -233,7 +236,8 @@ public function setUploadTime(int $time) {
233236
/**
234237
* Returns the size of the node, in bytes
235238
*
236-
* @return integer
239+
* @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
240+
* @return int|float
237241
*/
238242
public function getSize() {
239243
return $this->info->getSize();

apps/dav/lib/Connector/Sabre/QuotaPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function beforeCopy(string $sourcePath, string $destinationPath): bool {
178178
* This method is called before any HTTP method and validates there is enough free space to store the file
179179
*
180180
* @param string $path relative to the users home
181-
* @param int $length
181+
* @param int|float|null $length
182182
* @throws InsufficientStorage
183183
* @return bool
184184
*/

apps/dav/lib/Direct/DirectFile.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public function getETag() {
7777
return $this->file->getEtag();
7878
}
7979

80+
/**
81+
* @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
82+
* @return int|float
83+
*/
8084
public function getSize() {
8185
$this->getFile();
8286

apps/dav/lib/Upload/UploadFile.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Sabre\DAV\IFile;
3030

3131
class UploadFile implements IFile {
32-
3332
/** @var File */
3433
private $file;
3534

@@ -53,6 +52,10 @@ public function getETag() {
5352
return $this->file->getETag();
5453
}
5554

55+
/**
56+
* @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
57+
* @return int|float
58+
*/
5659
public function getSize() {
5760
return $this->file->getSize();
5861
}

apps/dav/tests/unit/CalDAV/CalDavBackendTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,12 @@ public function testCalendarQuery($expectedEventsInResult, $propFilters, $compFi
423423
$events[0] = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
424424
$events[1] = $this->createEvent($calendarId, '20130912T150000Z', '20130912T170000Z');
425425
$events[2] = $this->createEvent($calendarId, '20130912T173000Z', '20130912T220000Z');
426-
$events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z');
426+
if (PHP_INT_SIZE > 8) {
427+
$events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z');
428+
} else {
429+
/* On 32bit we do not support events after 2038 */
430+
$events[3] = $this->createEvent($calendarId, '20370912T130000Z', '20370912T130000Z');
431+
}
427432

428433
$result = $this->backend->calendarQuery($calendarId, [
429434
'name' => '',
@@ -471,7 +476,7 @@ public function providesCalendarQueryParameters() {
471476
'only-events' => [[0, 1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => null], 'prop-filters' => []]],],
472477
'start' => [[1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],],
473478
'end' => [[0], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC'))], 'prop-filters' => []]],],
474-
'future' => [[3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2099-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],],
479+
'future' => [[3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2036-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],],
475480
];
476481
}
477482

@@ -648,8 +653,15 @@ public function testScheduling($objectData) {
648653
* @dataProvider providesCalDataForGetDenormalizedData
649654
*/
650655
public function testGetDenormalizedData($expected, $key, $calData) {
651-
$actual = $this->backend->getDenormalizedData($calData);
652-
$this->assertEquals($expected, $actual[$key]);
656+
try {
657+
$actual = $this->backend->getDenormalizedData($calData);
658+
$this->assertEquals($expected, $actual[$key]);
659+
} catch (\ValueError $e) {
660+
if (($e->getMessage() === 'Epoch doesn\'t fit in a PHP integer') && (PHP_INT_SIZE < 8)) {
661+
$this->markTestSkipped('This fail on 32bits because of PHP limitations in DateTime');
662+
}
663+
throw $e;
664+
}
653665
}
654666

655667
public function providesCalDataForGetDenormalizedData() {

apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ public function testGetPropertiesForFile() {
228228
$this->assertEquals('00000123instanceid', $propFind->get(self::FILEID_PROPERTYNAME));
229229
$this->assertEquals('123', $propFind->get(self::INTERNAL_FILEID_PROPERTYNAME));
230230
$this->assertEquals('1973-11-29T21:33:09+00:00', $propFind->get(self::CREATIONDATE_PROPERTYNAME));
231-
$this->assertEquals(null, $propFind->get(self::SIZE_PROPERTYNAME));
231+
$this->assertEquals(0, $propFind->get(self::SIZE_PROPERTYNAME));
232232
$this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
233233
$this->assertEquals('http://example.com/', $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
234234
$this->assertEquals('foo', $propFind->get(self::OWNER_ID_PROPERTYNAME));
235235
$this->assertEquals('M. Foo', $propFind->get(self::OWNER_DISPLAY_NAME_PROPERTYNAME));
236236
$this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
237-
$this->assertEquals([self::SIZE_PROPERTYNAME], $propFind->get404Properties());
237+
$this->assertEquals([], $propFind->get404Properties());
238238
}
239239

240240
public function testGetPropertiesStorageNotAvailable() {

apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ public function testOnReport() {
259259
$filesNode2 = $this->getMockBuilder(File::class)
260260
->disableOriginalConstructor()
261261
->getMock();
262+
$filesNode2->method('getSize')
263+
->willReturn(10);
262264

263265
$this->userFolder->expects($this->at(0))
264266
->method('getById')

apps/files/appinfo/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
use OCA\Files\Controller\OpenLocalEditorController;
4141

4242
/** @var Application $application */
43-
$application = \OC::$server->query(Application::class);
43+
$application = \OC::$server->get(Application::class);
4444
$application->registerRoutes(
4545
$this,
4646
[

apps/files/tests/HelperTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ public function sortDataProvider() {
9393
/**
9494
* @dataProvider sortDataProvider
9595
*/
96-
public function testSortByName($sort, $sortDescending, $expectedOrder) {
96+
public function testSortByName(string $sort, bool $sortDescending, array $expectedOrder) {
97+
if (($sort === 'mtime') && (PHP_INT_SIZE < 8)) {
98+
$this->markTestSkipped('Skip mtime sorting on 32bit');
99+
}
97100
$files = self::getTestFileList();
98101
$files = \OCA\Files\Helper::sortFiles($files, $sort, $sortDescending);
99102
$fileNames = [];

0 commit comments

Comments
 (0)