anchor.diff:           mark_pending_delete/2,
            mark_scheduled_delete/2,
            pending_delete_manifests/1,
  -         prune/1,
  -         prune/2,
            upgrade_wrapped_manifests/1,
            upgrade_manifest/1]).
   
  
positive.code: pending_delete_manifest(_) ->
      false.
  
  seconds_diff(T2, T1) ->
      TimeDiffMicrosends = timer:now_diff(T2, T1),
      SecondsTime = TimeDiffMicrosends / (1000 * 1000),
      erlang:trunc(SecondsTime).
  
  %% ===================================================================
  %% EUnit tests
  %% ===================================================================
  -ifdef(TEST).
  
  new_mani_helper() ->
      riak_moss_lfs_utils:new_manifest(<<"bucket">>,
          <<"key">>,
          <<"uuid">>,
          100, %% content-length
          <<"ctype">>,
          undefined, %% md5
          orddict:new(),
          10,
          undefined).
  
  manifest_test_() ->
      {setup,
          fun setup/0,
          fun cleanup/1,
          [fun wrong_state_for_pruning/0,
           fun wrong_state_for_pruning_2/0,
           fun does_need_pruning/0,
           fun not_old_enough_for_pruning/0]
      }.
  
  setup() ->
      ok.
  
  cleanup(_Ctx) ->
      ok.
  
  wrong_state_for_pruning() ->
      Mani = new_mani_helper(),
      Mani2 = Mani?MANIFEST{state=active},
      ?assert(not needs_pruning(Mani2, erlang:now())).
  
  wrong_state_for_pruning_2() ->
      Mani = new_mani_helper(),
      Mani2 = Mani?MANIFEST{state=pending_delete},
      ?assert(not needs_pruning(Mani2, erlang:now())).
  
  does_need_pruning() ->
      application:set_env(riak_moss, leeway_seconds, 1),
      %% 1000000 second diff
      ScheduledDeleteTime = {1333,985708,445136},
      Now = {1334,985708,445136},
      Mani = new_mani_helper(),
      Mani2 = Mani?MANIFEST{state=scheduled_delete,
                                  scheduled_delete_time=ScheduledDeleteTime},
      ?assert(needs_pruning(Mani2, Now)).
  
  not_old_enough_for_pruning() ->
      application:set_env(riak_moss, leeway_seconds, 2),
      %$ 1 second diff
      ScheduledDeleteTime = {1333,985708,445136},
      Now = {1333,985709,445136},
      Mani = new_mani_helper(),
      Mani2 = Mani?MANIFEST{state=scheduled_delete,
                                  scheduled_delete_time=ScheduledDeleteTime},
      ?assert(not needs_pruning(Mani2, Now)).
  
  -endif.
  
negative.code: pending_delete_manifests(Manifests) ->
      lists:filter(fun pending_delete_manifest/1, Manifests).
  
  upgrade_wrapped_manifests(ListofOrdDicts) ->
      DictMapFun = fun (_Key, Value) -> upgrade_manifest(Value) end,
      MapFun = fun (Value) -> orddict:map(DictMapFun, Value) end,
  