Permalink
Browse files

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.
  • Loading branch information...
rnewson authored and benoitc committed Dec 20, 2012
1 parent ac9e73b commit 6643b401abfe79234ed1952d44494d609c112e44
Showing with 6 additions and 4 deletions.
  1. +6 −4 apps/couch/src/couch_file.erl
@@ -229,10 +229,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

0 comments on commit 6643b40

Please sign in to comment.