Navigation Menu

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

Commit

Permalink
fseek: $whence parameter is not properly passed to underlying stream.
Browse files Browse the repository at this point in the history
S3 driver: override appendUploadedData() function as the streamWrapper does not support "a+" mode.
  • Loading branch information
cdujeu committed Jul 14, 2015
1 parent 4e4119b commit 49ccb74
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/plugins/access.fs/class.fsAccessWrapper.php
Expand Up @@ -290,7 +290,7 @@ public function stream_open($path, $mode, $options, &$context)

public function stream_seek($offset , $whence = SEEK_SET)
{
fseek($this->fp, $offset, SEEK_SET);
fseek($this->fp, $offset, $whence);
}

public function stream_tell()
Expand Down
35 changes: 35 additions & 0 deletions core/src/plugins/access.s3/class.s3AccessDriver.php
Expand Up @@ -145,6 +145,41 @@ protected function parseSpecificContributions(&$contribNode)
$this->disableArchiveBrowsingContributions($contribNode);
}

/**
* We have to overwrite original FS function as S3 wrapper does not support "a+" open mode.
*
* @param String $folder Folder destination
* @param String $source Maybe updated by the function
* @param String $target Existing part to append data
* @return bool If the target file already existed or not.
* @throws Exception
*/
protected function appendUploadedData($folder, $source, $target){

$already_existed = false;
if($source == $target){
throw new Exception("Something nasty happened: trying to copy $source into itself, it will create a loop!");
}
// S3 does not really support append. Let's grab the remote target first.
if (file_exists($folder ."/" . $target)) {
$already_existed = true;
$this->logDebug("Should copy stream from $source to $target - folder is ($folder)");
$partO = fopen($folder."/".$source, "r");
$appendF = fopen($folder ."/". $target, 'a');
while (!feof($partO)) {
$buf = fread($partO, 1024);
fwrite($appendF, $buf);
}
fclose($partO);
fclose($appendF);
$this->logDebug("Done, closing streams!");
}
@unlink($folder."/".$source);
return $already_existed;

}


public function isWriteable($dir, $type="dir")
{
return true;
Expand Down

0 comments on commit 49ccb74

Please sign in to comment.