dsh-pocket 1.7.3 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/tunnel.mjs +21 -3
  2. package/package.json +1 -1
package/lib/tunnel.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  // 无密码模式:URL 即钥匙(dsh web 能执行代码,请勿把二维码/URL 发给别人)。
5
5
 
6
6
  import { spawn, execSync } from 'node:child_process';
7
- import { mkdir, access, chmod, rm, stat, rename, cp } from 'node:fs/promises';
7
+ import { mkdir, access, chmod, rm, stat, rename, cp, open } from 'node:fs/promises';
8
8
  import { homedir } from 'node:os';
9
9
  import { join, dirname } from 'node:path';
10
10
  import { pipeline } from 'node:stream/promises';
@@ -146,13 +146,15 @@ export async function downloadFile(url, dest, { signal, segments = PARALLEL_SEGM
146
146
 
147
147
  /**
148
148
  * 清华 TUNA 镜像的 cloudflared Homebrew bottle URL(国内 CDN,实测 ~3MB/s)。
149
- * 只覆盖 macOS/Linux(Windows Homebrew bottle,返回 null)。
149
+ * **仅 macOS**——Linux Homebrew bottle 其 ELF 解释器是 `@@HOMEBREW_PREFIX@@`
150
+ * 占位符(需 brew install 时 patchelf 替换),没装 Homebrew 的机器直接 spawn 会
151
+ * ENOENT(issue #22);Linux 走官方 GitHub tgz(解压即用)+ 加速源。
150
152
  * 匹配按 CPU 架构取清华目录里版本号最新的 bottle——Homebrew 构建时部署目标
151
153
  * 设得较老、向后兼容,所以旧系统(如 Ventura)也能用新一点的 bottle。
152
154
  * 抓目录失败/无匹配 → null(调用方回退 GitHub/加速源,不影响可用性)。
153
155
  */
154
156
  async function tsinghuaBottleUrl({ os, a }) {
155
- if (os !== 'darwin' && os !== 'linux') return null;
157
+ if (os !== 'darwin') return null;
156
158
  let res;
157
159
  try {
158
160
  res = await fetch(TUNA_BOTTLES, { signal: AbortSignal.timeout(20_000) });
@@ -303,6 +305,22 @@ export async function resolveCloudflared({ home, onPhase = () => {}, signal } =
303
305
  for (const bin of candidates) {
304
306
  try {
305
307
  await access(bin);
308
+ // Linux:识别并丢弃 Homebrew bottle 坏缓存(issue #22)——其 ELF 解释器是
309
+ // @@HOMEBREW_PREFIX@@ 占位符,直接 spawn 报 ENOENT;读文件头(解释器路径在
310
+ // ELF 头部附近)即可识别,命中则删掉走重新下载
311
+ if (os === 'linux') {
312
+ try {
313
+ const fd = await open(bin, 'r');
314
+ const head = Buffer.alloc(8192);
315
+ await fd.read(head, 0, 8192, 0);
316
+ await fd.close();
317
+ if (head.includes('@@HOMEBREW_PREFIX@@')) {
318
+ await rm(bin, { force: true }).catch(() => {});
319
+ console.warn('dsh-pocket: discarding unusable Homebrew-bottle cloudflared cache | 丢弃不可用的 Homebrew bottle 缓存,重新下载');
320
+ continue;
321
+ }
322
+ } catch { /* 读失败按正常缓存处理 */ }
323
+ }
306
324
  return bin; // 缓存命中,秒开
307
325
  } catch { /* 继续找下一个 */ }
308
326
  }
package/package.json CHANGED
@@ -76,5 +76,5 @@
76
76
  "access": "public",
77
77
  "registry": "https://registry.npmjs.org/"
78
78
  },
79
- "version": "1.7.3"
79
+ "version": "1.7.4"
80
80
  }