diff options
author | Hans Bolinder <[email protected]> | 2014-10-23 09:02:28 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2014-10-23 09:02:28 +0200 |
commit | 527ae7b5030ba7339eba5ba4089888c8f90e2879 (patch) | |
tree | ffd9350604b0f02cee5ea8de8e77c50dd5966597 /lib/stdlib/src/dets.erl | |
parent | aeeda10c7ada4f81add3cb9c0b8205cc15168675 (diff) | |
parent | ff3fae223431a9cb0d2a2852a07f9447960c92ed (diff) | |
download | otp-527ae7b5030ba7339eba5ba4089888c8f90e2879.tar.gz otp-527ae7b5030ba7339eba5ba4089888c8f90e2879.tar.bz2 otp-527ae7b5030ba7339eba5ba4089888c8f90e2879.zip |
Merge branch 'maint'
* maint:
Fix rare race condition in Dets
Diffstat (limited to 'lib/stdlib/src/dets.erl')
-rw-r--r-- | lib/stdlib/src/dets.erl | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/stdlib/src/dets.erl b/lib/stdlib/src/dets.erl index 76e03bbfaa..a4bd45ea19 100644 --- a/lib/stdlib/src/dets.erl +++ b/lib/stdlib/src/dets.erl @@ -2839,17 +2839,22 @@ fsck_try(Fd, Tab, FH, Fname, SlotNumbers, Version) -> tempfile(Fname) -> Tmp = lists:concat([Fname, ".TMP"]), - tempfile(Tmp, 10). - -tempfile(Tmp, 0) -> - Tmp; -tempfile(Tmp, N) -> case file:delete(Tmp) of - {error, eacces} -> % 'dets_process_died' happened anyway... (W-nd-ws) - timer:sleep(1000), - tempfile(Tmp, N-1); - _ -> - Tmp + {error, _Reason} -> % typically enoent + ok; + ok -> + assure_no_file(Tmp) + end, + Tmp. + +assure_no_file(File) -> + case file:read_file_info(File) of + {ok, _FileInfo} -> + %% Wait for some other process to close the file: + timer:sleep(100), + assure_no_file(File); + {error, _} -> + ok end. %% -> {ok, NewHead} | {try_again, integer()} | Error |