append .part to put files

This commit is contained in:
Jörn Friedrich Dreyer 2013-02-10 14:16:45 +01:00
parent 1c56539c01
commit 1263511a17
2 changed files with 24 additions and 2 deletions

View File

@ -45,7 +45,13 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
*/
public function put($data) {
\OC\Files\Filesystem::file_put_contents($this->path,$data);
// mark file as partial while uploading (ignored by the scanner)
$partpath = $this->path . '.part';
\OC\Files\Filesystem::file_put_contents($partpath, $data);
// rename to correct path
\OC\Files\Filesystem::rename($partpath, $this->path);
return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
}

View File

@ -97,7 +97,7 @@ class Scanner {
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
while ($file = readdir($dh)) {
if ($file !== '.' and $file !== '..') {
if (!$this->isIgnoredFile($file)) {
$child = ($path) ? $path . '/' . $file : $file;
$data = $this->scanFile($child);
if ($data) {
@ -133,6 +133,22 @@ class Scanner {
}
return $size;
}
/**
* @brief check if the file should be ignored when scanning
* NOTE: files with a '.part' extension are ignored as well!
* prevents unfinished put requests to be scanned
* @param String $file
* @return boolean
*/
private function isIgnoredFile($file) {
if ($file === '.' || $file === '..'
|| pathinfo($file,PATHINFO_EXTENSION) === 'part')
{
return true;
}
return false;
}
/**
* walk over any folders that are not fully scanned yet and scan them