From 35366e0c1bb24ec916fc8ef8c4477b567a35a6a1 Mon Sep 17 00:00:00 2001 From: duffyduck Date: Tue, 14 Apr 2026 10:04:41 +0200 Subject: [PATCH] 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) --- app/smb_processor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/smb_processor.py b/app/smb_processor.py index 323603a..9352d2a 100644 --- a/app/smb_processor.py +++ b/app/smb_processor.py @@ -66,8 +66,14 @@ def _list_pdf_files(source_path: str) -> list[str]: def _read_smb_file(filepath: str) -> bytes: - """Read a file from SMB share into memory.""" - with smbclient.open_file(filepath, mode="rb") as f: + """Read a file from SMB share into memory. + + 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()