@@ -32,6 +32,13 @@ function! xolox#misc#perm#update(fname, contents)
3232 " The second argument is the list of lines to be written to the file. Writes
3333 " the new contents to a temporary file and renames the temporary file into
3434 " place, thereby preventing readers from reading a partially written file.
35+ " Returns 1 if the file is successfully updated, 0 otherwise.
36+ "
37+ " Note that if `xolox#misc#perm#get()` and `xolox#misc#perm#set()` cannot be
38+ " used to preserve the file owner/group/mode the file is still updated using
39+ " a rename (for compatibility with non-UNIX systems and incompatible
40+ " `/usr/bin/stat` implementations) so in that case you can still lose the
41+ " file's owner/group/mode.
3542 let starttime = xolox#misc#timer#start ()
3643 let temporary_file = printf (' %s.tmp' , a: fname )
3744 call xolox#misc#msg#debug (" vim-misc %s: Writing new contents of %s to temporary file %s .." , g: xolox #misc#version , a: fname , temporary_file)
@@ -56,7 +63,7 @@ function! xolox#misc#perm#get(fname)
5663 let pathname = xolox#misc#path#absolute (a: fname )
5764 if filereadable (pathname)
5865 let command = printf (' stat --format %s %s' , ' %U:%G:%a' , shellescape (pathname))
59- let result = xolox#misc#os#exec ({' command' : command })
66+ let result = xolox#misc#os#exec ({' command' : command , ' check ' : 0 })
6067 if result[' exit_code' ] == 0 && len (result[' stdout' ]) >= 1
6168 let tokens = split (result[' stdout' ][0 ], ' :' )
6269 if len (tokens) == 3
@@ -88,6 +95,6 @@ endfunction
8895function ! s: run (command , ... )
8996 let args = map (copy (a: 000 ), ' shellescape(v:val)' )
9097 call insert (args , a: command , 0 )
91- let result = xolox#misc#os#exec ({' command' : call (' printf' , args )})
98+ let result = xolox#misc#os#exec ({' command' : call (' printf' , args ), ' check ' : 0 })
9299 return result[' exit_code' ] == 0
93100endfunction
0 commit comments