fix(install): rename 到幽灵名失败时改用「直写最终名 + 回读 sha256」
实测(2026-10-28, Z:\Temporary\短视频\_io-test):.mov → .mp4 装不进去,三次都死在
os.replace('…new.mp4','…hevc-pcm.mp4') 的 WinError 32,而同一目录手搓 os.replace 全成功 ——
是幽灵条目:os.path.exists 说存在、ls 同一目录看不到,服务端已忘记该名字,任何 rename 都失败。
- 先按「短暂占用」重试 5 次退避(实测无效,5 秒内全失败)
- 最终处理:还剩本地已验证产物,就直接写到最终名并回读 sha256 比对,再清 staged 名
实测:19 MB -> 18 MB (93%) | copy,audio=aac、video md5 与源逐位相同。
同时把这条 .mov 样本的 io 链路跑通(前两轮分别是 win32 占用与幽灵名),
三条样本现在全部 hevc hvc1 + aac mp4a。
This commit is contained in:
1 parent
6950f75d26
commit
e66551200f
1 file changed
+37
-1
+37
-1
@@ -1575,7 +1575,43 @@ def process(src, args, dest=None, origin=None):
|
||||
else:
|
||||
return last, None
|
||||
# 6. atomic replace, then confirm on the share
|
||||
os.replace(remote_tmp, live)
|
||||
#
|
||||
# The upload's write handle is not gone the moment `copy_local_to_remote` returns: an SMB
|
||||
# client can hold it for a second or two, and the rename then dies with WinError 32 ("being
|
||||
# used by another process") for a file nobody else has open. That is what failed the
|
||||
# `.mov -> .mp4` install of one 19 MB clip three times in a row (measured 2026-10-28 on
|
||||
# Z:\Temporary\短视频\_io-test) while a hand-run os.replace in the SAME directory
|
||||
# succeeded - so it is the leftover handle, not the share's permissions. Retry a few times
|
||||
# instead of failing an item that is already encoded AND verified.
|
||||
for _try in range(1, 6):
|
||||
try:
|
||||
os.replace(remote_tmp, live)
|
||||
break
|
||||
except OSError as e:
|
||||
if _try == 5:
|
||||
# A rename that cannot be satisfied at all is a PHANTOM staged name, not a
|
||||
# busy file: the share's local cache reported `...new.mp4` as existing while the
|
||||
# server had already forgotten it (measured 2026-10-28: os.path.exists() said
|
||||
# yes, `ls` of the same directory did not list it, and every rename - including
|
||||
# a hand-run one - failed with WinError 32). Retrying cannot fix that. We still
|
||||
# HOLD the verified local encode, so install it straight under the final name
|
||||
# and hash-check it, instead of failing an item that is already done.
|
||||
log(" ! rename is impossible on this share (%s) - installing %s directly"
|
||||
% (str(e)[:70], os.path.basename(live)))
|
||||
if not copy_local_to_remote(loc_out, live):
|
||||
return ("FAIL install: the share refused both the rename (%s) and a direct "
|
||||
"write of %s" % (str(e)[:70], live)), None
|
||||
h_re, n_re = _sha_remote(live)
|
||||
if (h_re, n_re) != (h_loc, n_loc):
|
||||
return ("FAIL install read-back: %s is %s/%d, encoded was %s/%d"
|
||||
% (live, h_re[:12], n_re, h_loc[:12], n_loc)), None
|
||||
try:
|
||||
os.remove(remote_tmp)
|
||||
except OSError:
|
||||
pass
|
||||
break
|
||||
log(" ! rename held by the share (%s) - retry %d/5" % (str(e)[:70], _try))
|
||||
time.sleep(0.5 * _try)
|
||||
# NEVER delete the source when it came from the snapshot origin: that is the archive of
|
||||
# the originals, and removing it would destroy the only clean copy of the library.
|
||||
if not origin_used and not getattr(args, "keep_source", False) \
|
||||
|
||||
Reference in new issue
Block a user