-
Notifications
You must be signed in to change notification settings - Fork 8
/
CopyFoldersTask.php
63 lines (55 loc) · 1.49 KB
/
CopyFoldersTask.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Copy a specified set of folders from one location to another
*
* @author marcus
*
*/
class CopyFoldersTask extends Task
{
private $items = null;
private $targetDir = null;
private $copy = false;
private $sourceDir = null;
public function setItems($items) {
$this->items = explode(',', $items);
}
public function setSourceDir($sourceDir) {
$this->sourceDir = $sourceDir;
}
public function setTargetDir($targetDir) {
$this->targetDir = $targetDir;
}
public function copy($copy) {
$this->copy = $copy;
}
public function main() {
if (!is_dir($this->targetDir)) {
throw new BuildException("Invalid symlink target $this->targetDir");
}
foreach ($this->items as $item) {
// if there's a source dir set, we're assuming everything is coming from that dir
$sourceItem = $this->sourceDir ? $this->sourceDir . '/' . $item : $item;
if (!recurse_copy($sourceItem, $this->targetDir . '/' . $item)) {
throw new BuildException("Failed copying from $sourceItem to ".$this->targetDir);
}
}
}
}
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
return true;
}
?>