Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Write with sudo not taking place with sudo:* #10

Closed
ronin13 opened this Issue · 10 comments

2 participants

@ronin13

http://sprunge.us/IIDa is the output of :verbose autocmd BufWriteCmd

http://sprunge.us/jccZ is the output of :verbose autocmd FileWriteCmd

For instance for

vim sudo:/etc/rc.conf

while writing I get

File permissions of "rc.conf" are read-only.                                                                                                                                                                                                                                      
It may still be possible to write it.                                                                                                                                                                                                                                             
Do you wish to try?                                                                                                                                                                                                                                                               
(Y)es, [N]o:   
@ronin13
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Dec 27 2011 13:54:40)
Included patches: 1-386
Compiled by Raghu
Big version without GUI.  Features included (+) or not (-):
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent 
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments 
+conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs 
-dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path 
+find_in_path +float +folding -footer +fork() -gettext -hangul_input +iconv 
+insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent 
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape 
+mouse_dec -mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse 
+mouse_xterm +mouse_urxvt +multi_byte +multi_lang -mzscheme -netbeans_intg 
+path_extra +perl +persistent_undo +postscript +printer -profile +python 
-python3 +quickfix +reltime +rightleft -ruby +scrollbind +signs +smartindent 
-sniff +startuptime +statusline -sun_workshop +syntax +tag_binary 
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
 -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo 
+vreplace +wildignore +wildmenu +windows +writebackup +X11 +xfontset -xim -xsmp
 +xterm_clipboard -xterm_save 
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -I/usr/local/include  -O2 -march=native -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-E  -Wl,--hash-style=gnu -Wl,--as-needed -s  -L/usr/local/lib -Wl,--as-needed -o vim    -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -lncurses -lelf   -ldl    -Wl,-E -Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu -fstack-protector -L/usr/local/lib  -L/usr/lib/perl5/core_perl/CORE -lperl -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic      
@chrisbra
Owner

How do you write the file? What are the permissions of the file?

I can't reproduce the issue currently.

@ronin13

I am writing the file with regular :w

Shouldn't this autocmd --

au BufWriteCmd,FileWriteCmd sudo:/*,sudo:* SudoWrite <afile>   

-- being working ?

However, when I do :doautocmd Sudo FileWriteCmd

it says 'no matching autocommands'

Interestingly, SudoRead autocmd seems to be working fine (tested on a 0600 file)

Also, manually calling SudoWrite works but autocmd is the issue.

It looks like vim doesn't apply sudo:* match for the write autocmd

@chrisbra
Owner
@ronin13
@chrisbra
Owner

ok, this happens, because the plugin removes the sudo:// protocoll handler when reading files. Therefore the pattern from the autocommand does not match anymore and writing won't happen. However, the last commit I pushed, should make it possible.

@ronin13
@ronin13

I pulled and used it, however it was still failing for me in something like -- vim sudo:/etc/wgetrc (full path)

Then I noticed that code is looking for sudo:// whereas the autocmd is looking for sudo:/* and sudo:*

So I modified the code to following and it works fine for me now:

 diff --git a/autoload/SudoEdit.vim b/autoload/SudoEdit.vim
 index a4e157c..216fcfa 100644
 --- a/autoload/SudoEdit.vim
 +++ b/autoload/SudoEdit.vim
 @@ -64,7 +64,7 @@ fu! SudoEdit#LocalSettings(setflag, readflag) "{{{2
         if has("persistent_undo") && !empty(@%) && !<sid>CheckNetrwFile(@%)
             " Force reading in the buffer
             " to avoid stupid W13 warning
 -           let file=substitute(expand("%"), '^sudo://', '', '')
 +           let file=substitute(expand("%"), '^sudo:', '', '')
             if !a:readflag
                 sil call SudoEdit#SudoRead(file)
                 exe "sil wundo!" fnameescape(undofile(file))
 @@ -168,7 +168,7 @@ fu! SudoEdit#SudoDo(readflag, file) range "{{{2
      let file = a:file
      if file =~ '^sudo:'
         let s:use_sudo_protocol_handler = 1
 -       let file = substitute(file, '^sudo://', '', '')
 +       let file = substitute(file, '^sudo:', '', '')
      endif
      let file = empty(a:file) ? expand("%") : file
      "let file = !empty(a:file) ? substitute(a:file, '^sudo:', '', '') : expand("%")
 @@ -194,8 +194,8 @@ fu! SudoEdit#SudoDo(readflag, file) range "{{{2
         endtry
      endif
      call SudoEdit#LocalSettings(0, a:readflag)
 -    if file !~ 'sudo://' && s:use_sudo_protocol_handler
 -       let file = 'sudo://' . fnamemodify(file, ':p')
 +    if file !~ 'sudo:' && s:use_sudo_protocol_handler
 +       let file = 'sudo:' . fnamemodify(file, ':p')
      endif
      exe ':sil f ' . file
      if v:shell_error
@chrisbra
Owner

Thanks, I commit your patch

@chrisbra
Owner

closing

@chrisbra chrisbra closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.