To fix the problem, I added an extra handleBrokenLink option to lookupPath. When this option is passed, if the input path is a broken symlink, instead of raising EEXIST, it returns { path: theTarget, node: undefined}. Then in open we update path based on the returned path, so if the node doesn't exist we attempt create it at the resolved target path of the symlink rather than trying to create it on the source of the symlink which raises EEXIST again.
If we open a broken symlink with
O_CREAT
we should create a new file as the target of the symlink. This resolves https://github.com/emscripten-core/emscripten/issues/23001.To fix the problem, I added an extra
handleBrokenLink
option tolookupPath
. When this option is passed, if the input path is a broken symlink, instead of raisingEEXIST
, it returns{ path: theTarget, node: undefined}
. Then inopen
we updatepath
based on the returned path, so if the node doesn't exist we attempt create it at the resolved target path of the symlink rather than trying to create it on the source of the symlink which raisesEEXIST
again.