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

Commit

Permalink
Fix 2G limitation on windows in many places ( do not use filesize dir…
Browse files Browse the repository at this point in the history
…ectly )
  • Loading branch information
cdujeu committed Jun 24, 2015
1 parent ed6e001 commit 783e094
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 10 deletions.
16 changes: 12 additions & 4 deletions core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -378,7 +378,7 @@ public function switchAction($action, $httpVars, $fileVars)
$tmpFNAME = $this->urlBase.$dir."/".str_replace(".zip", ".tmp", $localName);
copy($file, $tmpFNAME);
try {
AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($tmpFNAME), filesize($tmpFNAME)));
AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($tmpFNAME), $this->filesystemFileSize($tmpFNAME)));
} catch (Exception $e) {
@unlink($tmpFNAME);
throw $e;
Expand All @@ -397,6 +397,7 @@ public function switchAction($action, $httpVars, $fileVars)
header("Content-type:application/json");
if($selection->isUnique()){
$stat = @stat($this->urlBase.$selection->getUniqueFile());
$this->filesystemFileSize(null, $stat);
if (!$stat) {
print '{}';
} else {
Expand All @@ -407,6 +408,7 @@ public function switchAction($action, $httpVars, $fileVars)
print '{';
foreach($files as $index => $path){
$stat = @stat($this->urlBase.$path);
$this->filesystemFileSize(null, $stat);
if(!$stat) $stat = '{}';
else $stat = json_encode($stat);
print json_encode($path).':'.$stat . (($index < count($files) -1) ? "," : "");
Expand Down Expand Up @@ -1548,10 +1550,14 @@ public function date_modif($file)
return $tmp;// date("d,m L Y H:i:s",$tmp);
}

public function filesystemFileSize($filePath)
public function filesystemFileSize($filePath, &$stat = null)
{
$bytesize = "-";
$bytesize = @filesize($filePath);
if($stat != null && is_array($stat)){
$bytesize = $stat[7];
}else{
$bytesize = @filesize($filePath);
}
if (method_exists($this->wrapperClassName, "getLastRealSize")) {
$last = call_user_func(array($this->wrapperClassName, "getLastRealSize"));
if ($last !== false) {
Expand All @@ -1561,7 +1567,9 @@ public function filesystemFileSize($filePath)
if ($bytesize < 0) {
$bytesize = sprintf("%u", $bytesize);
}

if($stat != null && is_array($stat)){
$stat["size"] = $stat[7] = $bytesize;
}
return $bytesize;
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/plugins/core.access/class.AbstractAccessDriver.php
Expand Up @@ -209,7 +209,9 @@ protected function copyOrMoveFile($destDir, $srcFile, &$error, &$success, $move
return ;
}
if (!$move) {
AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($destFile), filesize($realSrcFile)));
if(method_exists($this, "filesystemFileSize")) $size = $this->filesystemFileSize($realSrcFile);
else $size = filesize($realSrcFile);
AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($destFile), $size));
}
if (dirname($realSrcFile)==dirname($destFile)) {
if ($move) {
Expand Down
9 changes: 7 additions & 2 deletions core/src/plugins/editor.audio/class.AudioPreviewer.php
Expand Up @@ -64,16 +64,21 @@ public function switchAction($action, $httpVars, $postProcessData)
$cType = "audio/".array_pop(explode(".", $file));

$localName = basename($file);
$node = new AJXP_Node($destStreamURL.$file);
if(method_exists($node->getDriver(), "filesystemFileSize")){
$size = $node->getDriver()->filesystemFileSize($node->getUrl());
}else{
$size = filesize($node->getUrl());
}

header("Content-Type: ".$cType."; name=\"".$localName."\"");
header("Content-Length: ".filesize($destStreamURL.$file));
header("Content-Length: ".$size);

$stream = fopen("php://output", "a");
call_user_func(array($streamData["classname"], "copyFileInStream"), $destStreamURL.$file, $stream);
fflush($stream);
fclose($stream);

$node = new AJXP_Node($destStreamURL.$file);
AJXP_Controller::applyHook("node.read", array($node));
$this->logInfo('Preview', 'Read content of '.$node->getUrl());
//exit(1);
Expand Down
7 changes: 6 additions & 1 deletion core/src/plugins/editor.browser/class.FileMimeSender.php
Expand Up @@ -61,7 +61,12 @@ public function switchAction($action, $httpVars, $filesVars)
return false;
}

$filesize = filesize($destStreamURL . $file);
$node = new AJXP_Node($destStreamURL.$file);
if(method_exists($node->getDriver(), "filesystemFileSize")){
$filesize = $node->getDriver()->filesystemFileSize($node->getUrl());
}else{
$filesize = filesize($node->getUrl());
}
$fp = fopen($destStreamURL . $file, "rb");
$fileMime = "application/octet-stream";

Expand Down
6 changes: 5 additions & 1 deletion core/src/plugins/editor.video/class.VideoReader.php
Expand Up @@ -47,7 +47,11 @@ public function switchAction($action, $httpVars, $filesVars)
$file = $selection->getUniqueFile();
$node = new AJXP_Node($destStreamURL.$file);
session_write_close();
$filesize = filesize($destStreamURL.$file);
if(method_exists($node->getDriver(), "filesystemFileSize")){
$filesize = $node->getDriver()->filesystemFileSize($node->getUrl());
}else{
$filesize = filesize($node->getUrl());
}
$filename = $destStreamURL.$file;

//$fp = fopen($destStreamURL.$file, "r");
Expand Down
6 changes: 6 additions & 0 deletions core/src/plugins/meta.filehasher/class.FileHasher.php
Expand Up @@ -194,6 +194,9 @@ public function switchActions($actionName, $httpVars, $fileVars)
if ($selection->isUnique()) {
$node = $selection->getUniqueNode($this->accessDriver);
$stat = @stat($node->getUrl());
if(method_exists($this->accessDriver, "filesystemFileSize")){
$this->accessDriver->filesystemFileSize(null, $stat);
}
if (!$stat) {
print '{}';
} else {
Expand Down Expand Up @@ -221,6 +224,9 @@ public function switchActions($actionName, $httpVars, $fileVars)
foreach ($files as $index => $path) {
$node = new AJXP_Node($destStreamURL.$path);
$stat = @stat($destStreamURL.$path);
if(method_exists($this->accessDriver, "filesystemFileSize")){
$this->accessDriver->filesystemFileSize(null, $stat);
}
if(!$stat) $stat = '{}';
else {
if(!is_dir($node->getUrl())) $hash = $this->getFileHash($node);
Expand Down
6 changes: 6 additions & 0 deletions core/src/plugins/meta.syncable/class.ChangesTracker.php
Expand Up @@ -458,6 +458,9 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
} else if ($oldNode == null || $copy) {
// CREATE
$stat = stat($newNode->getUrl());
if(method_exists($newNode->getDriver(), "filesystemFileSize")){
$newNode->getDriver()->filesystemFileSize(null, $stat);
}
$newNode->setLeaf(!($stat['mode'] & 040000));
$this->logDebug('INSERT', $newNode->getUrl());
dibi::query("INSERT INTO [ajxp_index]", array(
Expand All @@ -473,6 +476,9 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
// CONTENT CHANGE
clearstatcache();
$stat = stat($newNode->getUrl());
if(method_exists($newNode->getDriver(), "filesystemFileSize")){
$newNode->getDriver()->filesystemFileSize(null, $stat);
}
$this->logDebug("Content changed", "current stat size is : " . $stat["size"]);
$this->logDebug('UPDATE CONTENT', $newNode->getUrl());
dibi::query("UPDATE [ajxp_index] SET ", array(
Expand Down
8 changes: 7 additions & 1 deletion core/src/plugins/uploader.http/class.HttpDownloader.php
Expand Up @@ -161,7 +161,13 @@ public function switchAction($action, $httpVars, $fileVars)
$file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
header("text/plain");
if (is_file($destStreamURL.$file)) {
echo filesize($destStreamURL.$file);
$node = new AJXP_Node($destStreamURL.$file);
if(method_exists($node->getDriver(), "filesystemFileSize")){
$filesize = $node->getDriver()->filesystemFileSize($node->getUrl());
}else{
$filesize = filesize($node->getUrl());
}
echo $filesize;
} else {
echo "stop";
}
Expand Down

0 comments on commit 783e094

Please sign in to comment.