@@ -311,36 +311,40 @@ sync(FromStore, ToStore) ->
311311 FromStoreOpts = maps :put (<<" resolve" >>, false , FromStore ),
312312 {ok , Entries } = hb_store :list (FromStore , <<" /" >>),
313313 ValidEntries = lists :filter (fun (Key ) -> Key =/= <<" lmdb" >> end , Entries ),
314- case sync_entries (ValidEntries , <<" " >>, FromStoreOpts , ToStore ) of
314+ case sync_entries (ValidEntries , <<" / " >>, FromStoreOpts , ToStore ) of
315315 [] -> ok ;
316316 FailedKeyValues -> {error , {sync_failed , FailedKeyValues }}
317317 end .
318318
319319sync_entries (Entries , ParentDir , FromStore , ToStore ) ->
320320 ? event ({sync_entries , ParentDir , Entries }),
321321 lists :foldl (fun (Key , Acc ) ->
322- Path = <<ParentDir /binary , " /" , Key /binary >>,
323- case type (FromStore , Path ) of
322+ NewPath =
323+ case ParentDir of
324+ Bin when Bin == <<" " >> orelse Bin == <<" /" >> -> Key ;
325+ _ -> <<ParentDir /binary , " /" , Key /binary >>
326+ end ,
327+ case type (FromStore , NewPath ) of
324328 Type when Type == simple orelse Type == link ->
325- case hb_store :read (FromStore , Path ) of
329+ case hb_store :read (FromStore , NewPath ) of
326330 {ok , Value } when Type == simple ->
327- case hb_store :write (ToStore , Path , Value ) of
331+ case hb_store :write (ToStore , NewPath , Value ) of
328332 ok -> Acc ;
329- _Error -> [{Path , Value } | Acc ]
333+ _Error -> [{NewPath , Value } | Acc ]
330334 end ;
331335 {ok , LinkTarget } when Type == link ->
332- ok = hb_store :make_link (ToStore , LinkTarget , Path ),
336+ ok = hb_store :make_link (ToStore , LinkTarget , NewPath ),
333337 Acc ;
334338 _Error ->
335- [{Path , undefined } | Acc ]
339+ [{NewPath , undefined } | Acc ]
336340 end ;
337341 composite ->
338- case hb_store :make_group (ToStore , Path ) of
342+ case hb_store :make_group (ToStore , NewPath ) of
339343 ok ->
340- {ok , Entries2 } = hb_store :list (FromStore , Path ),
341- Acc ++ sync_entries (Entries2 , Path , FromStore , ToStore );
344+ {ok , Entries2 } = hb_store :list (FromStore , NewPath ),
345+ Acc ++ sync_entries (Entries2 , NewPath , FromStore , ToStore );
342346 _Error ->
343- [{Path , undefined } | Acc ]
347+ [{NewPath , undefined } | Acc ]
344348 end ;
345349 not_found ->
346350 Acc
0 commit comments