diff options
author | Damien F. Katz <damien@apache.org> | 2010-07-03 04:25:06 +0000 |
---|---|---|
committer | Damien F. Katz <damien@apache.org> | 2010-07-03 04:25:06 +0000 |
commit | c7117e17bed9cc0dec38264ee31463d5ef56ac4c (patch) | |
tree | cbfa756df445aefce25dcc6399e045e83c2efd31 /src/couchdb/couch_file.erl | |
parent | d0e2510ccb74b61a62e32f75c35396f62556c2f7 (diff) |
Fix deletion to move properly to root of storage, to avoid copying files when view and database dirs are on different mounts.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@960153 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_file.erl')
-rw-r--r-- | src/couchdb/couch_file.erl | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl index b130c1db..0a891712 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,init_delete_dir/0]). +-export([delete/2,delete/3,init_delete_dir/1]). %%---------------------------------------------------------------------- %% Args: Valid Options are [create] and [create,overwrite]. @@ -170,20 +170,28 @@ close(Fd) -> erlang:demonitor(MRef, [flush]) end. -delete(Filepath) -> - DbDir = couch_config:get("couchdb", "database_dir"), - DelFile = filename:join([DbDir,".delete", ?b2l(couch_uuids:random())]), + +delete(RootDir, Filepath) -> + delete(RootDir, Filepath, true). + + +delete(RootDir, Filepath, Async) -> + DelFile = filename:join([RootDir,".delete", ?b2l(couch_uuids:random())]), case file:rename(Filepath, DelFile) of ok -> - spawn(file, delete, [DelFile]), - ok; + if (Async) -> + spawn(file, delete, [DelFile]), + ok; + true -> + file:delete(DelFile) + end; Error -> Error end. -init_delete_dir() -> - Dir = filename:join(couch_config:get("couchdb","database_dir"),".delete"), +init_delete_dir(RootDir) -> + Dir = filename:join(RootDir,".delete"), % note: ensure_dir requires an actual filename companent, which is the % reason for "foo". filelib:ensure_dir(filename:join(Dir,"foo")), |