4 * Sabre_DAV_Tree_Filesystem
8 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
9 * @author Evert Pot (http://www.rooftopsolutions.nl/)
10 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
12 class Sabre_DAV_Tree_Filesystem extends Sabre_DAV_Tree {
15 * Base url on the filesystem.
24 * Supply the path you'd like to share.
26 * @param string $basePath
28 public function __construct($basePath) {
30 $this->basePath = $basePath;
35 * Returns a new node for the given path
38 * @return Sabre_DAV_FS_Node
40 public function getNodeForPath($path) {
42 $realPath = $this->getRealPath($path);
43 if (!file_exists($realPath)) throw new Sabre_DAV_Exception_NotFound('File at location ' . $realPath . ' not found');
44 if (is_dir($realPath)) {
45 return new Sabre_DAV_FS_Directory($realPath);
47 return new Sabre_DAV_FS_File($realPath);
53 * Returns the real filesystem path for a webdav url.
55 * @param string $publicPath
58 protected function getRealPath($publicPath) {
60 return rtrim($this->basePath,'/') . '/' . trim($publicPath,'/');
65 * Copies a file or directory.
67 * This method must work recursively and delete the destination
70 * @param string $source
71 * @param string $destination
74 public function copy($source,$destination) {
76 $source = $this->getRealPath($source);
77 $destination = $this->getRealPath($destination);
78 $this->realCopy($source,$destination);
85 * @param string $source
86 * @param string $destination
89 protected function realCopy($source,$destination) {
91 if (is_file($source)) {
92 copy($source,$destination);
95 foreach(scandir($source) as $subnode) {
97 if ($subnode=='.' || $subnode=='..') continue;
98 $this->realCopy($source.'/'.$subnode,$destination.'/'.$subnode);
106 * Moves a file or directory recursively.
108 * If the destination exists, delete it first.
110 * @param string $source
111 * @param string $destination
114 public function move($source,$destination) {
116 $source = $this->getRealPath($source);
117 $destination = $this->getRealPath($destination);
118 rename($source,$destination);