Fix SMB STATUS_ACCESS_DENIED on rename after read

smbclient.open_file() opens files with default share mode (read-only),
which blocks subsequent rename/delete operations because the underlying
SMB connection stays in the library's connection pool.

Use share_access="rwd" to allow concurrent read/write/delete, making
the move-after-read operation deterministically work.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
duffyduck 2026-04-14 10:04:41 +02:00
parent 337e0e99a5
commit 35366e0c1b
1 changed files with 8 additions and 2 deletions

View File

@ -66,8 +66,14 @@ def _list_pdf_files(source_path: str) -> list[str]:
def _read_smb_file(filepath: str) -> bytes: def _read_smb_file(filepath: str) -> bytes:
"""Read a file from SMB share into memory.""" """Read a file from SMB share into memory.
with smbclient.open_file(filepath, mode="rb") as f:
share_access="rwd" allows concurrent read/write/delete operations on the same
file, which is required because smbclient keeps the underlying SMB connection
in a pool. Without this, subsequent rename/delete on the file fails with
STATUS_ACCESS_DENIED until the session is closed.
"""
with smbclient.open_file(filepath, mode="rb", share_access="rwd") as f:
return f.read() return f.read()