couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject couch commit: updated refs/heads/master to 0f81930
Date Wed, 07 Oct 2015 17:50:02 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 4ca9e4184 -> 0f819309c


Export couch_server:delete_file for reuse


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/0f819309
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/0f819309
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/0f819309

Branch: refs/heads/master
Commit: 0f819309c8923f1c93fec73793d095d5ee74d0ee
Parents: 4ca9e41
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Tue Oct 6 08:12:59 2015 -0700
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Wed Oct 7 09:23:12 2015 -0700

----------------------------------------------------------------------
 src/couch_server.erl        | 28 ++++++++++++++++++++--------
 test/couch_server_tests.erl | 24 +++++++++++-------------
 2 files changed, 31 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/0f819309/src/couch_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_server.erl b/src/couch_server.erl
index 3fea228..bb93dfe 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -25,6 +25,8 @@
 % config_listener api
 -export([handle_config_change/5, handle_config_terminate/3]).
 
+-export([delete_file/3]).
+
 -include_lib("couch/include/couch_db.hrl").
 
 -define(MAX_DBS_OPEN, 100).
@@ -460,8 +462,8 @@ handle_call({delete, DbName, Options}, _From, Server) ->
 
         couch_db_plugin:on_delete(DbName, Options),
 
-        case delete_db_file(Server#server.root_dir, FullFilepath, Options) of
-        ok ->
+        case delete_file(Server#server.root_dir, FullFilepath, Options) of
+        {ok, _} ->
             couch_event:notify(DbName, deleted),
             {reply, ok, Server2};
         {error, enoent} ->
@@ -538,20 +540,30 @@ db_closed(Server, Options) ->
         true -> Server
     end.
 
-delete_db_file(RootDir, FullFilePath, Options) ->
+delete_file(RootDir, FullFilePath, Options) ->
     Async = not lists:member(sync, Options),
     RenameOnDelete = config:get_boolean("couchdb", "rename_on_delete", false),
     case {Async, RenameOnDelete} of
         {_, true} ->
             rename_on_delete(FullFilePath);
         {Async, false} ->
-            couch_file:delete(RootDir, FullFilePath, Async)
+            case couch_file:delete(RootDir, FullFilePath, Async) of
+                ok -> {ok, deleted};
+                Else -> Else
+            end
     end.
 
 rename_on_delete(Original) ->
+    DeletedFileName = deleted_filename(Original),
+    case file:rename(Original, DeletedFileName) of
+        ok -> {ok, {renamed, DeletedFileName}};
+        Else -> Else
+    end.
+
+deleted_filename(Original) ->
     {{Y,Mon,D}, {H,Min,S}} = calendar:universal_time(),
     Suffix = lists:flatten(
-        io_lib:format(".~w~2.10.0B~2.10.0B." ++
-            "~2.10.0B~2.10.0B~2.10.0B.deleted.couch", [Y,Mon,D,H,Min,S])),
-    Rename = filename:rootname(Original) ++ Suffix,
-    file:rename(Original, Rename).
+        io_lib:format(".~w~2.10.0B~2.10.0B."
+            ++ "~2.10.0B~2.10.0B~2.10.0B.deleted"
+            ++ filename:extension(Original), [Y,Mon,D,H,Min,S])),
+    filename:rootname(Original) ++ Suffix.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/0f819309/test/couch_server_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_server_tests.erl b/test/couch_server_tests.erl
index 3df48a3..fcabbe5 100644
--- a/test/couch_server_tests.erl
+++ b/test/couch_server_tests.erl
@@ -62,27 +62,25 @@ make_test_case(Mod, Funs) ->
     }.
 
 should_rename_on_delete(_, #db{filepath = Origin, name = DbName}) ->
-    Renamed = renamed_filename(Origin),
     ?_test(begin
         ?assert(filelib:is_regular(Origin)),
         ?assertMatch(ok, couch_server:delete(DbName, [])),
-        ?assert(filelib:is_regular(Renamed)),
-        ?assertNot(filelib:is_regular(Origin))
+        ?assertNot(filelib:is_regular(Origin)),
+        DeletedFiles = deleted_files(Origin),
+        ?assertMatch([_], DeletedFiles),
+        [Renamed] = DeletedFiles,
+        ?assertEqual(
+            filename:extension(Origin), filename:extension(Renamed)),
+        ?assert(filelib:is_regular(Renamed))
     end).
 
 should_delete(_, #db{filepath = Origin, name = DbName}) ->
-    PossiblyRenamed = renamed_filename(Origin),
     ?_test(begin
         ?assert(filelib:is_regular(Origin)),
         ?assertMatch(ok, couch_server:delete(DbName, [])),
-        ?assertNot(filelib:is_regular(PossiblyRenamed)),
-        ?assertNot(filelib:is_regular(Origin))
+        ?assertNot(filelib:is_regular(Origin)),
+        ?assertMatch([], deleted_files(Origin))
     end).
 
-
-renamed_filename(Original) ->
-    {{Y,Mon,D}, {H,Min,S}} = calendar:universal_time(),
-    Suffix = lists:flatten(
-        io_lib:format(".~w~2.10.0B~2.10.0B." ++
-            "~2.10.0B~2.10.0B~2.10.0B.deleted.couch", [Y,Mon,D,H,Min,S])),
-    filename:rootname(Original) ++ Suffix.
+deleted_files(ViewFile) ->
+    filelib:wildcard(filename:rootname(ViewFile) ++ "*.deleted.*").


Mime
View raw message