Incorrect POSIXError (Code 52) when creating duplicate directory in 4.0.0+
Description
After upgrading to version 4.0.0+, attempting to create a directory that already exists incorrectly throws a POSIXError with code 52 ("Network dropped connection on reset") instead of the expected file already exists error (EEXIST, POSIX code 17). This breaks backward compatibility with error-handling logic that previously relied on checking for EEXIST.
Steps to Reproduce
- Create a directory (e.g.,
/test/directory) - Attempt to create the same directory again
- Observe error:
POSIXError(_nsError: Error Domain=NSPOSIXErrorDomain Code=52 "Network dropped connection on reset" UserInfo={NSLocalizedDescription=Error code 52: Create failed with status -1073741771.})
I’ve checked the issue. It seems the problem is in libsmb2’s create_cb_1 function.
It should either call smb2_set_nterror or invoke the callback function with a status code (or both, depending on the function), following the pattern used in other callbacks.
As a workaround, you could perform a preflight check to verify the directory’s existence, or consider opening an issue to request a fix in libsmb2 itself.