diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2011-08-10 20:47:27 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2011-08-10 20:47:27 +0000 |
commit | b2db4f11376472fa801c58f98dcc2e356783e276 (patch) | |
tree | 65125d2180df23279a7b16f986a979516f38902f /src/couchdb | |
parent | 5385dee622f39df1110bdca76e2a1b1c3bd5540c (diff) |
Merged revision 1156360 from trunk
Prevent data loss on db creation request
1) Create and populate a database
2) Restart the server
3) Send a PUT request to create the database - the server
will override the existing file, making all previous
documents no longer accessible nor recoverable
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1156361 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r-- | src/couchdb/couch_server.erl | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index 7870d69e..b9503d2f 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -314,11 +314,13 @@ handle_call({open, DbName, Options}, {FromPid,_}=From, Server) -> {reply, couch_db:open_ref_counted(MainPid, FromPid), Server} end; handle_call({create, DbName, Options}, From, Server) -> - case ets:lookup(couch_dbs_by_name, DbName) of - [] -> - open_db(DbName, Server, [create | Options], From); - [_AlreadyRunningDb] -> - {reply, file_exists, Server} + FileName = get_full_filename(Server, ?b2l(DbName)), + case file:open(FileName, [read]) of + {ok, Fd} -> + ok = file:close(Fd), + {reply, file_exists, Server}; + Error -> + open_db(DbName, Server, [create | Options], From) end; handle_call({delete, DbName, _Options}, _From, Server) -> DbNameList = binary_to_list(DbName), |