Skip to content

Commit

Permalink
prevent writing file racing
Browse files Browse the repository at this point in the history
  • Loading branch information
skywind3000 committed Mar 1, 2019
1 parent fdff5c5 commit 38c1741
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ As you see, z.lua is the fastest one and requires less resource.

## History

- 1.5.10 (2019-03-01): Prevent writing file racing.
- 1.5.9 (2019-02-25): `z -b` should not match current directory (close #56).
- 1.5.8 (2019-02-21): new `$_ZL_FZF_HEIGHT` to control `--height` parameter in fzf.
- 1.5.7 (2019-02-21): rename `$_ZL_FZF_SORT` to `$_ZL_INT_SORT` it will affect both `-i` and `-I`.
Expand Down
17 changes: 11 additions & 6 deletions z.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- z.lua - a cd command that learns, by skywind 2018, 2019
-- Licensed under MIT license.
--
-- Version 1.5.9, Last Modified: 2019/02/25 23:17
-- Version 1.5.10, Last Modified: 2019/03/01 13:08
--
-- * 10x faster than fasd and autojump, 3x faster than z.sh
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
Expand Down Expand Up @@ -960,11 +960,16 @@ function data_save(filename, M)
fp = io.open(filename, 'w')
else
math.random_init()
tmpname = filename .. '.' .. tostring(os.time())
tmpname = tmpname .. math.random_string(8)
local rnd = os.getenv('_ZL_RANDOM')
tmpname = tmpname .. '' .. (rnd and rnd or '')
-- print('tmpname: '..tmpname)
while true do
tmpname = filename .. '.' .. tostring(os.time())
tmpname = tmpname .. math.random_string(8)
local rnd = os.getenv('_ZL_RANDOM')
tmpname = tmpname .. '' .. (rnd and rnd or '')
if not os.path.exists(tmpname) then
-- print('tmpname: '..tmpname)
break
end
end
fp = io.open(tmpname, 'w')
end
if fp == nil then
Expand Down

0 comments on commit 38c1741

Please sign in to comment.