diff --git a/.gitignore b/.gitignore index fe9c0e3..29f6119 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,4 @@ # source browser cache clone web/.src/ -web/repo/ +web/git/ diff --git a/web/git.php b/web/git.php index 6420bab..5bc03b1 100644 --- a/web/git.php +++ b/web/git.php @@ -7,18 +7,9 @@ define('PMM_SITE', 1); require __DIR__ . '/_common.php'; $REPO_URL = 'https://github.com/JGZYES/ParlzPackageManger.git'; -/* Choose a PHP-writable location for the local repo clone (the web root may be - * owned by root, so PHP/php-fpm often can't create web/repo). */ -function pick_repo_dir(): string { - $env = getenv('PMM_SRC_DIR'); - if ($env && (is_dir($env) || @mkdir($env, 0775, true))) return $env; - $local = __DIR__ . '/repo'; - if (is_dir($local) || @mkdir($local, 0775, true)) return $local; - $tmp = sys_get_temp_dir() . '/pmm-src'; - @mkdir($tmp, 0775, true); - return $tmp; -} -$REPO_DIR = pick_repo_dir(); +/* Local repo clone lives in web/git (i.e. /www/sites/ParlzPackageManger/index/web/git + * on the live host). PMM_SRC_DIR may override it. PHP needs write access there. */ +$REPO_DIR = getenv('PMM_SRC_DIR') ?: (__DIR__ . '/git'); /* handle the one-click clone/pull early (no page output yet) */ if (isset($_GET['action']) && $_GET['action'] === 'init') { @@ -28,7 +19,7 @@ if (isset($_GET['action']) && $_GET['action'] === 'init') { $cmd = 'git clone --depth 1 ' . escapeshellarg($REPO_URL) . ' ' . escapeshellarg($REPO_DIR) . ' 2>&1'; $out = (string)@shell_exec($cmd); if (is_dir($REPO_DIR . '/.git')) echo 'OK'; - else echo '克隆失败:' . substr($out, 0, 220) . "\n(已尝试写入 " . $REPO_DIR . ')'; + else echo '克隆失败:' . substr($out, 0, 220) . "\n(请确保 PHP 对 ' . $REPO_DIR . ' 可写:chmod -R 775 ' . $REPO_DIR . ' 或其父目录;或设 PMM_SRC_DIR)'; } else { $out = (string)@shell_exec('git -C ' . escapeshellarg($REPO_DIR) . ' pull --depth 1 2>&1'); echo 'OK (pull: ' . substr(trim($out), 0, 80) . ')'; @@ -91,7 +82,8 @@ pmm_header('source', '源码浏览');
页面用 PHP 可写目录 存放仓库副本。若服务器 web 根对 PHP 不可写,会在 /tmp 类的临时目录存一份(重启可能失效)。可改用环境变量 PMM_SRC_DIR 指定持久可写目录;或 chmod 775 仓库目录。初始化命令:
页面将 PMM 仓库副本存入 。若 PHP 无写权限(web 根归 root),先
+ chmod -R 775 或其父目录;或用环境变量 PMM_SRC_DIR 指定持久目录。初始化命令:
git clone --depth 1