Handle BSD case for 32 bit filemtime and install warning#28759
Conversation
|
Nice:+1: |
| 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.
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.
A good question! That "rounds" off the answer at max int.
There was a problem hiding this comment.
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.
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.
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.
good point - didnt look that close - sorry
| switch($osType) { | ||
| case 'linux': | ||
| return (strtolower(substr(PHP_OS, 0, 5)) === 'linux'); | ||
| break; |
There was a problem hiding this comment.
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
runningOnconvenience 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: