Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"File exists" error on Windows #5443

Open
kit-ty-kate opened this issue Feb 13, 2023 · 4 comments
Open

"File exists" error on Windows #5443

kit-ty-kate opened this issue Feb 13, 2023 · 4 comments

Comments

@kit-ty-kate
Copy link
Member

kit-ty-kate commented Feb 13, 2023

Happened twice today in two different PRs

#=== ERROR while fetching sources for dune.3.6.1 and dune-configurator.3.6.1 ==#
OpamSolution.Fetch_fail("Failed to copy source of:\n  - dune.3.6.1: \"D:\\\\cygwin\\\\bin\\\\cp.exe -PRp C:\\\\Users\\\\runneradmin\\\\AppData\\\\Local\\\\Temp\\\\opam-6696-56db09 D:\\\\a\\\\opam\\\\opam\\\\.opam\\\\default\\\\.opam-switch\\\\sources\\\\dune.3.6.1\" exited with code 1 \"/usr/bin/cp: cannot create regular file 'D:\\a\\opam\\opam\\.opam\\default\\.opam-switch\\sources\\dune.3.6.1/dune': File exists\"\n  - dune-configurator.3.6.1: \"D:\\\\cygwin\\\\bin\\\\cp.exe -PRp C:\\\\Users\\\\runneradmin\\\\AppData\\\\Local\\\\Temp\\\\opam-6696-56db09 D:\\\\a\\\\opam\\\\opam\\\\.opam\\\\default\\\\.opam-switch\\\\sources\\\\dune-configurator.3.6.1\" exited with code 1 \"/usr/bin/cp: cannot create regular file 'D:\\a\\opam\\opam\\.opam\\default\\.opam-switch\\sources\\dune-configurator.3.6.1/dune': File exists\"\n")

Full logs:

@dra27
Copy link
Member

dra27 commented Feb 21, 2023

Expanding some of the escaping in the error:

#=== ERROR while fetching sources for dune.3.6.1 and dune-configurator.3.6.1 ==#
Failed to copy source of:
  - dune.3.6.1:
      "D:\cygwin\bin\cp.exe -PRp C:\Users\runneradmin\AppData\Local\Temp\opam-6696-56db09 D:\a\opam\opam\.opam\default\.opam-switch\sources\dune.3.6.1"
        exited with code 1 "/usr/bin/cp: cannot create regular file 'D:\\a\\opam\\opam\\.opam\\default\\.opam-switch\\sources\\dune.3.6.1/dune': File exists"
  - dune-configurator.3.6.1:
      "D:\cygwin\bin\cp.exe -PRp C:\Users\runneradmin\AppData\Local\Temp\opam-6696-56db09 D:\a\opam\opam\.opam\default\.opam-switch\sources\dune-configurator.3.6.1"
        exited with code 1 "/usr/bin/cp: cannot create regular file 'D:\\a\\opam\\opam\\.opam\\default\\.opam-switch\\sources\\dune-configurator.3.6.1/dune': File exists"

@dra27
Copy link
Member

dra27 commented Feb 21, 2023

(just noting that the issue isn't necessarily repeating)

@jonahbeckford
Copy link
Contributor

jonahbeckford commented Feb 21, 2023

I've seen this problem before. I thought it was limited to MSYS2 not Cygwin because it is related to symlink copying. Let me see if I can scrounge for references:

The last reference gives a detailed description of what is happening and why it is indeterminate.

@db4
Copy link

db4 commented Jun 6, 2023

In the case of Cygwin, I think I can explain what's going on. The problematic packages contain both dune and dune.exe files in the same directory, but Cygwin treats dune.exe as dune in some situations:

Cygwin always handled the .exe suffix transparently in terms of stat(2) calls, but Cygwin 1.7 also handles them transparently in terms of open(2) and any other call. Therefore, if a file foo.exe exists, and an application calls stat("foo"), it will get told that, yes, "foo" exists. That's a basic component of being able to call foo.exe from bash by just typing foo. POSIX systems just don't have the .exe suffix for executables.

(found in https://stackoverflow.com/questions/58048185/cygwin-cp-cant-copy-file-abc-because-destination-dir-contains-file-abc-exe)

That also explains why it works sometimes. If you copy a file with no extension first, you are lucky:

cp src/dune dst/dune
cp src/dune.exe dst/dune.exe
(OK)

But if you do the opposite, you are in trouble:

cp src/dune.exe dst/dune.exe
cp src/dune dst/dune
/usr/bin/cp: cannot create regular file 'dst/dune': File exists

This issue has effectively ruined my Windows build after upgrading some packages. How to fix it? I don't know. Never use dune and dune.exe together`?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants