Issue with cp when copying exe files in Msys2 or Git Bash in Windows

73 views Asked by At

I came across a weird issue with cp in Git Bash, and same for Msys2 shell. When copying an exe file (e.g., some-file.exe) along with a file with the same name but no extension (e.g., some-file), it will only copy some-file but as the name some-file.exe. Here are the steps to reproduce.

mkdir a-new-tmp-folder
cd a-new-tmp-folder
mkdir tmp
echo "file" >file
echo "file.exe" >file.exe
cp -t tmp file.exe file
ls tmp              # only `file.exe' there
cat tmp/file.exe    # shows `file' instead of expected `file.exe'

However, if swap the last 2 arguments of cp (cp -t tmp file file.exe), there won't be any issue. Could anyone please help explain?

1

There are 1 answers

0
lxvs On

As mentioned in Msys2 todo list, this is a known issue because the runtime emulates extension-less executables by also looking for .exe on various FS calls.

It seems that there is currently no solution or workaround for this issue.

Fix pacman errors wrt. conflicts in bin/foo vs bin/foo.exe

The runtime emulates extension-less executables by also looking for .exe on various FS calls. (There are more of these hacks, for example for symlink emulation.) This is causing pacman to complain when two packages independently provide both foo and foo.exe, or even worse dir/ and dir.exe. People have to either disregard these conflicts with --force or (re-)install packages in a specific order.

A possible solution to these conflicts would be to disable the .exe interpolation, but then something would break, either users wouldn't be able to either run MSYS2 executables directly from Windows, or couldn't use the short extension-less names of commands in MSYS2.