[vim/vim] With directory option, vim -r misreports original file name (#8812)

29 views
Skip to first unread message

Keith Thompson

unread,
Aug 29, 2021, 12:08:58 AM8/29/21
to vim/vim, Subscribed

Describe the bug
With the directory option set to specify a directory to hold vim swap files, vim -r in a different directory misreports the original file name

To Reproduce

$ mkdir ~/vimswap ~/FOO ~/BAR
$ echo 'set directory=~/vimswap' > ~/.vimrc.test
$ echo 'This is FOO/tmp' > ~/FOO/tmp
$ cd FOO
$ vim -u ~/.vimrc.test tmp

(suspend with Ctrl-Z)

$ cd ~/BAR
$ vim -u ~/.vimrc.test -r tmp

Error message:

Using swap file "~/vimswap/tmp.swp"
Original file "~/BAR/tmp"
"~/BAR/tmp" [New File]
E309: Unable to read block 1 from /home/kst/vimswap/tmp.swp
Press ENTER or type command to continue

Expected behavior
The reported file name should be ~/FOO/tmp, not ~/BAR/tmp.

Note that the swap file does contain the correct information

Environment:

  • Vim version 8.2.3326 (also exists in earlier versions)
  • OS: Ubuntu 21.04
  • Terminal: xterm (though I don't think that matters).


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Bram Moolenaar

unread,
Aug 29, 2021, 3:10:14 PM8/29/21
to vim/vim, Subscribed

You apparently suspended the first Vim instance before it could write to the swap file. If you wait a bit, or use :preserve, then the recovery will actually work. But you get the contents of ~/FOO/tmp in ~/BAR/tmp. That is because the file name is not checked, it could be a symbolic link to the same file.

Although it's a bit strange, I don't see how this can be avoided without breaking something else (editing a file via a symlink).

Gary Johnson

unread,
Aug 29, 2021, 3:22:35 PM8/29/21
to reply+ACY5DGEGYITP6LGUJY...@reply.github.com, vim...@googlegroups.com
On 2021-08-29, Bram Moolenaar wrote:

> Although it's a bit strange, I don't see how this can be avoided without
> breaking something else (editing a file via a symlink).

Wouldn't adding "//" to the end of the directory name fix the
problem? E.g.,

:set directory=~/vimswap//

See

:help 'directory'

Regards,
Gary

vim-dev ML

unread,
Aug 29, 2021, 3:22:55 PM8/29/21
to vim/vim, vim-dev ML, Your activity
Reply all
Reply to author
Forward
0 new messages