summaryrefslogtreecommitdiffstats
path: root/lib/filestorage/local.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/filestorage/local.php')
-rw-r--r--lib/filestorage/local.php45
1 files changed, 42 insertions, 3 deletions
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 6fe45acf8c5..4a4019a3224 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -29,7 +29,15 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
return is_file($this->datadir.$path);
}
public function stat($path) {
- return stat($this->datadir.$path);
+ $fullPath = $this->datadir . $path;
+ $statResult = stat($fullPath);
+
+ if ($statResult['size'] < 0) {
+ $size = self::getFileSizeFromOS($fullPath);
+ $statResult['size'] = $size;
+ $statResult[7] = $size;
+ }
+ return $statResult;
}
public function filetype($path) {
$filetype=filetype($this->datadir.$path);
@@ -42,7 +50,13 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
if($this->is_dir($path)) {
return 0;
}else{
- return filesize($this->datadir.$path);
+ $fullPath = $this->datadir . $path;
+ $fileSize = filesize($fullPath);
+ if ($fileSize < 0) {
+ return self::getFileSizeFromOS($fullPath);
+ }
+
+ return $fileSize;
}
}
public function isReadable($path) {
@@ -78,7 +92,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
public function file_get_contents($path) {
return file_get_contents($this->datadir.$path);
}
- public function file_put_contents($path, $data) {
+ public function file_put_contents($path, $data) {//trigger_error("$path = ".var_export($path, 1));
return file_put_contents($this->datadir.$path, $data);
}
public function unlink($path) {
@@ -156,6 +170,30 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
return $return;
}
+ private static function getFileSizeFromOS($fullPath) {
+ $name = strtolower(php_uname('s'));
+ // Windows OS: we use COM to access the filesystem
+ if (strpos($name, 'win') !== false) {
+ if (class_exists('COM')) {
+ $fsobj = new COM("Scripting.FileSystemObject");
+ $f = $fsobj->GetFile($fullPath);
+ return $f->Size;
+ }
+ } else if (strpos($name, 'bsd') !== false) {
+ if (\OC_Helper::is_function_enabled('exec')) {
+ return (float)exec('stat -f %z ' . escapeshellarg($fullPath));
+ }
+ } else if (strpos($name, 'linux') !== false) {
+ if (\OC_Helper::is_function_enabled('exec')) {
+ return (float)exec('stat -c %s ' . escapeshellarg($fullPath));
+ }
+ } else {
+ OC_Log::write('core', 'Unable to determine file size of "'.$fullPath.'". Unknown OS: '.$name, OC_Log::ERROR);
+ }
+
+ return 0;
+ }
+
public function hash($path, $type, $raw=false) {
return hash_file($type, $this->datadir.$path, $raw);
}
@@ -190,6 +228,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
/**
* check if a file or folder has been updated since $time
+ * @param string $path
* @param int $time
* @return bool
*/