anchor.diff:      ]).
   
   -define(TIMEOUT, 10 * 1000).
  +-include("machi_projection.hrl"). %% included for pv1_epoch_n type
   
   -record(state, {fluname :: atom(),
                   tid     :: ets:tid(),
  -                datadir :: file:dir()
  +                datadir :: file:dir(),
  +                epoch   :: pv1_epoch_n()
                  }).
   
   %% public API
  
positive.code:     N = make_filename_mgr_name(FluName),
      gen_server:start_link({local, N}, ?MODULE, [FluName, DataDir], []).
  
  -spec find_or_make_filename_from_prefix( FluName :: atom(), Prefix :: {prefix, string()} ) ->
          {file, Filename :: string()} | {error, Reason :: term() } | timeout.
  % @doc Find the latest available or make a filename from a prefix. A prefix
  % should be in the form of a tagged tuple `{prefix, P}'. Returns a tagged
  % tuple in the form of `{file, F}' or an `{error, Reason}'
  find_or_make_filename_from_prefix(FluName, {prefix, Prefix}) when is_atom(FluName) ->
      N = make_filename_mgr_name(FluName),
      gen_server:call(N, {find_filename, Prefix}, ?TIMEOUT); 
  find_or_make_filename_from_prefix(_FluName, Other) ->
      lager:error("~p is not a valid prefix.", [Other]),
      error(badarg).
  
  
negative.code: maybe_cleanup(Tid, Key, true) ->
      true = ets:delete(Tid, Key).
  
  increment_and_cache_filename(Tid, DataDir, Prefix) ->
      ok = machi_util:increment_max_filenum(DataDir, Prefix),
      N = machi_util:read_max_filenum(DataDir, Prefix),
      F = generate_filename(DataDir, Prefix, N),
      true = ets:insert_new(Tid, {{Prefix, N}, F}),
      filename:basename(F).
  
  
  
  -ifdef(TEST).
  
  