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_FSExt_Directory extends Sabre_DAV_FSExt_Node implements Sabre_DAV_ICollection, Sabre_DAV_IQuota {
15 * Creates a new file in the directory
17 * Data will either be supplied as a stream resource, or in certain cases
18 * as a string. Keep in mind that you may have to support either.
20 * After successful creation of the file, you may choose to return the ETag
21 * of the new file here.
23 * The returned ETag must be surrounded by double-quotes (The quotes should
24 * be part of the actual string).
26 * If you cannot accurately determine the ETag, you should not return it.
27 * If you don't store the file exactly as-is (you're transforming it
28 * somehow) you should also not return an ETag.
30 * This means that if a subsequent GET to this new file does not exactly
31 * return the same contents of what was submitted here, you are strongly
32 * recommended to omit the ETag.
34 * @param string $name Name of the file
35 * @param resource|string $data Initial payload
38 public function createFile($name, $data = null) {
40 // We're not allowing dots
41 if ($name=='.' || $name=='..') throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
42 $newPath = $this->path . '/' . $name;
43 file_put_contents($newPath,$data);
45 return '"' . md5_file($newPath) . '"';
50 * Creates a new subdirectory
55 public function createDirectory($name) {
57 // We're not allowing dots
58 if ($name=='.' || $name=='..') throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
59 $newPath = $this->path . '/' . $name;
65 * Returns a specific child node, referenced by its name
67 * This method must throw Sabre_DAV_Exception_NotFound if the node does not
71 * @throws Sabre_DAV_Exception_NotFound
72 * @return Sabre_DAV_INode
74 public function getChild($name) {
76 $path = $this->path . '/' . $name;
78 if (!file_exists($path)) throw new Sabre_DAV_Exception_NotFound('File could not be located');
79 if ($name=='.' || $name=='..') throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
83 return new Sabre_DAV_FSExt_Directory($path);
87 return new Sabre_DAV_FSExt_File($path);
94 * Checks if a child exists.
99 public function childExists($name) {
101 if ($name=='.' || $name=='..')
102 throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
104 $path = $this->path . '/' . $name;
105 return file_exists($path);
110 * Returns an array with all the child nodes
112 * @return Sabre_DAV_INode[]
114 public function getChildren() {
117 foreach(scandir($this->path) as $node) if($node!='.' && $node!='..' && $node!='.sabredav') $nodes[] = $this->getChild($node);
123 * Deletes all files in this directory, and then itself
127 public function delete() {
129 // Deleting all children
130 foreach($this->getChildren() as $child) $child->delete();
132 // Removing resource info, if its still around
133 if (file_exists($this->path . '/.sabredav')) unlink($this->path . '/.sabredav');
135 // Removing the directory itself
138 return parent::delete();
143 * Returns available diskspace information
147 public function getQuotaInfo() {
150 disk_total_space($this->path)-disk_free_space($this->path),
151 disk_free_space($this->path)