-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
Nice:+1: |
lib/private/Files/Storage/Local.php
Outdated
@@ -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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
725e114
to
f7fc09c
Compare
Rebased - CI should be passing on latest master. |
f7fc09c
to
e6aaf3c
Compare
e6aaf3c
to
e0d6c0f
Compare
@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. |
Code looks good, not tested 👍 |
e0d6c0f
to
ab0ec67
Compare
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) { |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
lib/private/legacy/util.php
Outdated
switch($osType) { | ||
case 'linux': | ||
return (strtolower(substr(PHP_OS, 0, 5)) === 'linux'); | ||
break; |
There was a problem hiding this comment.
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
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'). But also, I can't imagine using the "flexibility" any time soon. |
👍 |
@PVince81 or @DeepDiver1975 do either of you want to give this a final approval and press merge? |
Backport stable10 #28790 |
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. |
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
Checklist: