Skip to content

Commit

Permalink
Added the TemporaryFileFilter tree-class
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed May 27, 2008
1 parent 928c432 commit a425f04
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sabre/DAV/FilterTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license licence http://www.freebsd.org/copyright/license.html BSD License (4 Clause)
*/
class Sabre_DAV_FilterTree extends Sabre_DAV_Tree {
abstract class Sabre_DAV_FilterTree extends Sabre_DAV_Tree {

/**
* subject
Expand All @@ -32,7 +32,7 @@ class Sabre_DAV_FilterTree extends Sabre_DAV_Tree {
*/
public function __construct(Sabre_DAV_Tree $subject) {

$this->tempDir = $tempDir;
$this->subject = $subject;

}

Expand Down Expand Up @@ -144,7 +144,7 @@ public function move($sourcePath, $destinationPath) {
*/
public function supportsLocks() {

return $this->subject->supportLocks();
return $this->subject->supportsLocks();

}

Expand Down
124 changes: 124 additions & 0 deletions Sabre/DAV/TemporaryFileFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

require_once 'Sabre/DAV/FilterTree.php';

class Sabre_DAV_TemporaryFileFilter extends Sabre_DAV_FilterTree {

private $dataDir = null;

const FINDER_FORK =
'H4sIAAAAAAAAA+3XMWsCMRQH8Beh2Fu0OHQqR+Yicji6FV0cRKiHlG7xfNJwuSTkIuK36mdy6rfQiGepwtHNQd6PhHCP9w+5bIGH5yY0ACYi49MZ/+CVYw2iMPsAre+whu/WDoDFcPYENd7S9D0snVMCfsL8vGppVPXXMDJT9IS1CnsFerEUXgzyyWjssRiXs8wh6qGwfu3wFGVhX0gAuvW5i1S6tSG5sEqWPkmix2oXVp2EXZ0sOnfON1Ivzea//nbdLRBCCCGEEEIIuTUGf55tcfolS+6wNGuXIV8Zl3OpPWovjRZKbbnClecLJXR+fAffgcv//y2/QLzfHwDNa116ABAAAA==';

public function setDataDir($path) {

$this->dataDir = $path;

}

public function isTempFile($path) {

$tempPath = basename($path);

$tempFiles = array(
'/^._(.*)$/', // OS/X resource forks
'/^.DS_Store$/', // OS/X custom folder settings
'/^desktop.ini$/', // Windows custom folder settings
'/^Thumbs.db$/', // Windows thumbnail cache
'/^.(.*).swp$/', // ViM temporary files
);

$match = false;
foreach($tempFiles as $tempFile) {

if (preg_match($tempFile,$tempPath)) $match = true;

}

if ($match) {
$dataDir = (is_null($this->dataDir)?ini_get('session.save_path').'/sabredav/':$this->dataDir);
return $dataDir . '/sabredav_' . md5($path) . '.tempfile';
} else {
return false;
}

}

public function put($path,$data) {

if ($tempPath = $this->isTempFile($path)) {

file_put_contents($tempPath,$data);

} else return parent::put($path,$data);

}

public function createFile($path,$data) {

if ($tempPath = $this->isTempFile($path)) {

file_put_contents($tempPath,$data);

} else return parent::createFile($path,$data);

}

public function get($path) {

if ($tempPath = $this->isTempFile($path)) {

if (!file_exists($tempPath)) {
if (strpos(basename($path),'._')===0) echo gzdecode(base64_decode(self::FINDER_FORK));
else throw new Sabre_DAV_FileNotFoundException();
} else {
return file_get_contents($tempPath);
}

} else return parent::get($path);

}

public function delete($path) {

if ($tempPath = $this->isTempFile($path)) {

return(file_exists($tempPath) && unlink($tempPath));

} else return parent::delete($path);

}

public function getNodeInfo($path,$depth=0) {

if (($tempPath = $this->isTempFile($path)) && !$depth) {

//echo $tempPath;
if (!file_exists($tempPath)) {
if (strpos(basename($path),'._')===0) {
return array(array(
'name' => '',
'type' => Sabre_DAV_Server::NODE_FILE,
'lastmodified' => filemtime(__FILE__),
'size' => 4096,
));

} else {
throw new Sabre_DAV_FileNotFoundException();
}
}
$props = array(
'name' => '',
'type' => Sabre_DAV_Server::NODE_FILE,
'lastmodified' => filemtime($tempPath),
'size' => filesize($tempPath),
);

return array($props);

} else return parent::getNodeInfo($path,$depth);

}

}

?>

0 comments on commit a425f04

Please sign in to comment.