z icon indicating copy to clipboard operation
z copied to clipboard

Use database locking (flock) for zsh

Open mafredri opened this issue 8 years ago • 9 comments

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

mafredri avatar Mar 01 '17 16:03 mafredri

@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 avatar May 31 '17 08:05 balta2ar

@rupa ping

balta2ar avatar Jul 13 '17 15:07 balta2ar

@rupa ping

balta2ar avatar Oct 15 '17 17:10 balta2ar

Yes please! Would love to see this get merged.

jordanlewis avatar Dec 21 '17 19:12 jordanlewis

@rupa gentle ping

balta2ar avatar Jun 06 '18 17:06 balta2ar

This would be very useful..

alphaCTzo7G avatar Jul 20 '18 17:07 alphaCTzo7G

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.

mafredri avatar Feb 24 '19 11:02 mafredri

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

rupa avatar Mar 21 '19 02:03 rupa

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

mafredri avatar Mar 21 '19 19:03 mafredri