Side-by-side comparison of EEXIST and ENOTDIR — understand the differences, causes, and fixes.
EEXISTA file creation operation failed because a file with the specified name already exists.
An operation requiring that a file not exist was attempted on an existing file. This occurs with O_CREAT | O_EXCL flags in open(), when calling mkdir() on an existing directory, or creating a symlink where one already exists.
Check if the file exists before creating it. Use O_CREAT without O_EXCL if overwriting is acceptable. Remove the existing file first if appropriate.
ENOTDIRA component used as a directory in a pathname is not actually a directory.
A path component that should be a directory is actually a regular file or other non-directory type. For example, if /tmp/file is a regular file, accessing /tmp/file/something triggers this error.
Verify the path with ls -la to ensure all components are directories. Rename or remove the conflicting file. Check for symlinks that resolve to non-directory targets.