コード例 #1
0
ファイル: util.inc.php プロジェクト: gohai/sausagemachine
/**
 *	Copy the content of a directory
 *	@param $src path to a file or directory
 *	@param $dst path to a file or directory
 *	@return true if successful, false if not
 */
function cp_recursive($src, $dst)
{
    if (is_file($src)) {
        return @copy($src, $dst);
    } else {
        if (is_dir($src)) {
            if (($childs = @scandir($src)) === false) {
                return false;
            }
            if (!is_dir(rtrim($dst, '/'))) {
                if (false === @mkdir(rtrim($dst, '/'))) {
                    return false;
                }
            }
            $success = true;
            foreach ($childs as $child) {
                if ($child == '.' || $child == '..') {
                    continue;
                }
                if (false === cp_recursive(rtrim($src, '/') . '/' . $child, rtrim($dst, '/') . '/' . $child)) {
                    $success = false;
                }
            }
            return $success;
        }
    }
}
コード例 #2
0
ファイル: git.inc.php プロジェクト: gohai/sausagemachine
/**
 *	Get a private copy of a remote Git repository
 *
 *	The private copy can be manipulated with the returned tmp key. Call
 *	release_repo() after it is no longer needed.
 *	@param $url Git (clone) URL
 *	@param $branch branch to check out (default is "master")
 *	@param $force_update force a fetch
 *	@return tmp key, or false if unsuccessful
 */
function get_repo($url, $branch = 'master', $force_update = false)
{
    $tmp_key = tmp_key();
    // get a cached copy, currently on the master branch
    $cache_key = get_repo_for_reading($url, $force_update);
    if ($cache_key === false) {
        return false;
    }
    // create files and directories as permissive as possible
    $old_umask = @umask(00);
    // copy to tmp
    if (false === cp_recursive(cache_dir($cache_key), tmp_dir($tmp_key))) {
        // copying failed, remove again
        rm_recursive(tmp_dir($tmp_key));
        @umask($old_umask);
        return false;
    }
    if ($branch === 'master') {
        // XXX (later): revisit & document - IIRC the reason for this was that
        // same of the permissions were off after a regular copy (w/ umask) and
        // that running the git command somehow fix them?
        $ret = repo_cleanup($tmp_key);
    } else {
        $ret = repo_checkout_branch($tmp_key, $branch);
        // XXX (later): revisit - does this also need repo_cleanup()?
    }
    @umask($old_umask);
    if ($ret === false) {
        // copying failed, remove again
        rm_recursive(tmp_dir($tmp_key));
        return false;
    }
    // XXX (later): this could be done asynchronously
    check_tmp_dir_age();
    return $tmp_key;
}