anchor.diff:  %% Internal functions
   %% ===================================================================
   
  +%% @spec atomic_write(File :: string(), Val :: binary()) ->
  +%%       ok | {error, Reason :: term()}
  +%% @doc store a atomic value to disk. Write to temp file and rename to
  +%%       normal path.
  +atomic_write(File, Val) ->
  +    FakeFile = File ++ ".tmpwrite",
  +    case file:write_file(FakeFile, pack_ondisk(Val)) of
  +        ok ->
  +            file:rename(FakeFile, File);
  +        X -> X
  +    end.
  +
  +%% @private
  +%% Fold over the keys and objects on this backend
  +fold(State, Fun0, Acc) ->
  +    Fun = fun(BKey, AccIn) ->
  +                  {Bucket, Key} = BKey,
  +                  case get(Bucket, Key, State) of
  +                      {ok, Bin, _} ->
  +                          Fun0(BKey, Bin, AccIn);
  +                      _ ->
  +                          AccIn
  +                  end
  +          end,
  +    lists:foldl(Fun, Acc, list(State)).
  +
   %% @private
   %% Return a function to fold over the buckets on this backend
   fold_buckets_fun(FoldBucketsFun) ->
  -    fun(Location, {Acc, BucketSet}) ->
  -            %% {Bucket, _} = location_to_bkey(Location),
  -            {Bucket, _} = Location,
  -
  +    fun(BKey, {Acc, BucketSet}) ->
  +            {Bucket, _} = BKey,
               case sets:is_element(Bucket, BucketSet) of
                   true ->
                       {Acc, BucketSet};
  
positive.code:             end
      end.
  
  %% %% @private
  %% %% Return a function to fold over keys on this backend
  %% fold_keys_fun(FoldKeysFun, undefined) ->
  %%     %% Fold across everything...
  %%     fun(StorageKey, Acc) ->
  %%             case from_object_key(StorageKey) of
  %%                 {Bucket, Key} ->
  %%                     FoldKeysFun(Bucket, Key, Acc);
  %%                 _ ->
  %%                     throw({break, Acc})
  %%             end
  %%     end;
  %% fold_keys_fun(FoldKeysFun, {bucket, FilterBucket}) ->
  %%     %% Fold across a specific bucket...
  %%     fun(StorageKey, Acc) ->
  %%             case from_object_key(StorageKey) of
  %%                 {Bucket, Key} when Bucket == FilterBucket ->
  %%                     FoldKeysFun(Bucket, Key, Acc);
  %%                 _ ->
  %%                     throw({break, Acc})
  %%             end
  %%     end;
  %% fold_keys_fun(FoldKeysFun, {index, FilterBucket, {eq, <<"$bucket">>, _}}) ->
  %%     %% 2I exact match query on special $bucket field...
  %%     fold_keys_fun(FoldKeysFun, {bucket, FilterBucket});
  %% fold_keys_fun(FoldKeysFun, {index, FilterBucket, {eq, FilterField, FilterTerm}}) ->
  %%     %% Rewrite 2I exact match query as a range...
  %%     NewQuery = {range, FilterField, FilterTerm, FilterTerm},
  %%     fold_keys_fun(FoldKeysFun, {index, FilterBucket, NewQuery});
  %% fold_keys_fun(FoldKeysFun, {index, FilterBucket, {range, <<"$key">>, StartKey, EndKey}}) ->
  %%     %% 2I range query on special $key field...
  %%     fun(StorageKey, Acc) ->
  %%             case from_object_key(StorageKey) of
  %%                 {Bucket, Key} when FilterBucket == Bucket,
  %%                                    StartKey =< Key,
  %%                                    EndKey >= Key ->
  %%                     FoldKeysFun(Bucket, Key, Acc);
  %%                 _ ->
  %%                     throw({break, Acc})
  %%             end
  %%     end;
  %% fold_keys_fun(FoldKeysFun, {index, FilterBucket, {range, FilterField, StartTerm, EndTerm}}) ->
  %%     %% 2I range query...
  %%     fun(StorageKey, Acc) ->
  %%             case from_index_key(StorageKey) of
  %%                 {Bucket, Key, Field, Term} when FilterBucket == Bucket,
  %%                                                 FilterField == Field,
  %%                                                 StartTerm =< Term,
  %%                                                 EndTerm >= Term ->
  %%                     FoldKeysFun(Bucket, Key, Acc);
  %%                 _ ->
  %%                     throw({break, Acc})
  %%             end
  %%     end;
  %% fold_keys_fun(_FoldKeysFun, Other) ->
  %%     throw({unknown_limiter, Other}).
  
  %% %% @private
  %% %% Return a function to fold over the objects on this backend
  %% fold_objects_fun(FoldObjectsFun, FilterBucket) ->
  %%     %% 2I does not support fold objects at this time, so this is much
  %%     %% simpler than fold_keys_fun.
  %%     fun({StorageKey, Value}, Acc) ->
  %%             case from_object_key(StorageKey) of
  %%                 {Bucket, Key} when FilterBucket == undefined;
  %%                                    Bucket == FilterBucket ->
  %%                     FoldObjectsFun(Bucket, Key, Value, Acc);
  %%                 _ ->
  %%                     throw({break, Acc})
  %%             end
  %%     end.
  
  
  %% @spec location(state(), {riak_object:bucket(), riak_object:key()})
  %%          -> string()
  
negative.code:         {error, Err} -> {error, Err, State}
      end.
  
  %% @doc Fold over all the buckets.
  -spec fold_buckets(riak_kv_backend:fold_buckets_fun(),
                     any(),
                     [],
                     state()) -> {ok, any()} | {async, fun()} | {error, term()}.
  fold_buckets(FoldBucketsFun, Acc, Opts, State) ->
      FoldFun = fold_buckets_fun(FoldBucketsFun),
      BucketFolder =
          fun() ->
  