#2350 (MoveFile does not report failure when the target exists => Fixed in 2.0.4) – Oracle VirtualBox (original) (raw)
#2350 closed defect (fixed)
Reported by: | Owned by: | ||
---|---|---|---|
Component: | shared folders | Version: | VirtualBox 2.0.2 |
Keywords: | git lock rename | Cc: | |
Guest type: | Windows | Host type: | other |
As described in MSDN, MoveFile should fail if the target file exists.
However, when the files are located in a shared folder, it apparently returns success without actually doing anything. It makes using msysgit with repositories located on shared folders impossible, except in read-only mode.
Steps to reproduce with msysgit:
- Install MSysGit
- Create a shared folder and map it to a drive letter
- Try to create a repository on that drive, i.e. mkdir test; cd test; git init (You'll have to enable the "use from windows command prompt" option in the installer)
It'll output a bunch of errors, and leave a .../.git/config.lock file:
error: could not lock config file E:/Work/test/.git/config error: could not lock config file E:/Work/test/.git/config error: could not lock config file E:/Work/test/.git/config error: could not lock config file E:/Work/test/.git/config
Workaround: if I make it ignore the result of rename(), and try MoveFileEx anyway, it works properly:
--- a/compat/mingw.c +++ b/compat/mingw.c @@ -869,11 +869,12 @@ int mingw_rename(const char *pold, const char *pnew) * Try native rename() first to get errno right. * It is based on MoveFile(), which cannot overwrite existing files. */
int ok = 0; if (!rename(pold, pnew))
return 0;
if (errno != EEXIST)
ok++;
if (!ok && errno != EEXIST) return -1;
if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING))
if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING) || ok) return 0; /* TODO: translate more errors */ if (GetLastError() == ERROR_ACCESS_DENIED) {
Guest: Windows 2000 & XP, Host: Fedora 9