Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fixes stat result handling in case of empty files, according to docs …
Browse files Browse the repository at this point in the history
…stat should return -1 or text error message

small optimizations for handling of alternative stat commands
  • Loading branch information
mwehr committed Feb 24, 2016
1 parent 2dddc17 commit 2b0f678
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions core/src/plugins/access.fs/class.fsAccessWrapper.php
Expand Up @@ -492,21 +492,20 @@ protected function getTrueSizeOnFileSystem($file)
if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')) {
$cmd = "stat -L -c%s ".escapeshellarg($file);
$val = trim(`$cmd`);
if (strlen($val) == 0 || floatval($val) == 0) {
if (!is_numeric($val) || $val == -1) {
// No stat on system
$cmd = "ls -1s --block-size=1 ".escapeshellarg($file);
$val = trim(`$cmd`);
}
if (strlen($val) == 0 || floatval($val) == 0) {
// No block-size on system (probably busybox), try long output
$cmd = "ls -l ".escapeshellarg($file)."";

$arr = explode("/[\s]+/", `$cmd`);
$val = trim($arr[4]);
}
if (strlen($val) == 0 || floatval($val) == 0) {
// Still not working, get a value at least, not 0...
$val = sprintf("%u", filesize($file));
if (strlen($val) == 0 || floatval($val) == 0) {
// No block-size on system (probably busybox), try long output
$cmd = "ls -l ".escapeshellarg($file)."";
$arr = explode("/[\s]+/", `$cmd`);
$val = trim($arr[4]);
if (strlen($val) == 0 || floatval($val) == 0) {
// Still not working, get a value at least, not 0...
$val = sprintf("%u", filesize($file));
}
}
}
return floatval($val);
} else if (class_exists("COM")) {
Expand All @@ -517,5 +516,4 @@ protected function getTrueSizeOnFileSystem($file)
return exec('FOR %A IN ("'.$file.'") DO @ECHO %~zA');
} else return sprintf("%u", filesize($file));
}

}

0 comments on commit 2b0f678

Please sign in to comment.