Skip to content

Handle BSD case for 32 bit filemtime and install warning#28759

Merged
PVince81 merged 2 commits into
masterfrom
stat-c-os-dependent
Aug 24, 2017
Merged

Handle BSD case for 32 bit filemtime and install warning#28759
PVince81 merged 2 commits into
masterfrom
stat-c-os-dependent

Conversation

@phil-davis

@phil-davis phil-davis commented Aug 22, 2017

Copy link
Copy Markdown
Contributor

Description

Handle the BSD (and Mac) case in lib/private/Files/Storage/Local.php filemtime
That was performing a Linux-style stat command only.

Make a generic runningOn convenience function and refactor existing code that did special strpos() stuff to detect the OS.

Remove some legacy tests for "win" that were still in getFileSizeViaExec

Rearrange install OS error checks in Setup.php so that the error (really a warning) will be displayed for any OS that is not linux-type.

Related Issue

#28758
#28760

Motivation and Context

BSD stat command has different options to Linux

How Has This Been Tested?

Copied function runningOnBSD() onto my pfSense FreeBSD system and tried calling it manually.
It returns true for that, should also work for "OpenBSD" or other variants.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@phil-davis

Copy link
Copy Markdown
Contributor Author

Note: The filemtime() 32-bit check was introduced by PR #25428 for issue #18971 but that code only had a stat command for Linux.

@DeepDiver1975

Copy link
Copy Markdown
Member

Nice:+1:

@phil-davis phil-davis self-assigned this Aug 22, 2017
@phil-davis phil-davis added this to the development milestone Aug 22, 2017
if (PHP_INT_SIZE === 4) {
return (int) exec ('stat -c %Y '. escapeshellarg ($fullPath));
if (\OC_Util::runningOnLinux()) {
return (int) exec ('stat -c %Y '. escapeshellarg ($fullPath));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this change ...

Isn't it stupid to call stat to get values higher then 32 bit int and then case that to a 32bit int?

@phil-davis phil-davis Aug 22, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good question! That "rounds" off the answer at max int.

@phil-davis phil-davis Aug 22, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite as stupid as it looks. The problem is that for files of SIZE > 2GB on 32-bit systems, even filemtime() fails:
http://php.net/manual/en/function.filemtime.php#68814

The file SIZE might be too big for a 32-bit signed int, but mtime will fit OK until 2038.

Since filemtime() returns an int, I guess whoever wrote this also returned an int. But it would not matter to just remove the (int) cast.

@phil-davis phil-davis force-pushed the stat-c-os-dependent branch from 725e114 to f7fc09c Compare August 22, 2017 13:33
@phil-davis

Copy link
Copy Markdown
Contributor Author

Rebased - CI should be passing on latest master.

@phil-davis phil-davis force-pushed the stat-c-os-dependent branch from f7fc09c to e6aaf3c Compare August 22, 2017 14:53
@phil-davis phil-davis changed the title Handle BSD case for 32 bit filemtime Handle BSD case for 32 bit filemtime and install warning Aug 22, 2017
@phil-davis phil-davis force-pushed the stat-c-os-dependent branch from e6aaf3c to e0d6c0f Compare August 22, 2017 14:59
@phil-davis

phil-davis commented Aug 22, 2017

Copy link
Copy Markdown
Contributor Author

@DeepDiver1975 @mmattel I refactored this based on comments in the other related PR #28761 and included the little bit of Setup.php code from there. The refactoring meant that I had to touch Setup.php anyway.
Please re-review.

@mmattel

mmattel commented Aug 22, 2017

Copy link
Copy Markdown
Contributor

Code looks good, not tested 👍
Jenkins: docker: Error response from daemon: grpc: the connection is unavailable...

@phil-davis phil-davis force-pushed the stat-c-os-dependent branch from e0d6c0f to ab0ec67 Compare August 23, 2017 01:12
@phil-davis

Copy link
Copy Markdown
Contributor Author

Rebased again and Jenkins still dies early. I guess there will be no CI until someone is available to look at it.

*/
public static function runningOnMac() {
return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN');
public static function runningOn($osType) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a little bit less code ;-)

$osType = strtolower($osType) == 'mac' ? 'darwin' : strtolower($osType);
return (strtolower(substr(PHP_OS, 0, strlen($osType))) === $osType);

@phil-davis phil-davis Aug 23, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bsd case is different, because for that it is not necessarily at the start of the string. On my pfSense:

$x = PHP_OS;
var_dump($x);
string(7) "FreeBSD"

so it does not all fit nicely into a single check (although they could all do strpos() to just check if PHP_OS contains 'linux', 'darwin' or 'bsd' somewhere)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point - didnt look that close - sorry

Comment thread lib/private/legacy/util.php Outdated
switch($osType) {
case 'linux':
return (strtolower(substr(PHP_OS, 0, 5)) === 'linux');
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to break if you return directly

@phil-davis

Copy link
Copy Markdown
Contributor Author

I refactored it - maybe it is more obscure now?

But it is "flexible" - by default it checks for the parameter matching the start of PHP_OS. It can be passed 'lin' (matching a Linux...) or 'darw' (matching a 'darwin...') or 'free' (matching 'FreeBSD').
And it knows about the special cases of 'mac' => 'darwin' and 'bsd' can come anywhere in PHP_OS.

But also, I can't imagine using the "flexibility" any time soon.

@mmattel

mmattel commented Aug 24, 2017

Copy link
Copy Markdown
Contributor

👍

@phil-davis

Copy link
Copy Markdown
Contributor Author

@PVince81 or @DeepDiver1975 do either of you want to give this a final approval and press merge?
Or change or revert back something here?

@PVince81 PVince81 merged commit df60e3a into master Aug 24, 2017
@PVince81 PVince81 deleted the stat-c-os-dependent branch August 24, 2017 11:37
@phil-davis

Copy link
Copy Markdown
Contributor Author

Backport stable10 #28790
since this makes the setup warning more generic, applying to all attempts at installing on a non-linux-style platform.

@lock

lock Bot commented Aug 2, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants