<#18809 `IntrinsicError: File exists (os error 17)...
# github-notifications
c
#18809 `IntrinsicError: File exists (os error 17)` when attempting to overwrite a symlink in `dist/` Issue created by huonw Describe the bug If `pants export-codegen ...`'s is run on a target where the output includes a symlink, the second attempt to write that to
dist/codegen
fails with
IntrinsicError: File exists (os error 17)
, potentially being unable to overwrite the symlink. I'm guessing this applies to more than just
export-codegen
and
shell_command
, but that and
shell_command
are the easiest way I know to repeatedly attempt to write a symlink to a single path. Reproducer:
Copy code
cd $(mktemp -d)

cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.16.0rc1"
backend_packages = ["pants.backend.shell"]

[anonymous-telemetry]
enabled = false
EOF

cat > BUILD <<EOF
shell_command(
    name="symlink",
    command="ln -s whatever.txt link.txt",
    tools=["ln"],
    output_files=["link.txt"],
)

shell_command(
    name="normal",
    command="touch file.txt",
    tools=["touch"],
    output_files=["file.txt"],
)
EOF

pants export-codegen :symlink
# OK: ... Writing generated files to dist/codegen

pants export-codegen :symlink
# BUG: ... IntrinsicError: File exists (os error 17)

# delete the existing symlink, and try again:
rm dist/codegen/link.txt
pants export-codegen :symlink
# OK: ... Writing generated files to dist/codegen

# non-link works fine, for comparison:
pants export-codegen :normal
# OK: ... Writing generated files to dist/codegen

pants export-codegen :normal
# OK: ... Writing generated files to dist/codegen
All of the `export-codegen`s work, except for the
BUG
one:
Copy code
16:42:31.28 [INFO] Writing generated files to dist/codegen
16:42:31.28 [ERROR] 1 Exception encountered:

Engine traceback:
  in `export-codegen` goal

IntrinsicError: File exists (os error 17)
Pants version 2.16.0rc1 OS macOS Additional info #17758 is mildly related, since both that and this are pants failing to correctly update the contents of
dist/
. pantsbuild/pants