You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2012/12/20 18:57:32 UTC

[2/2] git commit: Delete view files on database deletion

Delete view files on database deletion

couch_file:nuke_dir attempts to recurse into subdirectories and delete
the contents, it does so when couch_file:delete returns {error,
eperm}. Unfortunately, the subdirectory has been renamed to a random
uuid before returning, and so the recursive call gets {error, enoent}
from list:dir(Path) where Path is the original (non-existent)
subdirectory path.

View files are not currently deleted when a database is because of
this (this happened since 1.2.0, no release is broken) because the
view engine rewrite added a further directory level called 'mrview'.

This patch modifies nuke_dir to depth-first, solving the issue.


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

Branch: refs/heads/master
Commit: 5b9708b68ce6d68f4f40235ea880f299b5dcd9e3
Parents: fb3a1ea
Author: Robert Newson <rn...@apache.org>
Authored: Thu Dec 20 17:05:37 2012 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Dec 20 17:32:48 2012 +0000

----------------------------------------------------------------------
 src/couchdb/couch_file.erl |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/5b9708b6/src/couchdb/couch_file.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index 54ff693..ee5dafb 100644
--- a/src/couchdb/couch_file.erl
+++ b/src/couchdb/couch_file.erl
@@ -223,10 +223,12 @@ delete(RootDir, Filepath, Async) ->
 nuke_dir(RootDelDir, Dir) ->
     FoldFun = fun(File) ->
         Path = Dir ++ "/" ++ File,
-        case delete(RootDelDir, Path, false) of
-            {error, eperm} -> ok = nuke_dir(RootDelDir, Path);
-            {error, enoent} -> ok;
-            ok -> ok
+        case filelib:is_dir(Path) of
+            true ->
+                ok = nuke_dir(RootDelDir, Path),
+                file:del_dir(Path);
+            false ->
+                delete(RootDelDir, Path, false)
         end
     end,
     case file:list_dir(Dir) of