|
1 <?php |
|
2 |
|
3 /** |
|
4 * The local connection class for copying files as the httpd user. |
|
5 */ |
|
6 class FileTransferLocal extends FileTransfer implements FileTransferChmodInterface { |
|
7 |
|
8 function connect() { |
|
9 // No-op |
|
10 } |
|
11 |
|
12 static function factory($jail, $settings) { |
|
13 return new FileTransferLocal($jail); |
|
14 } |
|
15 |
|
16 protected function copyFileJailed($source, $destination) { |
|
17 if (@!copy($source, $destination)) { |
|
18 throw new FileTransferException('Cannot copy %source to %destination.', NULL, array('%source' => $source, '%destination' => $destination)); |
|
19 } |
|
20 } |
|
21 |
|
22 protected function createDirectoryJailed($directory) { |
|
23 if (!is_dir($directory) && @!mkdir($directory, 0777, TRUE)) { |
|
24 throw new FileTransferException('Cannot create directory %directory.', NULL, array('%directory' => $directory)); |
|
25 } |
|
26 } |
|
27 |
|
28 protected function removeDirectoryJailed($directory) { |
|
29 if (!is_dir($directory)) { |
|
30 // Programmer error assertion, not something we expect users to see. |
|
31 throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', NULL, array('%directory' => $directory)); |
|
32 } |
|
33 foreach (new RecursiveIteratorIterator(new SkipDotsRecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) { |
|
34 if ($file->isDir()) { |
|
35 if (@!drupal_rmdir($filename)) { |
|
36 throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $filename)); |
|
37 } |
|
38 } |
|
39 elseif ($file->isFile()) { |
|
40 if (@!drupal_unlink($filename)) { |
|
41 throw new FileTransferException('Cannot remove file %file.', NULL, array('%file' => $filename)); |
|
42 } |
|
43 } |
|
44 } |
|
45 if (@!drupal_rmdir($directory)) { |
|
46 throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $directory)); |
|
47 } |
|
48 } |
|
49 |
|
50 protected function removeFileJailed($file) { |
|
51 if (@!drupal_unlink($file)) { |
|
52 throw new FileTransferException('Cannot remove file %file.', NULL, array('%file' => $file)); |
|
53 } |
|
54 } |
|
55 |
|
56 public function isDirectory($path) { |
|
57 return is_dir($path); |
|
58 } |
|
59 |
|
60 public function isFile($path) { |
|
61 return is_file($path); |
|
62 } |
|
63 |
|
64 public function chmodJailed($path, $mode, $recursive) { |
|
65 if ($recursive && is_dir($path)) { |
|
66 foreach (new RecursiveIteratorIterator(new SkipDotsRecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) { |
|
67 if (@!chmod($filename, $mode)) { |
|
68 throw new FileTransferException('Cannot chmod %path.', NULL, array('%path' => $filename)); |
|
69 } |
|
70 } |
|
71 } |
|
72 elseif (@!chmod($path, $mode)) { |
|
73 throw new FileTransferException('Cannot chmod %path.', NULL, array('%path' => $path)); |
|
74 } |
|
75 } |
|
76 } |