adding detection of aborted uploads
This commit is contained in:
parent
16ef5a8b35
commit
39599019e5
|
@ -55,18 +55,8 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
|
|||
}
|
||||
|
||||
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
|
||||
$info = OC_FileChunking::decodeName($name);
|
||||
if (empty($info)) {
|
||||
throw new Sabre_DAV_Exception_NotImplemented();
|
||||
return $this->createFileChunked($name, $data);
|
||||
}
|
||||
$chunk_handler = new OC_FileChunking($info);
|
||||
$chunk_handler->store($info['index'], $data);
|
||||
if ($chunk_handler->isComplete()) {
|
||||
$newPath = $this->path . '/' . $info['name'];
|
||||
$chunk_handler->file_assemble($newPath);
|
||||
return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
|
||||
}
|
||||
} else {
|
||||
$newPath = $this->path . '/' . $name;
|
||||
|
||||
// mark file as partial while uploading (ignored by the scanner)
|
||||
|
@ -101,9 +91,6 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
|
|||
return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new subdirectory
|
||||
*
|
||||
|
@ -250,7 +237,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
|
|||
* If the array is empty, all properties should be returned
|
||||
*
|
||||
* @param array $properties
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function getProperties($properties) {
|
||||
$props = parent::getProperties($properties);
|
||||
|
@ -260,4 +247,34 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
|
|||
}
|
||||
return $props;
|
||||
}
|
||||
|
||||
private function createFileChunked($name, $data)
|
||||
{
|
||||
$info = OC_FileChunking::decodeName($name);
|
||||
if (empty($info)) {
|
||||
throw new Sabre_DAV_Exception_NotImplemented();
|
||||
}
|
||||
$chunk_handler = new OC_FileChunking($info);
|
||||
$bytesWritten = $chunk_handler->store($info['index'], $data);
|
||||
|
||||
//detect aborted upload
|
||||
if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
|
||||
if (isset($_SERVER['CONTENT_LENGTH'])) {
|
||||
$expected = $_SERVER['CONTENT_LENGTH'];
|
||||
if ($bytesWritten != $expected) {
|
||||
$chunk_handler->cleanup();
|
||||
throw new Sabre_DAV_Exception_BadRequest(
|
||||
'expected filesize ' . $expected . ' got ' . $bytesWritten);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($chunk_handler->isComplete()) {
|
||||
$newPath = $this->path . '/' . $info['name'];
|
||||
$chunk_handler->file_assemble($newPath);
|
||||
return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue