rupa / z

z - jump around
Do What The F*ck You Want To Public License
16.39k stars 1.17k forks source link

Use database locking (flock) for zsh #199

Open mafredri opened 7 years ago

mafredri commented 7 years ago

This PR adds support for locking the database (via advisory file locking) during update when zsh is used as shell. This is done via zsystem flock that is available in the zsh/system module. The lock is acquired before the database is read and kept until the (new) database has been written and the command has exited.

A separate code path is needed when updating the database entry because replacing the file (via mv) would cause any process waiting for a lock to fail. Here we simply clobber the database with the contents of the tempfile.

This is a partial fix for #198, more specifically, this only fixes the problem on zsh.

// ping @balta2ar

balta2ar commented 7 years ago

@rupa ping. Could you please review and merge this? I've been using it for two months and so far had no races and DB corruptions.

balta2ar commented 7 years ago

@rupa ping

balta2ar commented 7 years ago

@rupa ping

jordanlewis commented 6 years ago

Yes please! Would love to see this get merged.

balta2ar commented 6 years ago

@rupa gentle ping

alphaCTzo7G commented 6 years ago

This would be very useful..

mafredri commented 5 years ago

As this PR is coming up on two years, I'm closing it. If there's anything I can do to make it land, I'd be happy to fix. For example, if the use of mktemp is a problem, it would not be needed if we also landed https://github.com/rupa/z/pull/247.

rupa commented 5 years ago

sorry my friend, I haven't have a lot of bandwidth, I don't use zsh, and I am definitely slow on changes with this project for a variety of reasons. This is an issue though, and i'd prefer it stay open.

Thanks, and apologies

mafredri commented 5 years ago

@rupa that's quite alright, I understand 😄. Rebased on master to get rid of the conflicts.