emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.92k stars 3.32k forks source link

When opening broken symlink with O_CREAT, create file at target #23002

Open hoodmane opened 1 week ago

hoodmane commented 1 week ago

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 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.

hoodmane commented 1 week ago

Oh this is not the right behavior yet. We should create the target file I guess.