Skip to content

Commit

Permalink
[stable25] Fix 32bit support and add workflow for 32bits testing
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
MichaIng committed Apr 24, 2023
1 parent 0a1f9bc commit 2a0d48e
Show file tree
Hide file tree
Showing 56 changed files with 223 additions and 91 deletions.
20 changes: 12 additions & 8 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@
use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\Files\StorageNotAvailableException;
use OCP\Share\IShare;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;

abstract class Node implements \Sabre\DAV\INode {

/**
* @var \OC\Files\View
* @var View
*/
protected $fileView;

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

/**
* @var \OCP\Files\FileInfo
* @var FileInfo
*/
protected $info;

Expand All @@ -84,8 +83,8 @@ abstract class Node implements \Sabre\DAV\INode {
/**
* Sets up the node, expects a full path name
*
* @param \OC\Files\View $view
* @param \OCP\Files\FileInfo $info
* @param View $view
* @param FileInfo $info
* @param IManager $shareManager
*/
public function __construct(View $view, FileInfo $info, IManager $shareManager = null) {
Expand All @@ -109,8 +108,12 @@ public function __construct(View $view, FileInfo $info, IManager $shareManager =
}
}

protected function refreshInfo() {
$this->info = $this->fileView->getFileInfo($this->path);
protected function refreshInfo(): void {
$info = $this->fileView->getFileInfo($this->path);
if ($info === false) {
throw new \Sabre\DAV\Exception('Failed to get fileinfo for '. $this->path);
}
$this->info = $info;
$root = \OC::$server->get(IRootFolder::class);
if ($this->info->getType() === FileInfo::TYPE_FOLDER) {
$this->node = new Folder($root, $this->fileView, $this->path, $this->info);
Expand Down Expand Up @@ -233,7 +236,8 @@ public function setUploadTime(int $time) {
/**
* Returns the size of the node, in bytes
*
* @return integer
* @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
* @return int|float
*/
public function getSize() {
return $this->info->getSize();
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/QuotaPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function beforeCopy(string $sourcePath, string $destinationPath): bool {
* This method is called before any HTTP method and validates there is enough free space to store the file
*
* @param string $path relative to the users home
* @param int $length
* @param int|float|null $length
* @throws InsufficientStorage
* @return bool
*/
Expand Down
4 changes: 4 additions & 0 deletions apps/dav/lib/Direct/DirectFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function getETag() {
return $this->file->getEtag();
}

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

Expand Down
5 changes: 4 additions & 1 deletion apps/dav/lib/Upload/UploadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Sabre\DAV\IFile;

class UploadFile implements IFile {

/** @var File */
private $file;

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

/**
* @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
* @return int|float
*/
public function getSize() {
return $this->file->getSize();
}
Expand Down
20 changes: 16 additions & 4 deletions apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,12 @@ public function testCalendarQuery($expectedEventsInResult, $propFilters, $compFi
$events[0] = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
$events[1] = $this->createEvent($calendarId, '20130912T150000Z', '20130912T170000Z');
$events[2] = $this->createEvent($calendarId, '20130912T173000Z', '20130912T220000Z');
$events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z');
if (PHP_INT_SIZE > 8) {
$events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z');
} else {
/* On 32bit we do not support events after 2038 */
$events[3] = $this->createEvent($calendarId, '20370912T130000Z', '20370912T130000Z');
}

$result = $this->backend->calendarQuery($calendarId, [
'name' => '',
Expand Down Expand Up @@ -471,7 +476,7 @@ public function providesCalendarQueryParameters() {
'only-events' => [[0, 1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => null], 'prop-filters' => []]],],
'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' => []]],],
'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' => []]],],
'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' => []]],],
'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' => []]],],
];
}

