Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug fix: Don't raise exception if /usr/bin/stat doesn't work

  • Loading branch information...
commit 9d1f006e53dcce4ff9eb9e2ed5fff0115c12fb58 1 parent 8dde3d1
@xolox authored
View
9 README.md
@@ -38,7 +38,7 @@ from the source code of the miscellaneous scripts using the Python module
<!-- Start of generated documentation -->
The documentation of the 92 functions below was extracted from
-19 Vim scripts on June 30, 2014 at 00:19.
+19 Vim scripts on June 30, 2014 at 00:41.
### Asynchronous Vim script evaluation
@@ -665,6 +665,13 @@ mode. The first argument is the pathname of the file to update (a string).
The second argument is the list of lines to be written to the file. Writes
the new contents to a temporary file and renames the temporary file into
place, thereby preventing readers from reading a partially written file.
+Returns 1 if the file is successfully updated, 0 otherwise.
+
+Note that if `xolox#misc#perm#get()` and `xolox#misc#perm#set()` cannot be
+used to preserve the file owner/group/mode the file is still updated using
+a rename (for compatibility with non-UNIX systems and incompatible
+`/usr/bin/stat` implementations) so in that case you can still lose the
+file's owner/group/mode.
#### The `xolox#misc#perm#get()` function
View
2  autoload/xolox/misc.vim
@@ -4,4 +4,4 @@
" Last Change: June 30, 2014
" URL: http://peterodding.com/code/vim/misc/
-let g:xolox#misc#version = '1.13'
+let g:xolox#misc#version = '1.13.1'
View
11 autoload/xolox/misc/perm.vim
@@ -32,6 +32,13 @@ function! xolox#misc#perm#update(fname, contents)
" The second argument is the list of lines to be written to the file. Writes
" the new contents to a temporary file and renames the temporary file into
" place, thereby preventing readers from reading a partially written file.
+ " Returns 1 if the file is successfully updated, 0 otherwise.
+ "
+ " Note that if `xolox#misc#perm#get()` and `xolox#misc#perm#set()` cannot be
+ " used to preserve the file owner/group/mode the file is still updated using
+ " a rename (for compatibility with non-UNIX systems and incompatible
+ " `/usr/bin/stat` implementations) so in that case you can still lose the
+ " file's owner/group/mode.
let starttime = xolox#misc#timer#start()
let temporary_file = printf('%s.tmp', a:fname)
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)
let pathname = xolox#misc#path#absolute(a:fname)
if filereadable(pathname)
let command = printf('stat --format %s %s', '%U:%G:%a', shellescape(pathname))
- let result = xolox#misc#os#exec({'command': command})
+ let result = xolox#misc#os#exec({'command': command, 'check': 0})
if result['exit_code'] == 0 && len(result['stdout']) >= 1
let tokens = split(result['stdout'][0], ':')
if len(tokens) == 3
@@ -88,6 +95,6 @@ endfunction
function! s:run(command, ...)
let args = map(copy(a:000), 'shellescape(v:val)')
call insert(args, a:command, 0)
- let result = xolox#misc#os#exec({'command': call('printf', args)})
+ let result = xolox#misc#os#exec({'command': call('printf', args), 'check': 0})
return result['exit_code'] == 0
endfunction
View
11 doc/misc.txt
@@ -167,7 +167,7 @@ from the source code of the miscellaneous scripts using the Python module
'vimdoctool.py' included in vim-tools [5].
The documentation of the 92 functions below was extracted from 19 Vim scripts
-on June 30, 2014 at 00:19.
+on June 30, 2014 at 00:41.
-------------------------------------------------------------------------------
*misc-asynchronous-vim-script-evaluation*
@@ -804,7 +804,14 @@ Atomically update a file's contents while preserving the owner, group and mode.
The first argument is the pathname of the file to update (a string). The second
argument is the list of lines to be written to the file. Writes the new
contents to a temporary file and renames the temporary file into place, thereby
-preventing readers from reading a partially written file.
+preventing readers from reading a partially written file. Returns 1 if the file
+is successfully updated, 0 otherwise.
+
+Note that if |xolox#misc#perm#get()| and |xolox#misc#perm#set()| cannot be used
+to preserve the file owner/group/mode the file is still updated using a rename
+(for compatibility with non-UNIX systems and incompatible '/usr/bin/stat'
+implementations) so in that case you can still lose the file's
+owner/group/mode.
-------------------------------------------------------------------------------
The *xolox#misc#perm#get()* function
Please sign in to comment.
Something went wrong with that request. Please try again.