cvs: pear /HTTP_WebDAV_Server/Server Filesystem.php
| From: | Hartmut Holzgraefe | Date: | Sat, 16 Apr 2005 22:43:31 +0000 |
| Subject: | cvs: pear /HTTP_WebDAV_Server/Server Filesystem.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-31210@lists.php.net to get a copy of this message | ||
hholzgra Sat Apr 16 18:43:31 2005 EDT
Modified files:
/pear/HTTP_WebDAV_Server/Server Filesystem.php
Log:
- redirect if trailing slash for collection was missing
- link files in GET output for collections
- use System:: functions instead of system() for portability
- started to reimplement DELETE and COPY to fix TODO items
(not tested yet)
http://cvs.php.net/diff.php/pear/HTTP_WebDAV_Server/Server/Filesystem.php?r1=1.14&r2=1.15&ty=u
Index: pear/HTTP_WebDAV_Server/Server/Filesystem.php
diff -u pear/HTTP_WebDAV_Server/Server/Filesystem.php:1.14
pear/HTTP_WebDAV_Server/Server/Filesystem.php:1.15
--- pear/HTTP_WebDAV_Server/Server/Filesystem.php:1.14 Sat Apr 16 18:36:41 2005
+++ pear/HTTP_WebDAV_Server/Server/Filesystem.php Sat Apr 16 18:43:31 2005
@@ -359,10 +359,19 @@
*/
function GetDir($fspath, &$options)
{
+ $path = $this->_slashify($options["path"]);
+ if ($path != $options["path"]) {
+ header("Location: ".$this->base_uri.$path);
+ exit;
+ }
+
// fixed width directory column format
$format = "%15s %-19s %-s\n";
- $handle = @opendir($fspath) or return false;
+ $handle = @opendir($fspath);
+ if (!$handle) {
+ return false;
+ }
echo "<html><head><title>Index of
".$options['path']."</title></head>\n";
@@ -375,10 +384,11 @@
while ($filename = readdir($handle)) {
if ($filename != "." && $filename != "..") {
$fullpath = $fspath."/".$filename;
+ $name = htmlspecialchars($filename);
printf($format,
number_format(filesize($fullpath)),
strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)),
- htmlspecialchars($filename));
+ "<a href='$name'>$name</a>");
}
}
@@ -463,9 +473,9 @@
if (!file_exists($path)) return "404 Not found";
if (is_dir($path)) {
- $query = "DELETE FROM properties WHERE path LIKE
'$options[path]%'";
+ $query = "DELETE FROM properties WHERE path LIKE
'".$options["path"]."%'";
mysql_query($query);
- system("rm -rf $path");
+ System::rm("-rf $path");
} else {
unlink ($path);
}
@@ -532,36 +542,52 @@
if (!$new) {
if ($options["overwrite"]) {
- $stat = $this->delete(array("path" =>
$options["dest"]));
- if ($stat{0} != "2") return $stat;
+ $stat = $this->DELETE(array("path" =>
$options["dest"]));
+ if (($stat{0} != "2") && (substr($stat, 0, 3) !=
"404")) {
+ return $stat;
+ }
} else {
return "412 precondition failed";
}
}
- if (is_dir($source)) {
+ if (is_dir($source) && ($options["depth"] != "infinity")) {
// RFC 2518 Section 9.2, last paragraph
- if ($options["depth"] != "infinity") {
- error_log("---- ".$options["depth"]);
- return "400 Bad request";
- }
- system(escapeshellcmd("cp -R ".escapeshellarg($source) ." " .
escapeshellarg($dest)));
-
- if ($del) {
- system(escapeshellcmd("rm -rf ".escapeshellarg($source)) );
+ return "400 Bad request";
+ }
+
+ if ($del) {
+ if (!rename($source, $dest)) {
+ return "500 Internal server error";
}
- } else {
- if ($del) {
- @unlink($dest);
- $query = "DELETE FROM properties WHERE path =
'$options[dest]'";
+ if (is_dir($source)) {
+ $destpath = $this->_slashify($options["dest"]);
+ $query = "UPDATE properties
+ SET path = REPLACE(path,
'".$options["path"]."', '".$destpath."')
+ WHERE path LIKE
'".$options["path"]."%'";
mysql_query($query);
- rename($source, $dest);
- $query = "UPDATE properties SET path = '$options[dest]' WHERE
path = '$options[path]'";
- mysql_query($query);
- } else {
- if (substr($dest,-1)=="/") $dest = substr($dest,0,-1);
- copy($source, $dest);
}
+ $query = "UPDATE properties
+ SET path = '".$destpath."'
+ WHERE path =
'".$options["path"]."%'";
+ mysql_query($query);
+ } else {
+ $files = array_reverse(System::find($source));
+
+ if (!is_array($files)) {
+ return "500 Internal server error";
+ }
+
+ foreach ($files as $file) {
+ $destfile = str_replace($source, $dest, $file);
+ if (is_dir($file)) {
+ mkdir($destfile);
+ } else {
+ copy($sourcefile, $destfile);
+ }
+ }
+
+ $query = "INSERT INTO properties SELECT ... FROM properties WHERE path =
'".$options['path']."';
}
return ($new && !$existing_col) ? "201 Created" : "204 No
Content";