Github user rnewson commented on a diff in the pull request:
https://github.com/apache/couchdb-couch/pull/161#discussion_r60072419
--- Diff: src/couch_file.erl ---
@@ -252,14 +252,23 @@ deleted_filename_suffix() ->
[Y, Mon, D, H, Min, S, couch_uuids:random()]).
nuke_dir(RootDelDir, Dir) ->
+ case config:get_boolean("couchdb", "rename_on_delete", false) of
+ true -> couch_server:delete_file(RootDelDir, Dir, []);
+ false -> delete_dir(RootDelDir, Dir)
+ end.
+
+delete_dir(RootDelDir, Dir) ->
FoldFun = fun(File) ->
Path = Dir ++ "/" ++ File,
case filelib:is_dir(Path) of
true ->
- ok = nuke_dir(RootDelDir, Path),
+ ok = delete_dir(RootDelDir, Path),
file:del_dir(Path);
false ->
- delete(RootDelDir, Path, false)
+ UUID = couch_uuids:random(),
+ TmpFile = filename:join([RootDelDir, ".delete", UUID]),
+ file:rename(Path, TmpFile),
+ file:delete(TmpFile)
--- End diff --
this still does seem a bit pointless in this context. The original context
was deleting a database which, at the time, was a single file. When we're
deleting all views, renaming each filed them immediately deleting it doesn't
seem to do much beyond complicate things.
@davisp thoughts here pls?
I suggest that nuke_dir renames the top level Dir to .delete first and then
recursively deletes it. That gives us the behaviour we want (making it easier
to clean if we crash and restart during the time-consuming file:delete calls)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---