Handle HAVE_ALL and HAVE_NONE. Cleanup the BITFIELD message.
[etorrent.git] / lib / etorrent-1.0 / src / etorrent_path_map.erl
blobf0148b33570a30e2a2720554bcd1ed08961d591b
1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_path_map.erl
3 %%% Author : Jesper Louis Andersen <>
4 %%% Description : Manipulate the #path_map table
5 %%%
6 %%% Created : 6 Jul 2008 by Jesper Louis Andersen <>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_path_map).
10 -include_lib("stdlib/include/qlc.hrl").
11 -include("etorrent_mnesia_table.hrl").
13 %% API
14 -export([select/2, delete/1]).
16 %%====================================================================
17 %% API
18 %%====================================================================
19 %%--------------------------------------------------------------------
20 %% Function: select(Path) -> Id,
21 %% select(Id) -> Path
22 %% Description: Bi-directionally lookup on {Path, Id} pairs. If a non-
23 %% exsisting path is selected, we add it as a side-effect
24 %%--------------------------------------------------------------------
25 select(Id, TorrentId) when is_integer(Id) ->
26 [R] = mnesia:dirty_read(path_map, {Id, TorrentId}),
28 select(Path, TorrentId) when is_list(Path) ->
29 case mnesia:dirty_index_read(path_map, Path, #path_map.path) of
30 [] ->
31 Id = etorrent_counters:next(path_map),
32 ok = mnesia:dirty_write(#path_map{ id = {Id, TorrentId},
33 path = Path}),
34 Id;
35 [R] ->
36 {Id, _TorrentId} = R#path_map.id,
38 end.
40 %%--------------------------------------------------------------------
41 %% Function: delete(TorrentId) -> ok
42 %% Description: Delete entries from the pathmap based on the TorrentId
43 %%--------------------------------------------------------------------
44 delete(TorrentId) when is_integer(TorrentId) ->
45 MatchHead = #path_map { id = {'_', TorrentId}, _ = '_' },
46 lists:foreach(fun(Obj) -> mnesia:dirty_delete_object(Obj) end,
47 mnesia:dirty_select(path_map, [{MatchHead, [], ['$_']}])),
48 ok.
50 %%====================================================================
51 %% Internal functions
52 %%====================================================================