diff options
author | Paul Joseph Davis <davisp@apache.org> | 2010-03-16 00:44:21 +0000 |
---|---|---|
committer | Paul Joseph Davis <davisp@apache.org> | 2010-03-16 00:44:21 +0000 |
commit | 67313872c0fde033688369b6785fc42ab6c64770 (patch) | |
tree | e19997ebbeaa67a8e21cd19fa8411f65bb334cde /src | |
parent | 17fd3e388668be4abf091b01f8f49db887bcddb5 (diff) |
Fixes couch_server:all_databases/0
The logic was failing when the database path had a '.' path component
in the middle because Filename -- Root is not a prefix operation. This
patch adds a normalization function to couch_util that is run on the
Root and Filename variables before doing the array subtraction. I could
probably make it smarter and error out but I got lazy.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@923526 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/couchdb/couch_server.erl | 4 | ||||
-rw-r--r-- | src/couchdb/couch_util.erl | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index ac3a5df3..e52bacfa 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -153,10 +153,12 @@ terminate(Reason, _Srv) -> all_databases() -> {ok, #server{root_dir=Root}} = gen_server:call(couch_server, get_server), + NormRoot = couch_util:normpath(Root), Filenames = filelib:fold_files(Root, "^[a-z0-9\\_\\$()\\+\\-]*[\\.]couch$", true, fun(Filename, AccIn) -> - case Filename -- Root of + NormFilename = couch_util:normpath(Filename), + case NormFilename -- NormRoot of [$/ | RelativeFilename] -> ok; RelativeFilename -> ok end, diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index b7e237c1..3b43016c 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -12,7 +12,7 @@ -module(couch_util). --export([priv_dir/0, start_driver/1,terminate_linked/1]). +-export([priv_dir/0, start_driver/1, normpath/1, terminate_linked/1]). -export([should_flush/0, should_flush/1, to_existing_atom/1]). -export([rand32/0, implode/2, collate/2, collate/3]). -export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1]). @@ -50,6 +50,19 @@ start_driver(LibDir) -> exit(erl_ddll:format_error(Error)) end. +% Normalize a pathname by removing .. and . components. +normpath(Path) -> + normparts(filename:split(Path), []). + +normparts([], Acc) -> + filename:join(lists:reverse(Acc)); +normparts([".." | RestParts], [_Drop | RestAcc]) -> + normparts(RestParts, RestAcc); +normparts(["." | RestParts], Acc) -> + normparts(RestParts, Acc); +normparts([Part | RestParts], Acc) -> + normparts(RestParts, [Part | Acc]). + % works like list_to_existing_atom, except can be list or binary and it % gives you the original value instead of an error if no existing atom. to_existing_atom(V) when is_list(V) -> |