-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.php
67 lines (55 loc) · 1.18 KB
/
link.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
64
65
66
67
#!/usr/bin/php
<?php
/*
* Modified from Nooku, removed need for command line console
* Dependencies:
*
*/
$source = $_SERVER['argv'][1];
$target = $_SERVER['argv'][2];
// Make symlinks
if(file_exists($source))
{
$it = new KSymlinker($source, $target);
while($it->valid()) {
$it->next();
}
}
class KSymlinker extends RecursiveIteratorIterator
{
protected $_srcdir;
protected $_tgtdir;
public function __construct($srcdir, $tgtdir)
{
$this->_srcdir = $srcdir;
$this->_tgtdir = $tgtdir;
parent::__construct(new RecursiveDirectoryIterator($this->_srcdir));
}
public function callHasChildren()
{
$filename = $this->getFilename();
if($filename[0] == '.') {
return false;
}
$src = $this->key();
$tgt = str_replace($this->_srcdir, '', $src);
$tgt = str_replace('/site', '', $tgt);
$tgt = $this->_tgtdir.$tgt;
if(is_link($tgt)) {
unlink($tgt);
}
if(!is_dir($tgt)) {
$this->createLink($src, $tgt);
return false;
}
return parent::callHasChildren();
}
public function createLink($src, $tgt)
{
if(!file_exists($tgt))
{
exec("ln -sf $src $tgt");
//echo $src.PHP_EOL."\t--> $tgt".PHP_EOL;
}
}
}