Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't exit vim editing file with no write access for user #260

Open
Praful opened this issue May 3, 2022 · 5 comments
Open

Can't exit vim editing file with no write access for user #260

Praful opened this issue May 3, 2022 · 5 comments

Comments

@Praful
Copy link

Praful commented May 3, 2022

I'm not sure whether to log this with Vim or here.

I am logged in as UserA and have read-only access to a folder that is owned by Administrator. If I open a file in gvim, I can edit it. However, when I try to save it, the following message appears:

File permissions of [filename] are read-only. It may still be possible to write it. Do you wish to try?

The options are Yes or No. Whichever I choose, I get asked again. The only way to exit this infinite loop is to kill the gvim process from Task Manager or equivalent.

@chrisbra
Copy link
Member

chrisbra commented May 3, 2022

so this happens also with gvim --clean? I have never noticed that

@chrisbra
Copy link
Member

chrisbra commented May 3, 2022

Hm, if I try this here, I get:

E45: 'readonly' option is set (add ! to override)

if I then try using :w! I get:

E212: can't open file for writing

But I never get that prompt. Hm, perhaps the 'backupcopy' could make difference?

Are those file permissions for that file special?

Note: already when opening, I see an indicator [readonly] in the status bar.

@Praful
Copy link
Author

Praful commented May 3, 2022

There are NTFS permissions set on the folder, which the files in it inherit. This is different from setting the read-only attribute on the file. The administrator has "full control" NTFS permission and UserA has "read-only" NTFS permission. To set the NTFS permission, I right-click folder in File Explorer > Properties > Security tab > set permissions.

The read-only attribute has not been set.

I do have the backup files option enabled in vim. I'll try in gvim clean mode tomorrow when I'm by PC.

@Praful
Copy link
Author

Praful commented May 4, 2022

I ran gvim --clean and the problem went away. I noticed that no dialog box appeared. I tried with a minimal vimrc, adding set confirm and the dialog box appears but the problem doesn't ie the dialog appears once then not again after I click 'No'.

Then I tried gvim --noplugin ie with my vimrc and the problem didn't appear. So it looks like a plugin is causing the issue.

For backup, swap and undo directories, I set directory, backupdir, and undodir to a directory that UserA has write access to.

I will investigate further and see if I can narrow down the issue.

@Praful
Copy link
Author

Praful commented May 4, 2022

I've narrowed it down to the following minimalist vimrc:

set confirm
if has("autocmd")
  augroup PK2
    autocmd!
    autocmd BufLeave,FocusLost * silent! wall
  augroup END
endif 

The culprit seems to be set confirm. If that's commented out, there is no infinite prompting to save a file.

Steps to reproduce:

  1. Save above in c:\temp\vimrc
  2. cd c:\temp
  3. create a file test.txt
  4. make file read-only: attrib +r test.txt
  5. run: gvim --clean .\test.txt -u c:\temp\vimrc
  6. edit test.txt
  7. save it: :w

The attempt to save test.txt will result in a dialog box repeatedly appearing.

In the above example, I'm using the read-only attribute but the same happens with NTFS permissions.

Obviously this is not a big issue since I can comment out the focuslost command or the set confirm command to work around the issue.

Edit: my guess is that the appearance of a Windows dialog box, even if it's created by vim causes a FocusLost event, which results in the confirm kicking in, which shows the dialog box, which, and so on. Is the answer not to treat vim-generated dialog boxes as a loss of focus?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants