Further to my last post, in the end I created a PHP script which uses exec to run linkd.exe which comes free as part of the Windows Resource Kit Tools.
I run this script whenever I need to refresh the links. Obviously any change made to the target directories and files automatically appear in each site without the need to run this script. This script only needs to be edited and rerun when a new site is added or a directory or file is added to the common target.
There is bound to be loads of things wrong with this script but hopefully it gives an idea of what on first impressions appears to work for me. No doubt in days to come changes will be made to this script to resolve issues and make it work better. This all assumes that there is not a much simpler solution out there which I have overlooked.
The script is shown below.
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
?>
<?php
// ----
// Sets inputs
// ----
$directories=array(
'admin',
'cms',
'images',
'module_calendar',
'module_contactform',
'module_cssmenu',
'module_homepreviews',
'module_localimages',
'module_login',
'module_my',
'module_savechecks',
'module_servervariables',
'module_sitesearch',
'module_slideshow',
'mysite',
'sapphire',
'themes',
);
$files=array(
'robots.txt',
'.htaccess',
'favicon.ico',
);
$sites=array(
'totnes',
'buckfastleigh',
'ashburton',
'newtonabbot',
);
// ----
$results=array();
foreach($sites as $site){
if(!file_exists("d:/vhosts/$site"))mkdir("d:/vhosts/$site",0777);
foreach($directories as $directory){
$results[]=$site;
$results[]=_unlink("d:/vhosts/$site/$directory");
$results[]=_link("D:/vhosts/links/silverstripe/$directory","d:/vhosts/$site/$directory");
$results[]=_list("d:/vhosts/$site/$directory");
}
foreach($files as $file){
$results[]=$site;
$results[]=_link("D:/vhosts/links/silverstripe/$file","d:/vhosts/$site/$file");
}
}
/* debug */echo "<pre>";print_r("Variable=<strong>\$results</strong> Value=");print_r($results);echo "</pre>";
?>
<?php
function _link( $target, $link ) {
if ($_SERVER['WINDIR'] || $_SERVER['windir']){
if(is_dir($target)){
// Links to directories in windows
exec("linkd $link $target", $message, $val);
$result=0==$val;
$function=__FUNCTION__;
return compact('result','function','message');
}elseif(is_file($target)){
// Hardlinks link to files in windows
exec("fsutil hardlink create $link $target", $message, $val);
$result=0==$val;
$function=__FUNCTION__;
return compact('result','function','message');
}
$result=false;
$function=__FUNCTION__;
$message='';
return compact('result','function','message');
}else{
symlink($target,$link);
}
}
function _unlink($link ){
if ($_SERVER['WINDIR'] || $_SERVER['windir']){
exec('linkd "' . $link . '" /D',$message,$val);
$result=0==$val;
$function=__FUNCTION__;
return compact('result','function','message');
} else {
unlink($link);
}
}
function _list($link){
if ($_SERVER['WINDIR'] || $_SERVER['windir']){
exec('linkd "' . $link . '"',$message,$val);
$result=0==$val;
$function=__FUNCTION__;
return compact('result','function','message');
}
}
?>