[vim/vim] [Win] Cannot open undo file for file from mapped network drive (#6459)

22 views
Skip to first unread message

Kevin Locke

unread,
Jul 15, 2020, 12:16:16 PM7/15/20
to vim/vim, Subscribed

Describe the bug
In Windows, with undofile enabled and undodir set to a local directory, saving a file on a mapped network drive which is not world-readable results in E828: Cannot open undo file for writing: ...

To Reproduce
Detailed steps to reproduce the behavior:

  1. On computer1, create a SMB/CIFS share containing a text file which is not world-readable:
    mkdir /tmp/myshare
    (umask 027 && touch /tmp/myshare/example.txt)
    echo '
    [MyShare]
      path = /tmp/myshare
      writeable = yes' >>/etc/samba/smb.conf
    killall -HUP smbd
    Note: Whether the share requires a password doesn't appear to matter. However, I suspect the share must not be on a computer on the same domain (where the SID of the current user would have permissions defined on the file).
  2. On computer2, map the share as a network drive:
    net use S: \\computer1\MyShare
  3. On computer2, edit the file using Vim with undofile and local undodir:
    vim -u NONE -c "set undofile | set undodir=%TEMP%" S:\example.txt
  4. Edit and save the file twice. i1<Esc>:w<CR>i2<Esc>:w<CR>

On the second save, E828: Cannot open undo file for writing: C:\Users\User\AppData\Local\Temp\S%%example.txt will be produced.

Expected behavior
Undo would work as expected and no error would be produced.

Environment (please complete the following information):

  • Vim version 8.2.1206
  • OS: Windows 10 2004

Additional context

icacls "%TEMP%\S%%example.txt" prints

C:\Users\User\AppData\Local\Temp\S%%example.txt S-1-5-21-189028407-2721759871-347389160-1000:(R,W)
                                                S-1-22-2-1000:(R)

Which indicates that the undo file has permissions for the SID on the share and is not inheriting permissions from the parent directory, which means that the SID for the current user does not have read/write permission on the undo file.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

zivvel

unread,
Apr 10, 2024, 9:43:56 AM4/10/24
to vim/vim, Subscribed

Issue persists in VIM 9.1 on Windows 11 23H2.
Is there any workaround? This is a consistent annoyance.


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/2047583720@github.com>

Christian Brabandt

unread,
Apr 10, 2024, 9:49:08 AM4/10/24
to vim/vim, Subscribed

set undodir?


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/2047600295@github.com>

Kevin Locke

unread,
Apr 10, 2024, 9:54:14 AM4/10/24
to vim/vim, Subscribed

The error occurs when undodir is set.


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/2047613357@github.com>

Christian Brabandt

unread,
Apr 10, 2024, 9:56:19 AM4/10/24
to vim/vim, Subscribed

yes what I meant: so set it to a non network share


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/2047619029@github.com>

Kevin Locke

unread,
Apr 10, 2024, 9:57:44 AM4/10/24
to vim/vim, Subscribed

Yes, as I explained in the bug description, the issue occurs when undodir is set to a local directory (%TEMP% in the reproduction steps)

In Windows, with undofile enabled and undodir set to a local directory


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/2047622671@github.com>

Christian Brabandt

unread,
Apr 10, 2024, 10:00:38 AM4/10/24
to vim/vim, Subscribed

yes, the issue is with the permissions (different ownership). This is currently not supported. Vim verifies that the undofile is from the same user account.


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/2047630682@github.com>

Kevin Locke

unread,
Apr 10, 2024, 10:03:54 AM4/10/24
to vim/vim, Subscribed

Vim verifies that the undofile is from the same user account.

Can you elaborate? Are you saying that Vim creates the undofile with the SID of the original file, rather than the current user, then complains that the undofile is not the user SID when it writes it a second time?


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/2047639113@github.com>

zivvel

unread,
Apr 10, 2024, 10:33:31 AM4/10/24
to vim/vim, Subscribed

(This issue did not exist in VIM 8.1)
I own the network-shared file Z:\file.txt (owner is SERVER\me)
I also own the local undo file C:\undodir\Z%%file.txt (owner is WORKSTATION\me)


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/2047720257@github.com>

gh-log

unread,
Nov 20, 2024, 6:16:17 PM11/20/24
to vim/vim, Subscribed

This is driving me crazy!

I need to edit files in samba share and undo dir is in my local Windows NTFS. I also edit local files so need undo dir in local drive.

I can edit undo files permissions to be writable, gvim can save the undo file changes once but changes the file permissions, so fails second time. This is weird.

undo file permissions should 1. not be changed once the file exists, 2. inherited from undo folder or gvim user, not from source file permissions.

Whats worse is that the original file in the smb share is editable by gvim!

This is a bug.


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/2489728255@github.com>

zivvel

unread,
Jul 16, 2026, 5:04:31 PM (12 hours ago) Jul 16
to vim/vim, Subscribed
zivvel left a comment (vim/vim#6459)

Still a bug in 9.2. I now work around this by checking whether expand(':p') is on a network-mapped drive and resetting undodir to a network folder in function called by "au BufEnter * ...". I'm sure there's a better way, but this is working for me. Feels yucky though.

if exists('$HOME') && expand($HOME) =~ '^[FZ]:' && isdirectory(expand($HOME))
	let s:udir = expand($HOME . '.vim_undo')
endif
function! SetUndoDir()
	if has('persistent_undo')
		if expand('<afile>:p') =~ '^[F-Z]:'
			if exists('s:udir')
				let &undodir = s:udir
			else
				set undodir=.
			endif
		else
			let &undodir = s:local_udir
		endif
		set undofile
	endif
endfunc
au BufEnter	*	call SetUndoDir()


Reply to this email directly, view it on GitHub, or unsubscribe.

Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/6459/4996567118@github.com>

Reply all
Reply to author
Forward
0 new messages