Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 24, 2017

Conversation

phil-davis
Copy link
Contributor

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

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
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
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
@@ -180,7 +180,12 @@ public function filemtime($path) {
return false;
}
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
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?

Copy link
Contributor Author

@phil-davis phil-davis Aug 22, 2017

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.

Copy link
Contributor Author

@phil-davis phil-davis Aug 22, 2017

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
Copy link
Contributor Author

Rebased - CI should be passing on latest master.

@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
Copy link
Contributor Author

phil-davis commented Aug 22, 2017

@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
Copy link
Contributor

mmattel commented Aug 22, 2017

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

@phil-davis
Copy link
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
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);

Copy link
Contributor Author

@phil-davis phil-davis Aug 23, 2017

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
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

switch($osType) {
case 'linux':
return (strtolower(substr(PHP_OS, 0, 5)) === 'linux');
break;
Copy link
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
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
Copy link
Contributor

mmattel commented Aug 24, 2017

👍

@phil-davis
Copy link
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?

@phil-davis
Copy link
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
Copy link

lock bot commented Aug 2, 2019

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