Skip to content

Commit f2dab5d

Browse files
committed
Automatically store lock files in /var/lock when possible (issue #110)
This is basically a follow up to issue #101 with the idea that sane defaults should be provided when possible - most users don't read the documentation and even when they do they might still not find what they are looking for (and I don't really blame them, I'm exactly the same :-). Issue #101 on GitHub: #101 Issue #110 on GitHub: #110
1 parent 4fb9cdd commit f2dab5d

3 files changed

Lines changed: 39 additions & 17 deletions

File tree

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ This option controls the location of your session scripts. Its default value is
129129

130130
### The `g:session_lock_directory` option
131131

132-
The vim-session plug-in uses lock files to prevent double loading of sessions. By default the lock files are stored in the same directory as the sessions. If you'd rather store lock files in a dedicated lock file directory you can use this option:
132+
The vim-session plug-in uses lock files to prevent double loading of sessions. The default location (directory) of these lock files depends on a couple of factors:
133133

134-
" Store lock files in a tmpfs that doesn't persist between reboots.
135-
let g:session_lock_directory = '/var/lock'
134+
1. If you have explicitly set the `g:session_lock_directory` option that defines the directory.
135+
2. If the directory `/var/lock` exists and is writable that is used as a sane default.
136+
3. As a sane fall back for platforms where `/var/lock` is not available the directory that stores the session scripts themselves is used.
136137

137138
### The `g:session_default_name` option
138139

@@ -263,7 +264,7 @@ Recently this plug-in switched from reimplementing [:mksession][mksession] to ac
263264
<!-- Start of generated documentation -->
264265

265266
The documentation of the 37 functions below was extracted from
266-
2 Vim scripts on September 14, 2014 at 13:07.
267+
2 Vim scripts on February 13, 2015 at 13:25.
267268

268269
### Public API for the vim-session plug-in
269270

@@ -488,8 +489,8 @@ If you have questions, bug reports, suggestions, etc. the author can be contacte
488489

489490
## License
490491

491-
This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
492-
© 2014 Peter Odding &lt;<peter@peterodding.com>&gt; and Ingo Karkat.
492+
This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
493+
© 2015 Peter Odding &lt;<peter@peterodding.com>&gt; and Ingo Karkat.
493494

494495
Thanks go out to everyone who has helped to improve the vim-session plug-in (whether through pull requests, bug reports or personal e-mails).
495496

autoload/xolox/session.vim

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
" Public API for the vim-session plug-in.
22
"
33
" Author: Peter Odding
4-
" Last Change: September 14, 2014
4+
" Last Change: February 13, 2015
55
" URL: http://peterodding.com/code/vim/session/
66

7-
let g:xolox#session#version = '2.7'
7+
let g:xolox#session#version = '2.8'
88

99
" Public API for session persistence. {{{1
1010

@@ -1020,6 +1020,22 @@ endfunction
10201020

10211021
function! s:lock_file_path(session_path)
10221022
let directory = xolox#misc#option#get('session_lock_directory', '')
1023+
if empty(directory)
1024+
" Stale lock files can be really annoying, especially after a reboot
1025+
" because that just shouldn't happen - it's always a bug. References:
1026+
" - https://github.com/xolox/vim-session/issues/97
1027+
" - https://github.com/xolox/vim-session/issues/110
1028+
" One simple way to give a large group of users what they want is to use a
1029+
" volatile directory that is specifically meant for storing lock files.
1030+
" I've decided to make this the default when possible. The best reference
1031+
" I've been able to find on the proper system wide location for lock files
1032+
" is the following (yes, I know, it's Linux specific, so sue me):
1033+
" http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/var.html
1034+
let global_lock_directory = '/var/lock'
1035+
if filewritable(global_lock_directory) == 2
1036+
let directory = global_lock_directory
1037+
endif
1038+
endif
10231039
if !empty(directory)
10241040
let pathname = xolox#misc#path#merge(directory, xolox#misc#path#encode(a:session_path))
10251041
else

doc/session.txt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,18 @@ for you. Note that a leading '~' is expanded to your current home directory
310310
The *g:session_lock_directory* option
311311

312312
The vim-session plug-in uses lock files to prevent double loading of sessions.
313-
By default the lock files are stored in the same directory as the sessions. If
314-
you'd rather store lock files in a dedicated lock file directory you can use
315-
this option:
316-
>
317-
" Store lock files in a tmpfs that doesn't persist between reboots.
318-
let g:session_lock_directory = '/var/lock'
319-
<
313+
The default location (directory) of these lock files depends on a couple of
314+
factors:
315+
316+
1. If you have explicitly set the |g:session_lock_directory| option that
317+
defines the directory.
318+
319+
2. If the directory '/var/lock' exists and is writable that is used as a
320+
sane default.
321+
322+
3. As a sane fall back for platforms where '/var/lock' is not available the
323+
directory that stores the session scripts themselves is used.
324+
320325
-------------------------------------------------------------------------------
321326
The *g:session_default_name* option
322327

@@ -525,7 +530,7 @@ might take a while...)
525530
Function reference ~
526531

527532
The documentation of the 37 functions below was extracted from 2 Vim scripts on
528-
September 14, 2014 at 13:07.
533+
February 13, 2015 at 13:25.
529534

530535
-------------------------------------------------------------------------------
531536
*public-api-for-vim-session-plug-in*
@@ -764,7 +769,7 @@ session. If you like the script please vote for it on Vim Online [19].
764769
*session-license*
765770
License ~
766771

767-
This software is licensed under the MIT license [20]. Š 2014 Peter Odding
772+
This software is licensed under the MIT license [20]. Š 2015 Peter Odding
768773
<peter@peterodding.com> and Ingo Karkat.
769774

770775
Thanks go out to everyone who has helped to improve the vim-session plug-in

0 commit comments

Comments
 (0)