Skip to content

Commit

Permalink
Handle BSD case for 32 bit filemtime
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Aug 22, 2017
1 parent 68772d6 commit f7fc09c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
7 changes: 6 additions & 1 deletion lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
} else if (\OC_Util::runningOnBSD() || \OC_Util::runningOnMac()) {
return (int) exec ('stat -f %m '. escapeshellarg ($fullPath));
}
return false;
}
return filemtime($fullPath);
}
Expand Down
11 changes: 2 additions & 9 deletions lib/private/LargeFileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,12 @@ public function getFileSizeViaCurl($fileName) {
*/
public function getFileSizeViaExec($filename) {
if (\OC_Helper::is_function_enabled('exec')) {
$os = strtolower(php_uname('s'));
$arg = escapeshellarg($filename);
$result = null;
if (strpos($os, 'linux') !== false) {
if (\OC_Util::runningOnLinux()) {
$result = $this->exec("stat -c %s $arg");
} else if (strpos($os, 'bsd') !== false || strpos($os, 'darwin') !== false) {
} else if (\OC_Util::runningOnBSD() || \OC_Util::runningOnMac()) {
$result = $this->exec("stat -f %z $arg");
} else if (strpos($os, 'win') !== false) {
$result = $this->exec("for %F in ($arg) do @echo %~zF");
if (is_null($result)) {
// PowerShell
$result = $this->exec("(Get-Item $arg).length");
}
}
return $result;
}
Expand Down
20 changes: 19 additions & 1 deletion lib/private/legacy/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -1252,13 +1252,31 @@ public static function obEnd() {
}
}

/**
* Checks whether the server is running on Linux
*
* @return bool true if running on Linux, false otherwise
*/
public static function runningOnLinux() {
return (strtolower(substr(PHP_OS, 0, 5)) === 'linux');
}

/**
* Checks whether the server is running on Mac OS X
*
* @return bool true if running on Mac OS X, false otherwise
*/
public static function runningOnMac() {
return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN');
return (strtolower(substr(PHP_OS, 0, 6)) === 'darwin');
}

/**
* Checks whether the server is running on BSD
*
* @return bool true if running on BSD, false otherwise
*/
public static function runningOnBSD() {
return (strpos(strtolower(PHP_OS), 'bsd') !== false);
}

/**
Expand Down

0 comments on commit f7fc09c

Please sign in to comment.