Github user iilyak commented on a diff in the pull request: https://github.com/apache/couchdb-couch/pull/27#discussion_r22413903 --- Diff: src/couch_file.erl --- @@ -257,13 +257,43 @@ nuke_dir(RootDelDir, Dir) -> init_delete_dir(RootDir) -> Dir = filename:join(RootDir,".delete"), - % note: ensure_dir requires an actual filename companent, which is the - % reason for "foo". - filelib:ensure_dir(filename:join(Dir,"foo")), + ensure_dir(Dir), + TmpDir = make_temp_name(Dir), + % rename original directory so we can return and delete files asynchronously + ok = file:rename(Dir, TmpDir), + % recreate original directory + ensure_dir(Dir), + spawn(fun() -> delete_temp_dirs(RootDir, Dir) end), + ok. + + +make_temp_name(Prefix) -> + {A,B,C} = now(), + lists:flatten(io_lib:format("~s.tmp-~p.~p.~p",[Prefix, A, B, C])). + + +delete_temp_dirs(RootDir, Prefix) -> + Dirs = filelib:wildcard(Prefix ++ ".tmp-" ++ "*", RootDir), + [ok = delete_dir(Dir) || Dir <- Dirs], + ok. + + +ensure_dir(Dir) -> + filelib:ensure_dir(Dir ++ "/"). --- End diff -- According to docs for filename module: In Windows, all functions return file names with forward slashes only, even if the arguments contain back slashes. Also if I remember correctly it worked on windows. However it was long time ago when I did erlang project on windows. So it might be broken on recent erlang versions, but I doubt.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---