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

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

Closed
ronin13 opened this issue Jan 3, 2012 · 10 comments
Closed

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

ronin13 opened this issue Jan 3, 2012 · 10 comments

Comments

@ronin13
Copy link

ronin13 commented Jan 3, 2012

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
Copy link
Author

ronin13 commented Jan 3, 2012

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
Copy link
Owner

chrisbra commented Jan 4, 2012

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

I can't reproduce the issue currently.

@ronin13
Copy link
Author

ronin13 commented Jan 6, 2012

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
Copy link
Owner

chrisbra commented Jan 6, 2012

Hi Raghavendra!

On Fr, 06 Jan 2012, Raghavendra D Prabhu wrote:

I am writing the file with regular :w

Shouldn't this autocmd -- au BufWriteCmd,FileWriteCmd sudo:/,sudo: SudoWrite -- 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)

Is there a reason, you need to do the :doautocmd instead of simply using
:SudoWrite?

regards,
Christian

@ronin13
Copy link
Author

ronin13 commented Jan 6, 2012

Hi,

  • On Fri, Jan 06, 2012 at 06:05:50AM -0800, chrisbra reply@reply.github.com wrote:

    Hi Raghavendra!

    On Fr, 06 Jan 2012, Raghavendra D Prabhu wrote:

    I am writing the file with regular :w

Shouldn't this autocmd -- au BufWriteCmd,FileWriteCmd sudo:/,sudo: SudoWrite -- 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)

Is there a reason, you need to do the :doautocmd instead of simply using
:SudoWrite?

Yes, I did doautocmd to test the autocmd functionality (which is
the main issue of this bug).

I will investigate more and let you know. Also, I tested this
latest vim built from git and it is same.

regards,
Christian


Reply to this email directly or view it on GitHub:
#10 (comment)


Raghavendra Prabhu
GPG Id : 0xD72BE977
Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977
www: wnohang.net

@chrisbra
Copy link
Owner

chrisbra commented Jan 9, 2012

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
Copy link
Author

ronin13 commented Jan 9, 2012

Hi,

  • On Mon, Jan 09, 2012 at 02:19:29PM -0800, chrisbra reply@reply.github.com wrote:

    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.


    Reply to this email directly or view it on GitHub:
    Write with sudo not taking place with sudo:* #10 (comment)

Thanks for looking into it and fixing it. I will pull, test it and let

you know.

Raghavendra Prabhu
GPG Id : 0xD72BE977
Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977
www: wnohang.net

@ronin13
Copy link
Author

ronin13 commented Jan 13, 2012

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
Copy link
Owner

Thanks, I commit your patch

@chrisbra
Copy link
Owner

closing

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