1

I used some filesystem changing notify lib to watch the directory /asdf, and inside the asdf, I vim tmp, and made some changes and then use :wq to save the file

then I got this output:

/asdf/4913 at watch.pl line 9.
/asdf/4913 at watch.pl line 9.
/asdf/tmp at watch.pl line 9.
/asdf/tmp at watch.pl line 9.
/asdf/tmp at watch.pl line 9.
/asdf/tmp~ at watch.pl line 9.
/asdf/tmp~ at watch.pl line 9.

what is 4913 file? what is tmp~ file? what exactly happens after :wq ?

Sato
  • 8,192
  • 17
  • 60
  • 115

1 Answers1

1

From https://github.com/neovim/neovim/issues/3460

An interesting case was mentioned: Neo/Vim creates a temporary file to check if a directory is writable and see the resulting ACL.

So, if you’re writing software that watches for file changes, you’ll find Vim creates and deletes file 4913 on almost every edit. ref

Additional details https://groups.google.com/forum/#!topic/vim_dev/sppdpElxY44
https://vi.stackexchange.com/questions/4038/why-does-set-nocompatible-result-in-vim-saving-extra-all-numeric-temporary-fi

Here's the code that's causing this

/*
 * Check if we can create a file and set the owner/group to
 * the ones from the original file.
 * First find a file name that doesn't exist yet (use some
 * arbitrary numbers).
 */
STRCPY(IObuff, fname);
for (i = 4913; ; i += 123)
{
    sprintf((char *)gettail(IObuff), "%d", i);
    if (mch_lstat((char *)IObuff, &st) < 0)
        break;
}
fd = mch_open((char *)IObuff,
                O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
if (fd < 0)     /* can't write in directory */
    backup_copy = TRUE;
else
{

    ignored = fchown(fd, st_old.st_uid, st_old.st_gid);
    if (mch_stat((char *)IObuff, &st) < 0
        || st.st_uid != st_old.st_uid
        || st.st_gid != st_old.st_gid
        || (long)st.st_mode != perm)
    backup_copy = TRUE;
    /* Close the file before removing it, on MS-Windows we
     * can't delete an open file. */
    close(fd);
    mch_remove(IObuff);
Community
  • 1
  • 1
sudo bangbang
  • 27,127
  • 11
  • 75
  • 77