Skip to content

Commit

Permalink
Automatically store lock files in /var/lock when possible (issue #110)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xolox committed Feb 13, 2015
1 parent 4fb9cdd commit f2dab5d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
13 changes: 7 additions & 6 deletions README.md
Expand Up @@ -129,10 +129,11 @@ This option controls the location of your session scripts. Its default value is

### The `g:session_lock_directory` option

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:
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:

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

### The `g:session_default_name` option

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

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

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

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

## License

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

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).

Expand Down
20 changes: 18 additions & 2 deletions autoload/xolox/session.vim
@@ -1,10 +1,10 @@
" Public API for the vim-session plug-in.
"
" Author: Peter Odding
" Last Change: September 14, 2014
" Last Change: February 13, 2015
" URL: http://peterodding.com/code/vim/session/

let g:xolox#session#version = '2.7'
let g:xolox#session#version = '2.8'

" Public API for session persistence. {{{1

Expand Down Expand Up @@ -1020,6 +1020,22 @@ endfunction

function! s:lock_file_path(session_path)
let directory = xolox#misc#option#get('session_lock_directory', '')
if empty(directory)
" Stale lock files can be really annoying, especially after a reboot
" because that just shouldn't happen - it's always a bug. References:
" - https://github.com/xolox/vim-session/issues/97
" - https://github.com/xolox/vim-session/issues/110
" One simple way to give a large group of users what they want is to use a
" volatile directory that is specifically meant for storing lock files.
" I've decided to make this the default when possible. The best reference
" I've been able to find on the proper system wide location for lock files
" is the following (yes, I know, it's Linux specific, so sue me):
" http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/var.html
let global_lock_directory = '/var/lock'
if filewritable(global_lock_directory) == 2
let directory = global_lock_directory
endif
endif
if !empty(directory)
let pathname = xolox#misc#path#merge(directory, xolox#misc#path#encode(a:session_path))
else
Expand Down
23 changes: 14 additions & 9 deletions doc/session.txt
Expand Up @@ -310,13 +310,18 @@ for you. Note that a leading '~' is expanded to your current home directory
The *g:session_lock_directory* option

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:
>
" Store lock files in a tmpfs that doesn't persist between reboots.
let g:session_lock_directory = '/var/lock'
<
The default location (directory) of these lock files depends on a couple of
factors:

1. If you have explicitly set the |g:session_lock_directory| option that
defines the directory.

2. If the directory '/var/lock' exists and is writable that is used as a
sane default.

3. As a sane fall back for platforms where '/var/lock' is not available the
directory that stores the session scripts themselves is used.

-------------------------------------------------------------------------------
The *g:session_default_name* option

Expand Down Expand Up @@ -525,7 +530,7 @@ might take a while...)
Function reference ~

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

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

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

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

0 comments on commit f2dab5d

Please sign in to comment.