void SG_vfile__remove( SG_context* pCtx, const SG_pathname* pPath, /**< The path of the file containing the JSON text */ const char* putf8Key ) { SG_vfile* pvf = NULL; SG_vhash* pvh = NULL; SG_ERR_CHECK( SG_vfile__begin(pCtx, pPath, SG_FILE_RDWR | SG_FILE_OPEN_OR_CREATE, &pvh, &pvf) ); if (pvh) { SG_ERR_CHECK( SG_vhash__remove(pCtx, pvh, putf8Key) ); } else { SG_ERR_THROW(SG_ERR_VHASH_KEYNOTFOUND); } SG_ERR_CHECK( SG_vfile__end(pCtx, &pvf, pvh) ); SG_VHASH_NULLFREE(pCtx, pvh); return; fail: SG_ERR_IGNORE( sg_vfile__dispose(pCtx, pvf) ); SG_VHASH_NULLFREE(pCtx, pvh); }
void SG_repo__db__calc_delta_from_root( SG_context * pCtx, SG_repo* pRepo, SG_uint64 dagnum, const char* psz_csid_to, SG_uint32 flags, SG_vhash** ppvh ) { SG_varray* pva_direct_forward_path = NULL; SG_vhash* pvh_add = NULL; SG_vhash* pvh_remove = NULL; SG_NULLARGCHECK_RETURN(psz_csid_to); SG_NULLARGCHECK_RETURN(pRepo); SG_NULLARGCHECK_RETURN(ppvh); SG_ERR_CHECK( SG_repo__dag__find_direct_path_from_root( pCtx, pRepo, dagnum, psz_csid_to, &pva_direct_forward_path ) ); if (pva_direct_forward_path) { SG_uint32 count_remove = 0; SG_ERR_CHECK( SG_VHASH__ALLOC(pCtx, &pvh_add) ); SG_ERR_CHECK( SG_VHASH__ALLOC(pCtx, &pvh_remove) ); SG_ERR_CHECK( SG_db__make_delta_from_path( pCtx, pRepo, dagnum, pva_direct_forward_path, flags, pvh_remove, pvh_add ) ); SG_ERR_CHECK( SG_vhash__count(pCtx, pvh_remove, &count_remove) ); if (count_remove) { SG_uint32 i = 0; // TODO it would be nice to have a batch remove so vhash would only have to rehash once for (i=0; i<count_remove; i++) { const char* psz = NULL; SG_ERR_CHECK( SG_vhash__get_nth_pair(pCtx, pvh_remove, i, &psz, NULL) ); SG_ERR_CHECK( SG_vhash__remove(pCtx, pvh_add, psz) ); } } } *ppvh = pvh_add; pvh_add = NULL; fail: SG_VHASH_NULLFREE(pCtx, pvh_add); SG_VHASH_NULLFREE(pCtx, pvh_remove); SG_VARRAY_NULLFREE(pCtx, pva_direct_forward_path); }