diff options
author | Robert Newson <rnewson@apache.org> | 2012-12-20 17:05:37 +0000 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2012-12-20 17:32:48 +0000 |
commit | 5b9708b68ce6d68f4f40235ea880f299b5dcd9e3 (patch) | |
tree | f91b9a3bc8603217d8e837d1f13bb23fc476200c | |
parent | fb3a1eafe6445ec2a3c2b28fcebcea6c4cfd8508 (diff) | |
download | couchdb-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.erl | 10 |
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 |