As a quick Google would tell you, Vim creates this file in an attempt to
verify it can create a file in the directory in which you see the file
and set the uid/gid. It's just a temporary file used during the process
of creating a backup file.
--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <jame...@debian.org>
Here's the code:
3486 for (i = 4913; ; i += 123)
3487 {
3488 sprintf((char *)gettail(IObuff), "%d", i);
3489 if (mch_lstat((char *)IObuff, &st) < 0)
3490 break;
3491 }
3492 fd = mch_open((char *)IObuff,
3493
O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
3494 if (fd < 0) /* can't write in directory */
3495 backup_copy = TRUE;
3496 else
3497 {
3498 # ifdef UNIX
3499 # ifdef HAVE_FCHOWN
3500 ignored = fchown(fd, st_old.st_uid, st_old.st_gid);
3501 # endif
3502 if (mch_stat((char *)IObuff, &st) < 0
3503 || st.st_uid != st_old.st_uid
3504 || st.st_gid != st_old.st_gid
3505 || (long)st.st_mode != perm)
3506 backup_copy = TRUE;
3507 # endif
3508 /* Close the file before removing it, on MS-Windows we
3509 * can't delete an open file. */
3510 close(fd);
3511 mch_remove(IObuff);
3512 }
If mch_open (line 3492) returns a file descriptor, then we get into
the following else which always calls mch_remove on the file (line
3511). So, Vim is removing the file but your filesystem isn't
properly handling that.
Arve:
To confirm, are you seeing this on a local filesystem (you say "plain old NTFS"), or is there a remote filesystem involved? Do you only see this with the 64-bit build of Vim, or 32-bit as well? Can you provide the simplest possible .vimrc and steps to repro the problem? I'm interested in investigating this. We can take this to private e-mail if that would be better, to not flood the mailing list.
Craig
Ben Fritz <f...@gmail.com> skribis:
I think exactly the same... Googling for the problem will find this
thread, so it's better if the solution is in the thread, too.
--
Raúl "DervishD" Núñez de Arenas Coronado
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!
The guidelines for the list may be found at:
http://groups.google.com/group/vim_use/web/vim-information
I have a 64-bit Vista system; haven't noticed any 4913s hanging around it.
* what o/s? (windows, but is it WInXP, Vista, 7?)
* using vim or gvim?
* compiled for native windows, cygwin, or what?
* vim version
* what compiler/linker did you use? or did you get a pre-compiled one
from somewhere?
Answers to these Qs will, I'd imagine, help someone with a similar setup
to attempt to duplicate your problem.
Regards,
Chip Campbell
Isn't it a caching problem? I can imagine that when you look at the
file system at the right moment the file is there. If this view isn't
updated for a little while you see the file, even though Vim has already
deleted it.
It's hard to imagine the file is properly deleted one moment and hangs
around another time. Either something essential changed or it's flaky.
--
"It's so simple to be wise. Just think of something stupid to say
and then don't say it." -- Sam Levenson
/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Although I have not been able to repro this myself, I have a theory, which is supported empirically by Arve. Consider:
3508 /* Close the file before removing it, on MS-Windows we
3509 * can't delete an open file. */
3510 close(fd);
3511 mch_remove(IObuff);
There's a race condition between lines 3510 and 3511, wherein another process could open a handle to the file and thus prevent the delete from succeeding. One class of software that is known to do this and cause problems is antivirus programs, which want to scan things for viruses as soon as they are created. Another class of software that sometimes causes problems is local search programs, which want to index things as soon as they are created. Such software can do their tasks unobtrusively if they are written carefully and using the mechanisms provided by the operating system, namely oplocks. Unfortunately there are lots of bad virus scanners and indexers out there (lots of bad software in general!).
One solution which is very commonly used in Windows programs is to detect when a delete or rename operation fails (can be narrowed to specific error codes -- sharing violation and access denied), and retry a couple times with short delays in between. The idea is to give the interfering process some time to finish whatever work it was doing with the file. I've had to write such code before. I realize it is ugly, but it works well in practice. It works best with small files. How many people out there have tried to delete a large hierarchy of files using "rd /s /q", and had it inexplicably fail to delete a few files? Yet if you repeat the command it will generally succeed. Most likely a virus scanner or search indexer got in the way and is now out of the way.
Another solution, which is cleaner but can only be used in cases where you know you want to delete a file immediately after closing its handle, is to set the delete disposition on the file before closing the handle. There are a couple of ways using Windows APIs to do this. One way is to pass FILE_FLAG_DELETE_ON_CLOSE to CreateFile() when opening the handle originally. Another way is to send down a FileDispositionInfo using SetFileInformationByHandle() or equivalent. (Essentially the DeleteFile() API just does the following: open a handle, set delete disposition, and close the handle; if we break apart these steps, we gain finer control.)
I suggest a TODO item around more reliable delete/rename on Windows. I can work on it at some point.
Craig