You are here

function _boost_symlink in Boost 5

Creates a symbolic link using a computed relative path where possible.

1 call to _boost_symlink()
boost_cache_set in ./boost.api.inc
Replaces the cached contents of the specified page, if stale.

File

./boost.helpers.inc, line 60
Various helper functions for the Boost module, to make life a bit easier.

Code

function _boost_symlink($target, $link) {
  if (!file_exists($target) || !file_exists(dirname($link))) {
    return FALSE;
  }
  $target = explode('/', $target);
  $link = explode('/', $link);

  // Only bother creating a relative link if the paths are in the same
  // top-level directory; otherwise just symlink to the absolute path.
  if ($target[1] == $link[1]) {

    // Remove the common path prefix
    $cwd = array();
    while (count($target) > 0 && count($link) > 0 && reset($target) == reset($link)) {
      $cwd[] = array_shift($target);
      array_shift($link);
    }

    // Compute the required relative path
    if (count($link) > 1) {
      $target = array_merge(array_fill(0, count($link) - 1, '..'), $target);
    }
    $link = array_merge($cwd, $link);
  }
  return symlink(implode('/', $target), implode('/', $link));
}