summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2012-12-20 17:05:37 +0000
committerRobert Newson <rnewson@apache.org>2012-12-20 17:32:48 +0000
commit5b9708b68ce6d68f4f40235ea880f299b5dcd9e3 (patch)
treef91b9a3bc8603217d8e837d1f13bb23fc476200c
parentfb3a1eafe6445ec2a3c2b28fcebcea6c4cfd8508 (diff)
downloadcouchdb-5b9708b68ce6d68f4f40235ea880f299b5dcd9e3.tar.gz
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.
-rw-r--r--src/couchdb/couch_file.erl10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index 54ff69346..ee5dafbf8 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