Skip to content

Commit

Permalink
Bug fix: Don't raise exception if /usr/bin/stat doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jun 29, 2014
1 parent 8dde3d1 commit 9d1f006
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.md
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion autoload/xolox/misc.vim
Expand Up @@ -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'
11 changes: 9 additions & 2 deletions autoload/xolox/misc/perm.vim
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
11 changes: 9 additions & 2 deletions doc/misc.txt
Expand Up @@ -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*
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9d1f006

Please sign in to comment.