diff options
Diffstat (limited to 'src/couchdb/couch_file.erl')
-rw-r--r-- | src/couchdb/couch_file.erl | 20 |
1 files changed, 17 insertions, 3 deletions
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, <<RawBin:Len/binary>>, false} = gen_server:call(Fd, {pread, Pos, Len}, infinity), |