Skip to content

Commit 9d1f006

Browse files
committed
Bug fix: Don't raise exception if /usr/bin/stat doesn't work
1 parent 8dde3d1 commit 9d1f006

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ from the source code of the miscellaneous scripts using the Python module
3838
<!-- Start of generated documentation -->
3939

4040
The documentation of the 92 functions below was extracted from
41-
19 Vim scripts on June 30, 2014 at 00:19.
41+
19 Vim scripts on June 30, 2014 at 00:41.
4242

4343
### Asynchronous Vim script evaluation
4444

@@ -665,6 +665,13 @@ mode. The first argument is the pathname of the file to update (a string).
665665
The second argument is the list of lines to be written to the file. Writes
666666
the new contents to a temporary file and renames the temporary file into
667667
place, thereby preventing readers from reading a partially written file.
668+
Returns 1 if the file is successfully updated, 0 otherwise.
669+
670+
Note that if `xolox#misc#perm#get()` and `xolox#misc#perm#set()` cannot be
671+
used to preserve the file owner/group/mode the file is still updated using
672+
a rename (for compatibility with non-UNIX systems and incompatible
673+
`/usr/bin/stat` implementations) so in that case you can still lose the
674+
file's owner/group/mode.
668675

669676
#### The `xolox#misc#perm#get()` function
670677

autoload/xolox/misc.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
" Last Change: June 30, 2014
55
" URL: http://peterodding.com/code/vim/misc/
66

7-
let g:xolox#misc#version = '1.13'
7+
let g:xolox#misc#version = '1.13.1'

autoload/xolox/misc/perm.vim

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
8895
function! 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
93100
endfunction

doc/misc.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ from the source code of the miscellaneous scripts using the Python module
167167
'vimdoctool.py' included in vim-tools [5].
168168

169169
The documentation of the 92 functions below was extracted from 19 Vim scripts
170-
on June 30, 2014 at 00:19.
170+
on June 30, 2014 at 00:41.
171171

172172
-------------------------------------------------------------------------------
173173
*misc-asynchronous-vim-script-evaluation*
@@ -804,7 +804,14 @@ Atomically update a file's contents while preserving the owner, group and mode.
804804
The first argument is the pathname of the file to update (a string). The second
805805
argument is the list of lines to be written to the file. Writes the new
806806
contents to a temporary file and renames the temporary file into place, thereby
807-
preventing readers from reading a partially written file.
807+
preventing readers from reading a partially written file. Returns 1 if the file
808+
is successfully updated, 0 otherwise.
809+
810+
Note that if |xolox#misc#perm#get()| and |xolox#misc#perm#set()| cannot be used
811+
to preserve the file owner/group/mode the file is still updated using a rename
812+
(for compatibility with non-UNIX systems and incompatible '/usr/bin/stat'
813+
implementations) so in that case you can still lose the file's
814+
owner/group/mode.
808815

809816
-------------------------------------------------------------------------------
810817
The *xolox#misc#perm#get()* function

0 commit comments

Comments
 (0)