Expand Down Expand Up @@ -648,8 +653,15 @@ public function testScheduling($objectData) {
* @dataProvider providesCalDataForGetDenormalizedData
*/
public function testGetDenormalizedData($expected, $key, $calData) {
$actual = $this->backend->getDenormalizedData($calData);
$this->assertEquals($expected, $actual[$key]);
try {
$actual = $this->backend->getDenormalizedData($calData);
$this->assertEquals($expected, $actual[$key]);
} catch (\ValueError $e) {
if (($e->getMessage() === 'Epoch doesn\'t fit in a PHP integer') && (PHP_INT_SIZE < 8)) {
$this->markTestSkipped('This fail on 32bits because of PHP limitations in DateTime');
}
throw $e;
}
}

public function providesCalDataForGetDenormalizedData() {
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ public function testGetPropertiesForFile() {
$this->assertEquals('00000123instanceid', $propFind->get(self::FILEID_PROPERTYNAME));
$this->assertEquals('123', $propFind->get(self::INTERNAL_FILEID_PROPERTYNAME));
$this->assertEquals('1973-11-29T21:33:09+00:00', $propFind->get(self::CREATIONDATE_PROPERTYNAME));
$this->assertEquals(null, $propFind->get(self::SIZE_PROPERTYNAME));
$this->assertEquals(0, $propFind->get(self::SIZE_PROPERTYNAME));
$this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
$this->assertEquals('http://example.com/', $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
$this->assertEquals('foo', $propFind->get(self::OWNER_ID_PROPERTYNAME));
$this->assertEquals('M. Foo', $propFind->get(self::OWNER_DISPLAY_NAME_PROPERTYNAME));
$this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
$this->assertEquals([self::SIZE_PROPERTYNAME], $propFind->get404Properties());
$this->assertEquals([], $propFind->get404Properties());
}

public function testGetPropertiesStorageNotAvailable() {
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ public function testOnReport() {
$filesNode2 = $this->getMockBuilder(File::class)
->disableOriginalConstructor()
->getMock();
$filesNode2->method('getSize')
->willReturn(10);

$this->userFolder->expects($this->at(0))
->method('getById')
Expand Down
2 changes: 1 addition & 1 deletion apps/files/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use OCA\Files\Controller\OpenLocalEditorController;

/** @var Application $application */
$application = \OC::$server->query(Application::class);
$application = \OC::$server->get(Application::class);
$application->registerRoutes(
$this,
[
Expand Down
5 changes: 4 additions & 1 deletion apps/files/tests/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ public function sortDataProvider() {
/**
* @dataProvider sortDataProvider
*/
public function testSortByName($sort, $sortDescending, $expectedOrder) {
public function testSortByName(string $sort, bool $sortDescending, array $expectedOrder) {
if (($sort === 'mtime') && (PHP_INT_SIZE < 8)) {
$this->markTestSkipped('Skip mtime sorting on 32bit');
}
$files = self::getTestFileList();
$files = \OCA\Files\Helper::sortFiles($files, $sort, $sortDescending);
$fileNames = [];
Expand Down
3 changes: 3 additions & 0 deletions apps/files_external/lib/Lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public function filemtime($path) {
}
}

/**
* @return false|int|float
*/
public function filesize($path) {
$result = $this->getConnection()->size($this->buildPath($path));
if ($result === -1) {
Expand Down
11 changes: 11 additions & 0 deletions apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ public function testCreateShareGroupFolder() {
$ocs->cleanup();
}

/**
* @group RoutingWeirdness
*/
public function testCreateShareLink() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK);
Expand All @@ -228,6 +231,9 @@ public function testCreateShareLink() {
$ocs->cleanup();
}

/**
* @group RoutingWeirdness
*/
public function testCreateShareLinkPublicUpload() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true');
Expand Down Expand Up @@ -420,6 +426,7 @@ public function testGetAllSharesWithMe() {

/**
* @medium
* @group RoutingWeirdness
*/
public function testPublicLinkUrl() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
Expand Down Expand Up @@ -1291,6 +1298,7 @@ public function datesProvider() {
* Make sure only ISO 8601 dates are accepted
*
* @dataProvider datesProvider
* @group RoutingWeirdness
*/
public function testPublicLinkExpireDate($date, $valid) {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
Expand Down Expand Up @@ -1321,6 +1329,9 @@ public function testPublicLinkExpireDate($date, $valid) {
$this->shareManager->deleteShare($share);
}

/**
* @group RoutingWeirdness
*/
public function testCreatePublicLinkExpireDateValid() {
$config = \OC::$server->getConfig();

Expand Down
6 changes: 5 additions & 1 deletion apps/files_trashbin/lib/Sabre/AbstractTrash.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public function getFileInfo(): FileInfo {
return $this->data;
}

public function getSize(): int {
/**
* @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
* @return int|float
*/
public function getSize() {
return $this->data->getSize();
}

Expand Down
4 changes: 4 additions & 0 deletions apps/files_trashbin/lib/Sabre/ITrash.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function getTitle(): string;

public function getDeletionTime(): int;

/**
* @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
* @return int|float
*/
public function getSize();

public function getFileId(): int;
Expand Down
3 changes: 1 addition & 2 deletions apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
use Psr\Log\LoggerInterface;

class ExpireTrashTest extends TestCase {
/** @var IConfig|MockObject */
Expand Down Expand Up @@ -61,7 +60,7 @@ protected function setUp(): void {

$this->time = $this->createMock(ITimeFactory::class);
$this->time->method('getTime')
->willReturn(99999999999);
->willReturn(999999999);

$this->jobList->expects($this->once())
->method('setLastRun');
Expand Down
6 changes: 5 additions & 1 deletion apps/files_versions/lib/Sabre/VersionFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public function getETag(): string {
return (string)$this->version->getRevisionId();
}

public function getSize(): int {
/**
* @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
* @return int|float
*/
public function getSize() {
return $this->version->getSize();
}

Expand Down
4 changes: 2 additions & 2 deletions apps/files_versions/lib/Versions/IVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function getTimestamp(): int;
/**
* Get the size of this version
*
* @return int
* @return int|float
* @since 15.0.0
*/
public function getSize(): int;
public function getSize();

/**
* Get the name of the source file at the time of making this version
Expand Down
13 changes: 10 additions & 3 deletions apps/files_versions/lib/Versions/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Version implements IVersion {
/** @var string */
private $name;

/** @var int */
/** @var int|float */
private $size;

/** @var string */
Expand All @@ -56,11 +56,14 @@ class Version implements IVersion {
/** @var IUser */
private $user;

/**
* @param int|float $size
*/
public function __construct(
int $timestamp,
$revisionId,
string $name,
int $size,
$size,
string $mimetype,
string $path,
FileInfo $sourceFileInfo,
Expand Down Expand Up @@ -94,7 +97,11 @@ public function getTimestamp(): int {
return $this->timestamp;
}

public function getSize(): int {
/**
* @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
* @return int|float
*/
public function getSize() {
return $this->size;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use Test\TestCase;

class ExpireVersionsTest extends TestCase {

/** @var IConfig|MockObject */
private $config;

Expand Down Expand Up @@ -70,7 +69,7 @@ public function testBackgroundJobDeactivated(): void {
$timeFactory = $this->createMock(ITimeFactory::class);
$timeFactory->method('getTime')
->with()
->willReturn(99999999999);
->willReturn(999999999);

$job = new ExpireVersions($this->config, $this->userManager, $this->expiration, $timeFactory);
$job->start($this->jobList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
use Test\TestCase;

class UsersControllerTest extends TestCase {

/** @var IUserManager|MockObject */
protected $userManager;
/** @var IConfig|MockObject */
Expand Down Expand Up @@ -497,7 +496,7 @@ public function testAddUserSuccessfulGenerateUserID() {
->method('generate')
->with(10)
->willReturnCallback(function () {
return (string)rand(1000000000, 9999999999);
return (string)rand(100000000, 999999999);
});

$this->assertTrue(key_exists(
Expand Down
1 change: 0 additions & 1 deletion core/Command/Log/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ protected function validateRotateSize(&$rotateSize) {
if ($rotateSize === false) {
throw new \InvalidArgumentException('Error parsing log rotation file size');
}
$rotateSize = (int) $rotateSize;
if ($rotateSize < 0) {
throw new \InvalidArgumentException('Log rotation file size must be non-negative');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Archive/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract public function rename(string $source, string $dest): bool;

/**
* get the uncompressed size of a file in the archive
* @return int|false
* @return int|float|false
*/
abstract public function filesize(string $path);

Expand Down
Loading

0 comments on commit 2a0d48e

Please sign in to comment.