couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject couch-mrview commit: updated refs/heads/master to f089832
Date Wed, 07 Oct 2015 17:51:32 GMT
Repository: couchdb-couch-mrview
Updated Branches:
  refs/heads/master 71f4fe7c1 -> f089832ea


Use couch_server:delete_file on view cleanup


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

Branch: refs/heads/master
Commit: f089832ea7f759b4e655051025cc48522fee9e1b
Parents: 71f4fe7
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Tue Oct 6 08:08:17 2015 -0700
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Wed Oct 7 09:31:12 2015 -0700

----------------------------------------------------------------------
 src/couch_mrview_cleanup.erl | 66 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f089832e/src/couch_mrview_cleanup.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_cleanup.erl b/src/couch_mrview_cleanup.erl
index 46c81b2..b96622a 100644
--- a/src/couch_mrview_cleanup.erl
+++ b/src/couch_mrview_cleanup.erl
@@ -41,7 +41,71 @@ run(Db) ->
 
     lists:foreach(fun(FN) ->
         couch_log:debug("Deleting stale view file: ~s", [FN]),
-        couch_file:delete(RootDir, FN, false)
+        delete_view_file(RootDir, FN)
     end, ToDelete),
 
     ok.
+
+delete_view_file(RootDir, FullFilePath) ->
+    couch_server:delete_file(RootDir, FullFilePath, [sync]).
+
+-ifdef(TEST).
+-include_lib("couch/include/couch_eunit.hrl").
+
+setup(rename) ->
+    setup(true);
+setup(delete) ->
+    setup(false);
+setup(RenameOnDelete) ->
+    meck:new(config, [passthrough]),
+    meck:expect(config, get_boolean, fun
+        ("couchdb", "rename_on_delete", _Default) -> RenameOnDelete
+    end),
+    ViewFile = ?tempfile() ++ ".view",
+    RootDir = filename:dirname(ViewFile),
+    ok = couch_file:init_delete_dir(RootDir),
+    ok = file:write_file(ViewFile, <<>>),
+    {RootDir, ViewFile}.
+
+teardown(_, {_, ViewFile}) ->
+    (catch meck:unload(config)),
+    (catch file:delete(ViewFile)).
+
+delete_view_file_test_() ->
+    Funs = [
+        fun should_rename_on_delete/2,
+        fun should_delete/2
+    ],
+    [
+        make_test_case(rename, [fun should_rename_on_delete/2]),
+        make_test_case(delete, [fun should_delete/2])
+    ].
+
+make_test_case(Mod, Funs) ->
+    {
+        lists:flatten(io_lib:format("~s", [Mod])),
+        {foreachx, fun setup/1, fun teardown/2, [{Mod, Fun} || Fun <- Funs]}
+    }.
+
+should_rename_on_delete(_, {RootDir, ViewFile}) ->
+    ?_test(begin
+        ?assert(filelib:is_regular(ViewFile)),
+        Result = delete_view_file(RootDir, ViewFile),
+        ?assertNot(filelib:is_regular(ViewFile)),
+        ?assertMatch({ok, {renamed, _}}, Result),
+        {ok, {renamed, RenamedViewFile}} = Result,
+        ?assert(filelib:is_regular(RenamedViewFile))
+    end).
+
+should_delete(_, {RootDir, ViewFile}) ->
+    ?_test(begin
+        ?assert(filelib:is_regular(ViewFile)),
+        delete_view_file(RootDir, ViewFile),
+        ?assertNot(filelib:is_regular(ViewFile)),
+        ?assertMatch([], deleted_files(ViewFile))
+    end).
+
+deleted_files(ViewFile) ->
+    filelib:wildcard(filename:rootname(ViewFile) ++ "*.deleted.*").
+
+-endif.


Mime
View raw message