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

Commit 49ccb74

Browse files
committed
fseek: $whence parameter is not properly passed to underlying stream.
S3 driver: override appendUploadedData() function as the streamWrapper does not support "a+" mode.
1 parent 4e4119b commit 49ccb74

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

core/src/plugins/access.fs/class.fsAccessWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public function stream_open($path, $mode, $options, &$context)
290290

291291
public function stream_seek($offset , $whence = SEEK_SET)
292292
{
293-
fseek($this->fp, $offset, SEEK_SET);
293+
fseek($this->fp, $offset, $whence);
294294
}
295295

296296
public function stream_tell()

core/src/plugins/access.s3/class.s3AccessDriver.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,41 @@ protected function parseSpecificContributions(&$contribNode)
145145
$this->disableArchiveBrowsingContributions($contribNode);
146146
}
147147

148+
/**
149+
* We have to overwrite original FS function as S3 wrapper does not support "a+" open mode.
150+
*
151+
* @param String $folder Folder destination
152+
* @param String $source Maybe updated by the function
153+
* @param String $target Existing part to append data
154+
* @return bool If the target file already existed or not.
155+
* @throws Exception
156+
*/
157+
protected function appendUploadedData($folder, $source, $target){
158+
159+
$already_existed = false;
160+
if($source == $target){
161+
throw new Exception("Something nasty happened: trying to copy $source into itself, it will create a loop!");
162+
}
163+
// S3 does not really support append. Let's grab the remote target first.
164+
if (file_exists($folder ."/" . $target)) {
165+
$already_existed = true;
166+
$this->logDebug("Should copy stream from $source to $target - folder is ($folder)");
167+
$partO = fopen($folder."/".$source, "r");
168+
$appendF = fopen($folder ."/". $target, 'a');
169+
while (!feof($partO)) {
170+
$buf = fread($partO, 1024);
171+
fwrite($appendF, $buf);
172+
}
173+
fclose($partO);
174+
fclose($appendF);
175+
$this->logDebug("Done, closing streams!");
176+
}
177+
@unlink($folder."/".$source);
178+
return $already_existed;
179+
180+
}
181+
182+
148183
public function isWriteable($dir, $type="dir")
149184
{
150185
return true;

0 commit comments

Comments
 (0)