session-sync 洗白扩展到 session/session_v2.directory:OC 2.x location 显示读会话表自身 directory 列
- Win DB 实锤:目标会话 ses_eb074c0daffe 的 session_v2.directory = C:/Users/ypshidifu(截图报错来源) - FIX_WORKTREE_SRC 扩展:project.worktree + session.directory + session_v2.directory 三表全洗(幂等,每次无条件跑) - 推送侧转换统一 _conv_win_path,session/session_v2 行的 directory 列同步转换
This commit is contained in:
+54
-25
@@ -173,32 +173,51 @@ except Exception as e:
|
|||||||
open("/root/.oc_sync_result.json", "w", encoding="utf-8").write(json.dumps(res))
|
open("/root/.oc_sync_result.json", "w", encoding="utf-8").write(json.dumps(res))
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# ★ 存量 worktree 洗白(2026-10-20 截图实锤「Session location unavailable / C:/Users/ypshidifu」):
|
# ★ 存量 Win 路径洗白(2026-10-20 二次实锤:OC 2.x 的 "Session location" 读的是
|
||||||
# IMPORT 用 INSERT OR IGNORE —— WSL 已存在的 project 行永远不会被 UPDATE,
|
# session/session_v2 表自身的 directory 列,不只是 project.worktree!
|
||||||
# 推送侧的路径转换只对「新插入」的行生效,存量 Win 路径洗不掉。
|
# 目标会话 ses_eb074c0daffe 的 session_v2.directory = "C:/Users/ypshidifu" 即截图来源。
|
||||||
# 此脚本每次同步无条件跑(幂等 UPDATE,开销可忽略),把 WSL project 表里
|
# 且 IMPORT 用 INSERT OR IGNORE —— WSL 已存在的行永远不会被 UPDATE,
|
||||||
# 所有 C:/Users/ypshidifu 或 C:\Users\ypshidifu 前缀的 worktree 洗成 /root。
|
# 推送侧转换只对「新插入」的行生效。此脚本每次同步无条件跑(幂等 UPDATE),
|
||||||
|
# 把三张表里所有 Win home 前缀的路径洗成 /root。
|
||||||
FIX_WORKTREE_SRC = r'''
|
FIX_WORKTREE_SRC = r'''
|
||||||
import sqlite3
|
import sqlite3
|
||||||
BK = chr(92)
|
BK = chr(92)
|
||||||
PRE_SL = "C:/Users/ypshidifu"
|
PRE_SL = "C:/Users/ypshidifu"
|
||||||
PRE_BK = "C:" + BK + "Users" + BK + "ypshidifu"
|
PRE_BK = "C:" + BK + "Users" + BK + "ypshidifu"
|
||||||
res = {"fixed": 0, "err": None}
|
res = {"fixed": {}, "err": None}
|
||||||
|
def conv(p):
|
||||||
|
if not p or not isinstance(p, str):
|
||||||
|
return None
|
||||||
|
if p.startswith(PRE_SL):
|
||||||
|
return "/root" + p[len(PRE_SL):]
|
||||||
|
if p.startswith(PRE_BK):
|
||||||
|
return "/root" + p[len(PRE_BK):]
|
||||||
|
return None
|
||||||
try:
|
try:
|
||||||
con = sqlite3.connect("/root/.local/share/opencode/opencode.db")
|
con = sqlite3.connect("/root/.local/share/opencode/opencode.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
rows = cur.execute("select id, worktree from project").fetchall()
|
# project.worktree
|
||||||
for pid, wt in rows:
|
n = 0
|
||||||
if not wt or not isinstance(wt, str):
|
for pid, wt in cur.execute("select id, worktree from project").fetchall():
|
||||||
continue
|
nw = conv(wt)
|
||||||
if wt.startswith(PRE_SL):
|
if nw:
|
||||||
cur.execute("update project set worktree=? where id=?",
|
cur.execute("update project set worktree=? where id=?", (nw, pid))
|
||||||
("/root" + wt[len(PRE_SL):], pid))
|
n += 1
|
||||||
res["fixed"] += 1
|
res["fixed"]["project.worktree"] = n
|
||||||
elif wt.startswith(PRE_BK):
|
# session.directory(列存在才跑)
|
||||||
cur.execute("update project set worktree=? where id=?",
|
def fix_dir(table):
|
||||||
("/root" + wt[len(PRE_BK):], pid))
|
cols = [r[1] for r in cur.execute("PRAGMA table_info(%s)" % table)]
|
||||||
res["fixed"] += 1
|
if "directory" not in cols:
|
||||||
|
return -1
|
||||||
|
n = 0
|
||||||
|
for sid, d in cur.execute("select id, directory from %s" % table).fetchall():
|
||||||
|
nw = conv(d)
|
||||||
|
if nw:
|
||||||
|
cur.execute("update %s set directory=? where id=?" % table, (nw, sid))
|
||||||
|
n += 1
|
||||||
|
return n
|
||||||
|
res["fixed"]["session.directory"] = fix_dir("session")
|
||||||
|
res["fixed"]["session_v2.directory"] = fix_dir("session_v2")
|
||||||
con.commit()
|
con.commit()
|
||||||
con.close()
|
con.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -340,16 +359,26 @@ def main():
|
|||||||
list(targets),
|
list(targets),
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
# ★ project.worktree 路径转换(Win C:/Users/ypshidifu/... -> WSL /root/...)
|
# ★ Win 路径转换(C:/Users/ypshidifu / C:\Users\ypshidifu -> /root)
|
||||||
# 修 WSL 侧「Session location unavailable / C:/Users/ypshidifu」
|
# 修 WSL 侧「Session location unavailable / C:/Users/ypshidifu」
|
||||||
|
# 2026-10-20 二次实锤:OC 2.x 的 location 显示读 session/session_v2 自己的
|
||||||
|
# directory 列,project.worktree 也要转,三处一起。
|
||||||
|
def _conv_win_path(p):
|
||||||
|
if not isinstance(p, str):
|
||||||
|
return p
|
||||||
|
if p.startswith(_WIN_HOME_PREFIX_SL):
|
||||||
|
return _WSL_HOME_PREFIX + p[len(_WIN_HOME_PREFIX_SL):]
|
||||||
|
if p.startswith("C:" + chr(92) + "Users" + chr(92) + "ypshidifu"):
|
||||||
|
return _WSL_HOME_PREFIX + p[len("C:" + chr(92) + "Users" + chr(92) + "ypshidifu"):]
|
||||||
|
return p
|
||||||
|
|
||||||
if tables.get("project"):
|
if tables.get("project"):
|
||||||
_wkcol = "worktree"
|
|
||||||
for _pr in tables["project"]:
|
for _pr in tables["project"]:
|
||||||
_wk = _pr.get(_wkcol)
|
_pr["worktree"] = _conv_win_path(_pr.get("worktree"))
|
||||||
if isinstance(_wk, str) and _wk.startswith(_WIN_HOME_PREFIX_SL):
|
for _t in ("session", "session_v2"):
|
||||||
_pr[_wkcol] = _WSL_HOME_PREFIX + _wk[len(_WIN_HOME_PREFIX_SL):]
|
for _r in tables.get(_t) or []:
|
||||||
elif isinstance(_wk, str) and _wk.startswith("C:\\Users\\ypshidifu"):
|
if "directory" in _r:
|
||||||
_pr[_wkcol] = _WSL_HOME_PREFIX + _wk.replace("C:\\Users\\ypshidifu", "")
|
_r["directory"] = _conv_win_path(_r.get("directory"))
|
||||||
try:
|
try:
|
||||||
tables["session_v2"] = [
|
tables["session_v2"] = [
|
||||||
dict(r)
|
dict(r)
|
||||||
|
|||||||
Reference in New Issue
Block a user