From d0e2510ccb74b61a62e32f75c35396f62556c2f7 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Sat, 3 Jul 2010 03:34:10 +0000 Subject: =?UTF-8?q?Fixed=20intermittent=20problem=20deleting=20files=20on?= =?UTF-8?q?=20Windows.=20Added=20Juhani=20R=C3=A4nkimies=20to=20THANKS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@960150 13f79535-47bb-0310-9956-ffa450edef68 --- THANKS | 1 + src/couchdb/couch_file.erl | 20 +++++++++++++++++--- src/couchdb/couch_server.erl | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/THANKS b/THANKS index c7b18bcb..456a3960 100644 --- a/THANKS +++ b/THANKS @@ -62,5 +62,6 @@ suggesting improvements or submitting changes. Some of these people are: * Brian Jenkins * Paul Bonser * Caleb Land + * Juhani Ränkimies For a list of authors see the `AUTHORS` file. diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl index 6671bcc1..b130c1db 100644 --- a/src/couchdb/couch_file.erl +++ b/src/couchdb/couch_file.erl @@ -28,7 +28,7 @@ -export([pread_binary/2, read_header/1, truncate/2, upgrade_old_header/2]). -export([append_term_md5/2,append_binary_md5/2]). -export([init/1, terminate/2, handle_call/3, handle_cast/2, code_change/3, handle_info/2]). --export([delete/1]). +-export([delete/1,init_delete_dir/0]). %%---------------------------------------------------------------------- %% Args: Valid Options are [create] and [create,overwrite]. @@ -171,14 +171,28 @@ close(Fd) -> end. delete(Filepath) -> - case file:rename(Filepath, Filepath ++ ".delete") of + DbDir = couch_config:get("couchdb", "database_dir"), + DelFile = filename:join([DbDir,".delete", ?b2l(couch_uuids:random())]), + case file:rename(Filepath, DelFile) of ok -> - spawn(file, delete, [Filepath ++ ".delete"]), + spawn(file, delete, [DelFile]), ok; Error -> Error end. + +init_delete_dir() -> + Dir = filename:join(couch_config:get("couchdb","database_dir"),".delete"), + % note: ensure_dir requires an actual filename companent, which is the + % reason for "foo". + filelib:ensure_dir(filename:join(Dir,"foo")), + filelib:fold_files(Dir, ".*", true, + fun(Filename, _) -> + ok = file:delete(Filename) + end, ok). + + % 09 UPGRADE CODE old_pread(Fd, Pos, Len) -> {ok, <>, false} = gen_server:call(Fd, {pread, Pos, Len}, infinity), diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index e930c021..84a02d13 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -131,6 +131,7 @@ init([]) -> gen_server:call(couch_server, {set_max_dbs_open, list_to_integer(Max)}) end), + ok = couch_file:init_delete_dir(), hash_admin_passwords(), ok = couch_config:register( fun("admins", _Key, _Value, Persist) -> -- cgit v1.2.3