1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_piece_diskstate.erl
3 %%% Author : Jesper Louis Andersen <jlouis@ogre.home>
4 %%% Description : Manipulation of the #piece_diskstate table.
6 %%% Created : 16 Jul 2008 by Jesper Louis Andersen <jlouis@ogre.home>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_piece_diskstate
).
10 -include_lib("stdlib/include/qlc.hrl").
11 -include("etorrent_mnesia_table.hrl").
14 -export([new
/2, prune
/1, select
/1]).
16 %%====================================================================
18 %%====================================================================
19 %%--------------------------------------------------------------------
22 %%--------------------------------------------------------------------
24 %%--------------------------------------------------------------------
25 %% Function: new/2 -> ok
26 %% Args: Filename ::= string() (filename of torrent)
27 %% State ::= seeding | {bitfield, BF}
29 %% BF ::= binary() (bitfield)
30 %% Description: Add/Update the Filenames persistent disk state
31 %%--------------------------------------------------------------------
32 new(Filename
, State
) ->
33 mnesia:dirty_write(#piece_diskstate
{ filename
= Filename
,
36 %%--------------------------------------------------------------------
37 %% Function: prune/1 -> ok
38 %% Args: Filenames ::= set() (of filenames)
39 %% Description: Prune the table for any entry not in the FN set.
40 %%--------------------------------------------------------------------
45 Q
= qlc:q([E#piece_diskstate
.filename
46 || E
<- mnesia:table(piece_diskstate
),
47 sets:is_element(E#piece_diskstate
.filename
,
51 lists:foreach(fun (T
) -> mnesia:dirty_delete(piece_diskstate
, T
) end,
55 %%--------------------------------------------------------------------
57 %% Args: Filename ::= string()
58 %% Description: Select the row matching the filename
59 %%--------------------------------------------------------------------
61 mnesia:dirty_read(piece_diskstate
, FN
).
63 %%====================================================================
65 %%====================================================================