void SG_vfile__update__string__sz( SG_context* pCtx, const SG_pathname* pPath, /**< The path of the file containing the JSON text */ const char* putf8Key, const char* pszVal ) { 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__ALLOC(pCtx, &pvh) ); } SG_ERR_CHECK( SG_vhash__update__string__sz(pCtx, pvh, putf8Key, pszVal) ); 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__unpack(SG_context* pCtx, SG_repo * pRepo, SG_blob_encoding blob_encoding) { SG_vhash* pvh = NULL; SG_uint32 count = 0; SG_uint32 i = 0; SG_repo_tx_handle* pTx; SG_ERR_CHECK( SG_repo__list_blobs(pCtx, pRepo, blob_encoding, SG_FALSE, SG_FALSE, 500, 0, &pvh) ); SG_ERR_CHECK( SG_vhash__count(pCtx, pvh, &count) ); for (i=0; i<count; i++) { const char* psz_hid = NULL; const SG_variant* pv = NULL; SG_ERR_CHECK( SG_vhash__get_nth_pair(pCtx, pvh, i, &psz_hid, &pv) ); // Not a lot of thought went into doing each of these in its own repo tx. Consider alternatives. SG_ERR_CHECK( SG_repo__begin_tx(pCtx, pRepo, &pTx) ); SG_ERR_CHECK( SG_repo__change_blob_encoding(pCtx, pRepo, pTx, psz_hid, SG_BLOBENCODING__FULL, NULL, NULL, NULL, NULL, NULL) ); SG_ERR_CHECK( SG_repo__commit_tx(pCtx, pRepo, &pTx) ); } SG_VHASH_NULLFREE(pCtx, pvh); return; fail: SG_VHASH_NULLFREE(pCtx, pvh); }
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_workingdir__set_mapping( SG_context* pCtx, const SG_pathname* pPathLocalDirectory, const char* pszNameRepoInstanceDescriptor, /**< The name of the repo instance descriptor */ const char* pszidGidAnchorDirectory /**< The GID of the directory within the repo to which this is anchored. Usually it's user root. */ ) { SG_vhash* pvhNew = NULL; SG_vhash* pvh = NULL; SG_pathname* pMyPath = NULL; SG_pathname* pDrawerPath = NULL; SG_pathname* pMappingFilePath = NULL; SG_NULLARGCHECK_RETURN(pPathLocalDirectory); SG_NULLARGCHECK_RETURN(pszNameRepoInstanceDescriptor); /* make a copy of the path so we can modify it (adding the final slash) */ SG_ERR_CHECK( SG_PATHNAME__ALLOC__COPY(pCtx, &pMyPath, pPathLocalDirectory) ); /* null the original parameter pointer to make sure we don't use it anymore */ pPathLocalDirectory = NULL; /* make sure the path we were given is a directory that exists */ SG_ERR_CHECK( SG_fsobj__verify_directory_exists_on_disk__pathname(pCtx, pMyPath) ); /* it's a directory, so it should have a final slash */ SG_ERR_CHECK( SG_pathname__add_final_slash(pCtx, pMyPath) ); /* make sure the name of the repo instance descriptor is valid */ SG_ERR_CHECK( SG_closet__descriptors__get(pCtx, pszNameRepoInstanceDescriptor, &pvh) ); SG_VHASH_NULLFREE(pCtx, pvh); // TODO verify that the anchor GID is valid for that repo? SG_ERR_CHECK( SG_VHASH__ALLOC(pCtx, &pvhNew) ); SG_ERR_CHECK( SG_vhash__add__string__sz(pCtx, pvhNew, "descriptor", pszNameRepoInstanceDescriptor) ); SG_ERR_CHECK( SG_vhash__add__string__sz(pCtx, pvhNew, "anchor", pszidGidAnchorDirectory) ); SG_ERR_CHECK( SG_workingdir__verify_drawer_exists(pCtx, pMyPath, &pDrawerPath) ); SG_ERR_CHECK( SG_PATHNAME__ALLOC__PATHNAME_SZ(pCtx, &pMappingFilePath, pDrawerPath, "repo.json") ); SG_ERR_CHECK( SG_vfile__update__vhash(pCtx, pMappingFilePath, "mapping", pvhNew) ); SG_VHASH_NULLFREE(pCtx, pvhNew); SG_PATHNAME_NULLFREE(pCtx, pMyPath); SG_PATHNAME_NULLFREE(pCtx, pDrawerPath); SG_PATHNAME_NULLFREE(pCtx, pMappingFilePath); return; fail: SG_PATHNAME_NULLFREE(pCtx, pDrawerPath); SG_PATHNAME_NULLFREE(pCtx, pMappingFilePath); SG_PATHNAME_NULLFREE(pCtx, pMyPath); SG_VHASH_NULLFREE(pCtx, pvhNew); SG_VHASH_NULLFREE(pCtx, pvh); }
static void _add_dagnodes_until_connected(SG_context* pCtx, SG_vhash** ppvhStagingStatus, sg_pull_instance_data* pMe, SG_client* pClient) { SG_bool disconnected = SG_FALSE; SG_vhash* pvhFragballRequest = NULL; char* pszFragballName = NULL; SG_vhash* pvhRequestStatus = NULL; const SG_pathname* pStagingPathname; SG_ERR_CHECK( SG_staging__get_pathname(pCtx, pMe->pStaging, &pStagingPathname) ); SG_ERR_CHECK( SG_vhash__has(pCtx, *ppvhStagingStatus, SG_SYNC_STATUS_KEY__DAGS, &disconnected) ); while (disconnected) { #if TRACE_PULL SG_ERR_CHECK( SG_vhash_debug__dump_to_console__named(pCtx, *ppvhStagingStatus, "pull staging status") ); #endif // There's at least one dag with connection problems. // Convert the staging status vhash into a fragball request vhash. pvhFragballRequest = *ppvhStagingStatus; *ppvhStagingStatus = NULL; SG_ERR_CHECK( SG_vhash__add__int64(pCtx, pvhFragballRequest, SG_SYNC_STATUS_KEY__GENERATIONS, GENERATIONS_PER_ROUNDTRIP) ); SG_ERR_CHECK( SG_client__pull_request_fragball(pCtx, pClient, pvhFragballRequest, pStagingPathname, &pszFragballName, &pvhRequestStatus) ); /* Ian TODO: inspect pvhRequestStatus */ SG_VHASH_NULLFREE(pCtx, pvhRequestStatus); SG_VHASH_NULLFREE(pCtx, pvhFragballRequest); SG_ERR_CHECK( SG_staging__slurp_fragball(pCtx, pMe->pStaging, (const char*)pszFragballName) ); SG_NULLFREE(pCtx, pszFragballName); SG_ERR_CHECK( SG_staging__check_status(pCtx, pMe->pStaging, SG_TRUE, SG_FALSE, SG_FALSE, SG_FALSE, SG_FALSE, ppvhStagingStatus) ); SG_ERR_CHECK( SG_vhash__has(pCtx, *ppvhStagingStatus, SG_SYNC_STATUS_KEY__DAGS, &disconnected) ); #if TRACE_PULL SG_ERR_CHECK( SG_vhash_debug__dump_to_console__named(pCtx, *ppvhStagingStatus, "pull staging status") ); #endif } SG_ERR_CHECK_RETURN( SG_context__msg__emit(pCtx, "done") ); /* fall through */ fail: SG_VHASH_NULLFREE(pCtx, *ppvhStagingStatus); SG_VHASH_NULLFREE(pCtx, pvhFragballRequest); SG_NULLFREE(pCtx, pszFragballName); SG_VHASH_NULLFREE(pCtx, pvhRequestStatus); SG_ERR_IGNORE( SG_context__msg__emit(pCtx, "\n") ); }
void SG_sync__compare_repo_blobs(SG_context* pCtx, SG_repo* pRepo1, SG_repo* pRepo2, SG_bool* pbIdentical) { const SG_uint32 chunk_size = 1000; SG_vhash* pvh = NULL; const char* pszBlob1 = NULL; SG_uint32 i, j; SG_uint32 count_observed = 0; SG_uint32 count_returned; SG_NULLARGCHECK_RETURN(pRepo1); SG_NULLARGCHECK_RETURN(pRepo2); SG_NULLARGCHECK_RETURN(pbIdentical); for(i = 0; SG_TRUE; i++) { // Ian TODO: other encodings SG_ERR_CHECK( SG_repo__list_blobs(pCtx, pRepo1, SG_BLOBENCODING__ZLIB, SG_FALSE, SG_FALSE, chunk_size, chunk_size * i, &pvh) ); for (j = 0; j < chunk_size; j++) { SG_bool b = SG_TRUE; SG_vhash__get_nth_pair(pCtx, pvh, j, &pszBlob1, NULL); if (SG_context__err_equals(pCtx, SG_ERR_ARGUMENT_OUT_OF_RANGE)) { SG_context__err_reset(pCtx); break; } SG_ERR_CHECK_CURRENT; SG_ERR_CHECK( SG_repo__does_blob_exist(pCtx, pRepo2, pszBlob1, &b) ); if (!b) { *pbIdentical = SG_FALSE; break; } count_observed++; } if (!j) break; SG_VHASH_NULLFREE(pCtx, pvh); } SG_ERR_CHECK( SG_repo__get_blob_stats(pCtx, pRepo2, NULL, NULL, &count_returned, NULL, NULL, NULL, NULL, NULL, NULL, NULL) ); if (count_returned != count_observed) *pbIdentical = SG_FALSE; // fall through fail: SG_VHASH_NULLFREE(pCtx, pvh); }
static void _add_blobs_until_done(SG_context* pCtx, SG_staging* pStaging, SG_client* pClient) { SG_bool need_blobs = SG_FALSE; SG_vhash* pvhFragballRequest = NULL; char* pszFragballName = NULL; SG_vhash* pvhRequestStatus = NULL; const SG_pathname* pStagingPathname = NULL; SG_vhash* pvhStagingStatus = NULL; SG_ERR_CHECK_RETURN( SG_context__msg__emit(pCtx, "Retrieving blobs...") ); SG_ERR_CHECK( SG_staging__check_status(pCtx, pStaging, SG_FALSE, SG_FALSE, SG_FALSE, SG_TRUE, SG_TRUE, &pvhStagingStatus) ); SG_ERR_CHECK( SG_vhash__has(pCtx, pvhStagingStatus, SG_SYNC_STATUS_KEY__BLOBS, &need_blobs) ); if (need_blobs) SG_ERR_CHECK( SG_staging__get_pathname(pCtx, pStaging, &pStagingPathname) ); while (need_blobs) { pvhFragballRequest = pvhStagingStatus; pvhStagingStatus = NULL; SG_ERR_CHECK( SG_client__pull_request_fragball(pCtx, pClient, pvhFragballRequest, pStagingPathname, &pszFragballName, &pvhRequestStatus) ); /* Ian TODO: inspect pvhRequestStatus */ SG_VHASH_NULLFREE(pCtx, pvhRequestStatus); SG_VHASH_NULLFREE(pCtx, pvhFragballRequest); SG_ERR_CHECK( SG_staging__slurp_fragball(pCtx, pStaging, (const char*)pszFragballName) ); SG_NULLFREE(pCtx, pszFragballName); SG_ERR_CHECK( SG_staging__check_status(pCtx, pStaging, SG_FALSE, SG_FALSE, SG_FALSE, SG_TRUE, SG_TRUE, &pvhStagingStatus) ); #if TRACE_PULL SG_ERR_CHECK( SG_vhash_debug__dump_to_console__named(pCtx, pvhStagingStatus, "pull staging status") ); #endif SG_ERR_CHECK( SG_vhash__has(pCtx, pvhStagingStatus, SG_SYNC_STATUS_KEY__BLOBS, &need_blobs) ); } SG_ERR_CHECK_RETURN( SG_context__msg__emit(pCtx, "done") ); /* fall through */ fail: SG_VHASH_NULLFREE(pCtx, pvhStagingStatus); SG_VHASH_NULLFREE(pCtx, pvhFragballRequest); SG_NULLFREE(pCtx, pszFragballName); SG_VHASH_NULLFREE(pCtx, pvhRequestStatus); SG_ERR_IGNORE( SG_context__msg__emit(pCtx, "\n") ); }
void u0048_multidag__new_repo( SG_context * pCtx, const char* pszRidescName, SG_repo** ppResult ) { SG_vhash* pvhPartialDescriptor = NULL; SG_repo* pRepo = NULL; const SG_vhash* pvhActualDescriptor = NULL; SG_changeset* pcsFirst = NULL; char* pszidGidActualRoot = NULL; const char* pszidFirstChangeset = NULL; char buf_repo_id[SG_GID_BUFFER_LENGTH]; char buf_admin_id[SG_GID_BUFFER_LENGTH]; VERIFY_ERR_CHECK( SG_gid__generate(pCtx, buf_repo_id, sizeof(buf_repo_id)) ); VERIFY_ERR_CHECK( SG_gid__generate(pCtx, buf_admin_id, sizeof(buf_admin_id)) ); VERIFY_ERR_CHECK( SG_closet__get_partial_repo_instance_descriptor_for_new_local_repo(pCtx, &pvhPartialDescriptor) ); /* This test case writes dag nodes which are not real. They don't have a * changeset associated with them. So, if we use a caching repo, the * caching code will fail because it tries to load a changeset * which doesn't exist. So, we strip down to a raw repo here. */ VERIFY_ERR_CHECK( SG_repo__create_repo_instance(pCtx,pvhPartialDescriptor,SG_TRUE,NULL,buf_repo_id,buf_admin_id,&pRepo) ); VERIFY_ERR_CHECK( sg_zing__init_new_repo(pCtx, pRepo) ); VERIFY_ERR_CHECK( SG_repo__create_user_root_directory(pCtx, pRepo, "@", &pcsFirst, &pszidGidActualRoot) ); VERIFY_ERR_CHECK( SG_changeset__get_id_ref(pCtx, pcsFirst, &pszidFirstChangeset) ); VERIFY_ERR_CHECK( SG_repo__get_descriptor(pCtx, pRepo, &pvhActualDescriptor) ); /* TODO should this give an error if the ridesc name already exists? */ VERIFY_ERR_CHECK( SG_closet__descriptors__add(pCtx, pszRidescName, pvhActualDescriptor) ); SG_NULLFREE(pCtx, pszidGidActualRoot); SG_CHANGESET_NULLFREE(pCtx, pcsFirst); SG_VHASH_NULLFREE(pCtx, pvhPartialDescriptor); *ppResult = pRepo; return; fail: SG_VHASH_NULLFREE(pCtx, pvhPartialDescriptor); SG_REPO_NULLFREE(pCtx, pRepo); return; }
void SG_pull__all__list_incoming( SG_context* pCtx, const char* pszPullIntoRepoDescriptorName, SG_client* pClient, SG_varray** ppvaInfo) { sg_pull_instance_data* pMe = NULL; char* pszFragballName = NULL; SG_vhash* pvhStatus = NULL; // Used for both fragball request status returned by SG_client // and staging status returned by SG_staging. const SG_pathname* pStagingPathname; SG_NULLARGCHECK_RETURN(pszPullIntoRepoDescriptorName); SG_NULLARGCHECK_RETURN(pClient); SG_ERR_CHECK( _pull_init(pCtx, pClient, pszPullIntoRepoDescriptorName, &pMe) ); SG_ERR_CHECK( SG_staging__get_pathname(pCtx, pMe->pStaging, &pStagingPathname) ); /* Request a fragball containing leaves of every dag */ SG_ERR_CHECK_RETURN( SG_context__msg__emit(pCtx, "Retrieving dagnodes...") ); SG_ERR_CHECK( SG_client__pull_request_fragball(pCtx, pClient, NULL, pStagingPathname, &pszFragballName, &pvhStatus) ); /* Ian TODO: inspect pvhStatus */ SG_ERR_CHECK( SG_VHASH_NULLFREE(pCtx, pvhStatus) ); SG_ERR_CHECK( SG_staging__slurp_fragball(pCtx, pMe->pStaging, pszFragballName) ); SG_ERR_CHECK( SG_staging__check_status(pCtx, pMe->pStaging, SG_TRUE, SG_FALSE, SG_FALSE, SG_FALSE, SG_FALSE, &pvhStatus) ); /* Check the status and use it to request more dagnodes until the dags connect */ SG_ERR_CHECK( _add_dagnodes_until_connected(pCtx, &pvhStatus, pMe, pClient) ); SG_ERR_CHECK( SG_VHASH_NULLFREE(pCtx, pvhStatus) ); SG_ERR_CHECK( SG_staging__check_status(pCtx, pMe->pStaging, SG_FALSE, SG_FALSE, SG_TRUE, SG_FALSE, SG_FALSE, &pvhStatus) ); { SG_bool b = SG_FALSE; SG_vhash* pvhRequest = NULL; SG_ERR_CHECK( SG_vhash__has(pCtx, pvhStatus, SG_SYNC_STATUS_KEY__NEW_NODES, &b) ); if (b) { /* There are incoming nodes. Get their info. */ SG_ERR_CHECK( SG_vhash__get__vhash(pCtx, pvhStatus, SG_SYNC_STATUS_KEY__NEW_NODES, &pvhRequest) ); SG_ERR_CHECK( SG_client__get_dagnode_info(pCtx, pClient, pvhRequest, ppvaInfo) ); } } /* fall through */ fail: _NULLFREE_INSTANCE_DATA(pCtx, pMe); SG_VHASH_NULLFREE(pCtx, pvhStatus); SG_NULLFREE(pCtx, pszFragballName); }
void SG_vc_hooks__ASK__WIT__LIST_ITEMS( SG_context* pCtx, SG_repo* pRepo, const char * psz_search_term, SG_varray *pBugs ) { SG_vhash* pvh_params = NULL; SG_vhash* pvh_result = NULL; SG_vhash* pvh_hook = NULL; const char* psz_js = NULL; const char* psz_descriptor_name = NULL; SG_bool hasBugs = SG_FALSE; SG_ERR_CHECK( sg_vc_hooks__lookup_by_interface__single_result( pCtx, pRepo, SG_VC_HOOK__INTERFACE__ASK__WIT__LIST_ITEMS, &pvh_hook ) ); if (!pvh_hook) return; SG_ERR_CHECK( SG_vhash__get__sz(pCtx, pvh_hook, "js", &psz_js) ); SG_ERR_CHECK( SG_VHASH__ALLOC(pCtx, &pvh_params) ); SG_ERR_CHECK( SG_repo__get_descriptor_name(pCtx, pRepo, &psz_descriptor_name) ); SG_ERR_CHECK( SG_vhash__add__string__sz(pCtx, pvh_params, "descriptor_name", psz_descriptor_name) ); SG_ERR_CHECK( SG_vhash__add__string__sz(pCtx, pvh_params, "text", psz_search_term) ); SG_ERR_CHECK( SG_vc_hooks__execute(pCtx, psz_js, pvh_params, &pvh_result) ); SG_ERR_CHECK( SG_vhash__has(pCtx, pvh_result, "items", &hasBugs) ); if (hasBugs && pBugs) { SG_varray *bugs = NULL; SG_ERR_CHECK( SG_vhash__get__varray(pCtx, pvh_result, "items", &bugs) ); SG_ERR_CHECK( SG_varray__copy_items(pCtx, bugs, pBugs) ); } fail: SG_VHASH_NULLFREE(pCtx, pvh_params); SG_VHASH_NULLFREE(pCtx, pvh_result); SG_VHASH_NULLFREE(pCtx, pvh_hook); }
void SG_vfile__update__varray(SG_context* pCtx, const SG_pathname* pPath, const char* putf8Key, SG_varray ** ppValue) { 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__ALLOC(pCtx, &pvh) ); SG_ERR_CHECK( SG_vhash__update__varray(pCtx, pvh, putf8Key, ppValue) ); 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); }
/** * List the hashes supported by each repo implementation. * * NOTE: I don't have a way to verify that the list is complete or verify * NOTE: what it should contain, so I just print the list. */ void MyFn(list_hashes)(SG_context * pCtx) { SG_repo * pRepo = NULL; SG_vhash * pvh_vtables = NULL; SG_vhash * pvh_HashMethods = NULL; SG_uint32 k, count_vtables; VERIFY_ERR_CHECK( SG_repo__query_implementation(pCtx,NULL, SG_REPO__QUESTION__VHASH__LIST_REPO_IMPLEMENTATIONS, NULL,NULL,NULL,0, &pvh_vtables) ); VERIFY_ERR_CHECK( SG_vhash__count(pCtx,pvh_vtables,&count_vtables) ); for (k=0; k<count_vtables; k++) { const char * pszKey_vtable_k; SG_uint32 j, count_HashMethods; VERIFY_ERR_CHECK( SG_vhash__get_nth_pair(pCtx,pvh_vtables,k,&pszKey_vtable_k,NULL) ); INFOP("vtable",("Repo Implementation[%d]: [%s]",k,pszKey_vtable_k)); VERIFY_ERR_CHECK( SG_repo__alloc(pCtx,&pRepo,pszKey_vtable_k) ); VERIFY_ERR_CHECK( SG_repo__query_implementation(pCtx,pRepo, SG_REPO__QUESTION__VHASH__LIST_HASH_METHODS, NULL,NULL,NULL,0, &pvh_HashMethods) ); VERIFY_ERR_CHECK( SG_vhash__count(pCtx,pvh_HashMethods,&count_HashMethods) ); for (j=0; j<count_HashMethods; j++) { const char * pszKey_HashMethod_j; const SG_variant * pVariant; SG_int64 i64; SG_uint32 strlen_Hash_j; VERIFY_ERR_CHECK( SG_vhash__get_nth_pair(pCtx,pvh_HashMethods,j,&pszKey_HashMethod_j,&pVariant) ); VERIFY_ERR_CHECK( SG_variant__get__int64(pCtx,pVariant,&i64) ); strlen_Hash_j = (SG_uint32)i64; INFOP("vtable.hash_method",("Repo [%s] Hash [%s] Length [%d]",pszKey_vtable_k,pszKey_HashMethod_j,strlen_Hash_j)); } SG_VHASH_NULLFREE(pCtx, pvh_HashMethods); SG_REPO_NULLFREE(pCtx, pRepo); } fail: SG_VHASH_NULLFREE(pCtx, pvh_HashMethods); SG_REPO_NULLFREE(pCtx, pRepo); SG_VHASH_NULLFREE(pCtx, pvh_vtables); }
void u0038_test_wdmapping(SG_context * pCtx) { SG_vhash* pvh = NULL; SG_closet_descriptor_handle* ph = NULL; SG_pathname* pPath = NULL; SG_pathname* pMappedPath = NULL; SG_string* pstrRepoDescriptorName = NULL; char* pszidGid = NULL; char buf_tid[SG_TID_MAX_BUFFER_LENGTH]; VERIFY_ERR_CHECK_DISCARD( SG_tid__generate2__suffix(pCtx, buf_tid, sizeof(buf_tid), 32, "u0038") ); VERIFY_ERR_CHECK_DISCARD( SG_PATHNAME__ALLOC__SZ(pCtx, &pPath, buf_tid) ); VERIFY_ERR_CHECK_DISCARD( SG_fsobj__mkdir__pathname(pCtx, pPath) ); SG_ERR_IGNORE( SG_closet__descriptors__remove(pCtx, "r1") ); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__add_begin(pCtx, "r1", NULL, NULL, NULL, NULL, &pvh, &ph) ); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__add_commit(pCtx, &ph, pvh, SG_REPO_STATUS__NORMAL) ); SG_VHASH_NULLFREE(pCtx, pvh); VERIFY_ERR_CHECK_DISCARD( SG_workingdir__set_mapping(pCtx, pPath, "r1", NULL) ); VERIFY_ERR_CHECK_DISCARD( SG_workingdir__find_mapping(pCtx, pPath, &pMappedPath, &pstrRepoDescriptorName, &pszidGid) ); VERIFY_COND("ridesc match", (0 == strcmp("r1", SG_string__sz(pstrRepoDescriptorName)))); VERIFY_ERR_CHECK_DISCARD( SG_pathname__append__from_sz(pCtx, pPath, "foo") ); VERIFY_ERR_CHECK_DISCARD( SG_pathname__append__from_sz(pCtx, pPath, "bar") ); VERIFY_ERR_CHECK_DISCARD( SG_pathname__append__from_sz(pCtx, pPath, "plok") ); SG_STRING_NULLFREE(pCtx, pstrRepoDescriptorName); SG_PATHNAME_NULLFREE(pCtx, pMappedPath); VERIFY_ERR_CHECK_DISCARD( SG_workingdir__find_mapping(pCtx, pPath, &pMappedPath, &pstrRepoDescriptorName, &pszidGid) ); SG_STRING_NULLFREE(pCtx, pstrRepoDescriptorName); SG_PATHNAME_NULLFREE(pCtx, pMappedPath); SG_PATHNAME_NULLFREE(pCtx, pPath); }
void SG_user__get_email_for_repo(SG_context * pCtx, SG_repo* pRepo, const char ** ppsz_email) { char * psz_admin_id = NULL; char * psz_userid = NULL; const char * psz_email_temp = NULL; SG_string * pstr_path = NULL; SG_vhash * pvh_userhash = NULL; if (pRepo) { SG_ERR_CHECK( SG_repo__get_admin_id(pCtx, pRepo, &psz_admin_id) ); // we store this userid under the admin scope of the repo we were given SG_ERR_CHECK( SG_string__alloc__format(pCtx, &pstr_path, "%s/%s/%s", SG_LOCALSETTING__SCOPE__ADMIN, psz_admin_id, SG_LOCALSETTING__USERID ) ); SG_ERR_CHECK( SG_localsettings__get__sz(pCtx, SG_string__sz(pstr_path), pRepo, &psz_userid, NULL) ); if (psz_userid == NULL || *psz_userid == 0) SG_ERR_THROW(SG_ERR_USER_NOT_FOUND); SG_ERR_CHECK( SG_user__lookup_by_userid(pCtx, pRepo, psz_userid, &pvh_userhash) ); SG_ERR_CHECK( SG_vhash__get__sz(pCtx, pvh_userhash, "email", &psz_email_temp) ); SG_ERR_CHECK( SG_STRDUP(pCtx, psz_email_temp, (char**)ppsz_email) ); } fail: SG_VHASH_NULLFREE(pCtx, pvh_userhash); SG_NULLFREE(pCtx, psz_admin_id); SG_NULLFREE(pCtx, psz_userid); SG_STRING_NULLFREE(pCtx, pstr_path); }
void SG_sync_remote__push_commit( SG_context* pCtx, SG_repo* pRepo, const char* pszPushId, SG_vhash** ppResult ) { SG_staging* pStaging = NULL; SG_vhash* pvh_status = NULL; SG_NULLARGCHECK_RETURN(pszPushId); SG_NULLARGCHECK_RETURN(ppResult); SG_ERR_CHECK( SG_staging__open(pCtx, pszPushId, &pStaging) ); SG_ERR_CHECK( SG_staging__commit(pCtx, pStaging, pRepo) ); SG_ERR_CHECK( SG_staging__check_status(pCtx, pStaging, pRepo, SG_TRUE, SG_FALSE, SG_TRUE, SG_TRUE, SG_FALSE, &pvh_status) ); *ppResult = pvh_status; pvh_status = NULL; /* fallthru */ fail: SG_VHASH_NULLFREE(pCtx, pvh_status); SG_STAGING_NULLFREE(pCtx, pStaging); }
void SG_user__lookup_by_email( SG_context* pCtx, SG_repo* pRepo, const char* psz_email, SG_vhash** ppvh ) { char* psz_hid_cs_leaf = NULL; SG_vhash* pvh_user = NULL; char buf_where[256 + 64]; SG_stringarray* psa_fields = NULL; SG_ERR_CHECK( SG_zing__get_leaf__fail_if_needs_merge(pCtx, pRepo, SG_DAGNUM__USERS, &psz_hid_cs_leaf) ); if (psz_hid_cs_leaf) { SG_ERR_CHECK( SG_sprintf(pCtx, buf_where, sizeof(buf_where), "email == '%s'", psz_email) ); SG_ERR_CHECK( SG_STRINGARRAY__ALLOC(pCtx, &psa_fields, 4) ); SG_ERR_CHECK( SG_stringarray__add(pCtx, psa_fields, "recid") ); SG_ERR_CHECK( SG_stringarray__add(pCtx, psa_fields, "email") ); //SG_ERR_CHECK( SG_stringarray__add(pCtx, psa_fields, "prefix") ); SG_ERR_CHECK( SG_stringarray__add(pCtx, psa_fields, "key") ); SG_ERR_CHECK( SG_zing__query__one(pCtx, pRepo, SG_DAGNUM__USERS, psz_hid_cs_leaf, "user", buf_where, psa_fields, &pvh_user) ); } *ppvh = pvh_user; pvh_user = NULL; fail: SG_STRINGARRAY_NULLFREE(pCtx, psa_fields); SG_VHASH_NULLFREE(pCtx, pvh_user); SG_NULLFREE(pCtx, psz_hid_cs_leaf); }
void u0026_jsonparser__test_jsonparser_vhash_2(SG_context * pCtx) { SG_string* pstr1 = NULL; SG_string* pstr2 = NULL; SG_vhash* pvh = NULL; VERIFY_ERR_CHECK( SG_STRING__ALLOC(pCtx, &pstr1) ); VERIFY_ERR_CHECK( SG_STRING__ALLOC(pCtx, &pstr2) ); VERIFY_ERR_CHECK( u0026_jsonparser__create_2(pCtx, pstr1) ); SG_VHASH__ALLOC__FROM_JSON__SZ(pCtx, &pvh, SG_string__sz(pstr1)); VERIFY_COND("from_json", !SG_context__has_err(pCtx)); VERIFY_COND("from_json", pvh); SG_context__err_reset(pCtx); SG_vhash__to_json(pCtx, pvh, pstr2); VERIFY_COND("from_json", !SG_context__has_err(pCtx)); // TODO do some checks fail: SG_STRING_NULLFREE(pCtx, pstr1); SG_STRING_NULLFREE(pCtx, pstr2); SG_VHASH_NULLFREE(pCtx, pvh); }
void u0038_test_wdmapping(SG_context * pCtx) { SG_vhash* pvh = NULL; SG_pathname* pPath = NULL; SG_pathname* pMappedPath = NULL; SG_string* pstrRepoDescriptorName = NULL; char* pszidGid = NULL; VERIFY_ERR_CHECK_DISCARD( SG_PATHNAME__ALLOC(pCtx, &pPath) ); VERIFY_ERR_CHECK_DISCARD( SG_pathname__set__from_cwd(pCtx, pPath) ); VERIFY_ERR_CHECK_DISCARD( SG_VHASH__ALLOC(pCtx, &pvh) ); VERIFY_ERR_CHECK_DISCARD( SG_vhash__add__string__sz(pCtx, pvh, "hello", "world") ); VERIFY_ERR_CHECK_DISCARD( SG_vhash__add__string__sz(pCtx, pvh, "hola", "mundo") ); SG_ERR_IGNORE( SG_closet__descriptors__remove(pCtx, "r1") ); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__add(pCtx, "r1", pvh) ); VERIFY_ERR_CHECK_DISCARD( SG_workingdir__set_mapping(pCtx, pPath, "r1", NULL) ); VERIFY_ERR_CHECK_DISCARD( SG_workingdir__find_mapping(pCtx, pPath, &pMappedPath, &pstrRepoDescriptorName, &pszidGid) ); VERIFY_COND("ridesc match", (0 == strcmp("r1", SG_string__sz(pstrRepoDescriptorName)))); VERIFY_ERR_CHECK_DISCARD( SG_pathname__append__from_sz(pCtx, pPath, "foo") ); VERIFY_ERR_CHECK_DISCARD( SG_pathname__append__from_sz(pCtx, pPath, "bar") ); VERIFY_ERR_CHECK_DISCARD( SG_pathname__append__from_sz(pCtx, pPath, "plok") ); SG_STRING_NULLFREE(pCtx, pstrRepoDescriptorName); SG_PATHNAME_NULLFREE(pCtx, pMappedPath); VERIFY_ERR_CHECK_DISCARD( SG_workingdir__find_mapping(pCtx, pPath, &pMappedPath, &pstrRepoDescriptorName, &pszidGid) ); SG_STRING_NULLFREE(pCtx, pstrRepoDescriptorName); SG_PATHNAME_NULLFREE(pCtx, pMappedPath); SG_PATHNAME_NULLFREE(pCtx, pPath); SG_VHASH_NULLFREE(pCtx, pvh); }
void SG_mrg__free(SG_context * pCtx, SG_mrg * pMrg) { if (!pMrg) return; ////////////////////////////////////////////////////////////////// pMrg->pMergeArgs = NULL; // we do not own this pMrg->pWcTx = NULL; // we do not own this ////////////////////////////////////////////////////////////////// SG_VHASH_NULLFREE(pCtx, pMrg->pvhPile); SG_NULLFREE(pCtx, pMrg->pszHid_StartingBaseline); SG_NULLFREE(pCtx, pMrg->pszBranchName_Starting); SG_NULLFREE(pCtx, pMrg->pszHidTarget); ////////////////////////////////////////////////////////////////// SG_DAGLCA_NULLFREE(pCtx,pMrg->pDagLca); SG_MRG_CSET_NULLFREE(pCtx, pMrg->pMrgCSet_LCA); SG_MRG_CSET_NULLFREE(pCtx, pMrg->pMrgCSet_Baseline); SG_MRG_CSET_NULLFREE(pCtx, pMrg->pMrgCSet_Other); SG_MRG_CSET_NULLFREE(pCtx,pMrg->pMrgCSet_FinalResult); SG_RBTREE_NULLFREE_WITH_ASSOC(pCtx,pMrg->prbCSets_Aux,(SG_free_callback *)SG_mrg_cset__free); SG_VECTOR_I64_NULLFREE(pCtx, pMrg->pVecRevertAllKillList); SG_NULLFREE(pCtx, pMrg); }
void sg_client__c__pull_clone( SG_context* pCtx, SG_client* pClient, const SG_pathname* pStagingPathname, char** ppszFragballName) { sg_client_c_instance_data* pMe = NULL; SG_repo* pRepo = NULL; SG_vhash* pvhStatus = NULL; SG_NULLARGCHECK_RETURN(pClient); SG_NULLARGCHECK_RETURN(ppszFragballName); pMe = (sg_client_c_instance_data*)pClient->p_vtable_instance_data; SG_ERR_CHECK( SG_repo__open_repo_instance(pCtx, pClient->psz_remote_repo_spec, &pRepo) ); SG_ERR_CHECK( SG_context__msg__emit(pCtx, "Copying repository...") ); SG_ERR_CHECK( SG_repo__fetch_repo__fragball(pCtx, pRepo, pStagingPathname, ppszFragballName) ); SG_ERR_CHECK( SG_context__msg__emit(pCtx, "done") ); /* fall through */ fail: SG_REPO_NULLFREE(pCtx, pRepo); SG_VHASH_NULLFREE(pCtx, pvhStatus); SG_ERR_IGNORE( SG_context__msg__emit(pCtx, "\n") ); }
void SG_group__list( SG_context* pCtx, SG_repo* pRepo, SG_varray** ppva ) { SG_string* pstr_where = NULL; SG_stringarray* psa_results = NULL; char* psz_hid_cs_leaf = NULL; SG_vhash* pvh_group = NULL; SG_varray* pva_result = NULL; SG_stringarray* psa_fields = NULL; SG_ERR_CHECK( SG_zing__get_leaf__fail_if_needs_merge(pCtx, pRepo, SG_DAGNUM__USERS, &psz_hid_cs_leaf) ); SG_ERR_CHECK( SG_STRINGARRAY__ALLOC(pCtx, &psa_fields, 2) ); SG_ERR_CHECK( SG_stringarray__add(pCtx, psa_fields, "recid") ); SG_ERR_CHECK( SG_stringarray__add(pCtx, psa_fields, "name") ); SG_ERR_CHECK( SG_zing__query(pCtx, pRepo, SG_DAGNUM__USERS, psz_hid_cs_leaf, "group", NULL, "name #ASC", 0, 0, psa_fields, &pva_result) ); *ppva = pva_result; pva_result = NULL; fail: SG_VHASH_NULLFREE(pCtx, pvh_group); SG_NULLFREE(pCtx, psz_hid_cs_leaf); SG_VARRAY_NULLFREE(pCtx, pva_result); SG_STRINGARRAY_NULLFREE(pCtx, psa_results); SG_STRING_NULLFREE(pCtx, pstr_where); SG_STRINGARRAY_NULLFREE(pCtx, psa_fields); }
/** * Queue a request to resolve (or partially resolve) an issue. * We assume that the caller has already * queued any necessary WD operations * (such as moves/renamed) and now just * needs to mark the item resolved (or * partially resolved). * * Since an item may have multiple conflict * bits set, you can use this to mark the * specific choices made in the pvhSavedResolutions * and only mark it fully resolved when * everything has been chosen. * * We steal the optional/given pvhSavedResolutions. * */ void sg_wc_tx__queue__resolve_issue__sr(SG_context * pCtx, SG_wc_tx * pWcTx, sg_wc_liveview_item * pLVI, SG_wc_status_flags statusFlags_x_xr_xu, SG_vhash ** ppvhSavedResolutions) { SG_string * pStringResolveData = NULL; SG_NULLARGCHECK_RETURN( pWcTx ); SG_NULLARGCHECK_RETURN( pLVI ); // ppvhSavedResolutions is optional. if (ppvhSavedResolutions && *ppvhSavedResolutions) { SG_ERR_CHECK( SG_STRING__ALLOC(pCtx, &pStringResolveData) ); SG_ERR_CHECK( SG_vhash__to_json(pCtx, (*ppvhSavedResolutions), pStringResolveData) ); } SG_ERR_CHECK( sg_wc_tx__journal__resolve_issue__sr(pCtx, pWcTx, pLVI->uiAliasGid, statusFlags_x_xr_xu, pStringResolveData) ); pLVI->statusFlags_x_xr_xu = statusFlags_x_xr_xu; SG_VHASH_NULLFREE(pCtx, pLVI->pvhSavedResolutions); if (ppvhSavedResolutions && *ppvhSavedResolutions) { pLVI->pvhSavedResolutions = *ppvhSavedResolutions; *ppvhSavedResolutions = NULL; } fail: SG_STRING_NULLFREE(pCtx, pStringResolveData); }
void SG_sync_remote__heartbeat( SG_context* pCtx, SG_repo* pRepo, SG_vhash** ppvh) { SG_vhash* pvh = NULL; char* pszRepoId = NULL; char* pszAdminId = NULL; char* pszHashMethod = NULL; SG_ERR_CHECK( SG_VHASH__ALLOC(pCtx, &pvh) ); SG_ERR_CHECK( SG_repo__get_repo_id(pCtx, pRepo, &pszRepoId) ); SG_ERR_CHECK( SG_repo__get_admin_id(pCtx, pRepo, &pszAdminId) ); SG_ERR_CHECK( SG_repo__get_hash_method(pCtx, pRepo, &pszHashMethod) ); SG_ERR_CHECK( SG_vhash__add__string__sz(pCtx, pvh, SG_SYNC_REPO_INFO_KEY__REPO_ID, pszRepoId) ); SG_ERR_CHECK( SG_vhash__add__string__sz(pCtx, pvh, SG_SYNC_REPO_INFO_KEY__ADMIN_ID, pszAdminId) ); SG_ERR_CHECK( SG_vhash__add__string__sz(pCtx, pvh, SG_SYNC_REPO_INFO_KEY__HASH_METHOD, pszHashMethod) ); *ppvh = pvh; pvh = NULL; /* fall through */ fail: SG_VHASH_NULLFREE(pCtx, pvh); SG_NULLFREE(pCtx, pszRepoId); SG_NULLFREE(pCtx, pszAdminId); SG_NULLFREE(pCtx, pszHashMethod); }
static void _node__free_nonreusable_memory(SG_context * pCtx, _node_t * pNode) { SG_ASSERT(pNode!=NULL); SG_DAGNODE_NULLFREE(pCtx, pNode->pDagnode); SG_VARRAY_NULLFREE(pCtx, pNode->pAudits); SG_VHASH_NULLFREE(pCtx, pNode->pVcParents); }
void SG_server__push_add( SG_context* pCtx, SG_server * pServer, const char* pPushId, const char* psz_fragball_name, SG_vhash** ppResult ) { SG_staging* pStaging = NULL; SG_vhash* pvh_status = NULL; SG_repo* pRepo = NULL; SG_NULLARGCHECK_RETURN(pServer); SG_NULLARGCHECK_RETURN(pPushId); SG_NULLARGCHECK_RETURN(ppResult); SG_ERR_CHECK( SG_staging__open(pCtx, pPushId, &pStaging) ); SG_ERR_CHECK( SG_staging__slurp_fragball(pCtx, pStaging, psz_fragball_name) ); SG_ERR_CHECK( SG_staging__check_status(pCtx, pStaging, SG_TRUE, SG_TRUE, SG_FALSE, SG_TRUE, SG_TRUE, &pvh_status) ); *ppResult = pvh_status; pvh_status = NULL; /* fallthru */ fail: SG_REPO_NULLFREE(pCtx, pRepo); SG_VHASH_NULLFREE(pCtx, pvh_status); SG_STAGING_NULLFREE(pCtx, pStaging); }
void u0038_test_ridesc(SG_context * pCtx) { SG_closet_descriptor_handle* ph = NULL; SG_vhash* pvh = NULL; SG_vhash* pvh_all = NULL; SG_uint32 count = 0; SG_ERR_IGNORE( SG_closet__descriptors__remove(pCtx, "1") ); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__add_begin(pCtx, "1", NULL, NULL, NULL, NULL, &pvh, &ph) ); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__add_commit(pCtx, &ph, pvh, SG_REPO_STATUS__NORMAL)); SG_VHASH_NULLFREE(pCtx, pvh); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__remove(pCtx, "1") ); SG_ERR_IGNORE( SG_closet__descriptors__remove(pCtx, "2") ); /* This may or may not be an error */ /* delete one that is not there should be an error */ VERIFY_ERR_CHECK_HAS_ERR_DISCARD( SG_closet__descriptors__remove(pCtx, "2") ); /* fetch one that is not there should be an error */ VERIFY_ERR_CHECK_HAS_ERR_DISCARD( SG_closet__descriptors__get(pCtx, "2", NULL, &pvh) ); VERIFY_COND("", pvh==NULL); SG_ERR_IGNORE( SG_closet__descriptors__remove(pCtx, "3") ); SG_ERR_IGNORE( SG_closet__descriptors__remove(pCtx, "4") ); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__add_begin(pCtx, "3", NULL, NULL, NULL, NULL, &pvh, &ph) ); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__add_commit(pCtx, &ph, pvh, SG_REPO_STATUS__NORMAL) ); SG_VHASH_NULLFREE(pCtx, pvh); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__add_begin(pCtx, "4", NULL, NULL, NULL, NULL, &pvh, &ph) ); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__add_commit(pCtx, &ph, pvh, SG_REPO_STATUS__NORMAL) ); SG_VHASH_NULLFREE(pCtx, pvh); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__get(pCtx, "3", NULL, &pvh) ); VERIFY_ERR_CHECK_DISCARD( SG_closet__descriptors__list(pCtx, &pvh_all) ); VERIFY_ERR_CHECK_DISCARD( SG_vhash__count(pCtx, pvh_all, &count) ); /* adding a duplicate name should be an error */ VERIFY_ERR_CHECK_ERR_EQUALS_DISCARD( SG_closet__descriptors__add_begin(pCtx, "3", NULL, NULL, NULL, NULL, NULL, &ph), SG_ERR_REPO_ALREADY_EXISTS); VERIFY_COND("count", (count >= 2)); SG_ERR_IGNORE( SG_closet__descriptors__remove(pCtx, "3") ); SG_ERR_IGNORE( SG_closet__descriptors__remove(pCtx, "4") ); SG_VHASH_NULLFREE(pCtx, pvh_all); SG_VHASH_NULLFREE(pCtx, pvh); }
void SG_dbrecord__free(SG_context * pCtx, SG_dbrecord* prec) { if (!prec) return; SG_VHASH_NULLFREE(pCtx, prec->pvh); SG_NULLFREE(pCtx, prec->pid); SG_NULLFREE(pCtx, prec); }
void MyFn(create_repo)(SG_context * pCtx, SG_repo ** ppRepo) { // caller must free returned value. SG_repo * pRepo; SG_pathname * pPathnameRepoDir = NULL; SG_vhash* pvhPartialDescriptor = NULL; char buf_repo_id[SG_GID_BUFFER_LENGTH]; char buf_admin_id[SG_GID_BUFFER_LENGTH]; char* pszRepoImpl = NULL; VERIFY_ERR_CHECK( SG_gid__generate(pCtx, buf_repo_id, sizeof(buf_repo_id)) ); VERIFY_ERR_CHECK( SG_gid__generate(pCtx, buf_admin_id, sizeof(buf_admin_id)) ); VERIFY_ERR_CHECK( SG_PATHNAME__ALLOC(pCtx, &pPathnameRepoDir) ); VERIFY_ERR_CHECK( SG_pathname__set__from_cwd(pCtx, pPathnameRepoDir) ); VERIFY_ERR_CHECK( SG_VHASH__ALLOC(pCtx, &pvhPartialDescriptor) ); VERIFY_ERR_CHECK_DISCARD( SG_localsettings__get__sz(pCtx, SG_LOCALSETTING__NEWREPO_DRIVER, NULL, &pszRepoImpl, NULL) ); VERIFY_ERR_CHECK_DISCARD( SG_vhash__add__string__sz(pCtx, pvhPartialDescriptor, SG_RIDESC_KEY__STORAGE, pszRepoImpl) ); VERIFY_ERR_CHECK( SG_vhash__add__string__sz(pCtx, pvhPartialDescriptor, SG_RIDESC_FSLOCAL__PATH_PARENT_DIR, SG_pathname__sz(pPathnameRepoDir)) ); VERIFY_ERR_CHECK( SG_repo__create_repo_instance(pCtx,pvhPartialDescriptor,SG_TRUE,NULL,buf_repo_id,buf_admin_id,&pRepo) ); SG_VHASH_NULLFREE(pCtx, pvhPartialDescriptor); { const SG_vhash * pvhRepoDescriptor = NULL; VERIFY_ERR_CHECK( SG_repo__get_descriptor(pCtx, pRepo,&pvhRepoDescriptor) ); //INFOP("open_repo",("Repo is [%s]",SG_string__sz(pstrRepoDescriptor))); } *ppRepo = pRepo; fail: SG_VHASH_NULLFREE(pCtx, pvhPartialDescriptor); SG_PATHNAME_NULLFREE(pCtx, pPathnameRepoDir); SG_NULLFREE(pCtx, pszRepoImpl); }
void SG_localsettings__foreach( SG_context* pCtx, const char* szPattern, SG_bool bIncludeDefaults, SG_localsettings_foreach_callback* pCallback, void* pCallerData ) { SG_vhash* pValues = NULL; SG_vhash* pDefaults = NULL; provide_matching_values__data ProvideMatchingValuesData = {NULL, NULL, NULL, NULL}; SG_UNUSED(pCallback); SG_UNUSED(pCallerData); // get the settings SG_ERR_CHECK( SG_localsettings__list__vhash(pCtx, &pValues) ); // if defaults were requested, get those too if (bIncludeDefaults) { SG_ERR_CHECK( SG_localsettings__factory__list__vhash(pCtx, &pDefaults) ); SG_ERR_CHECK( SG_vhash__add__vhash(pCtx, pValues, SG_LOCALSETTING__SCOPE__DEFAULT + 1, &pDefaults) ); // +1 to remove the slash at the beginning } // sort the settings SG_ERR_CHECK( SG_vhash__sort(pCtx, pValues, SG_TRUE, SG_vhash_sort_callback__increasing) ); // setup our callback data SG_ERR_CHECK( SG_STRING__ALLOC(pCtx, &(ProvideMatchingValuesData.pPrefix)) ); ProvideMatchingValuesData.szPattern = szPattern; ProvideMatchingValuesData.pCallback = pCallback; ProvideMatchingValuesData.pCallerData = pCallerData; // iterate through the vhash SG_ERR_CHECK( SG_vhash__foreach(pCtx, pValues, provide_matching_values, &ProvideMatchingValuesData) ); fail: SG_VHASH_NULLFREE(pCtx, pValues); SG_VHASH_NULLFREE(pCtx, pDefaults); SG_STRING_NULLFREE(pCtx, ProvideMatchingValuesData.pPrefix); }
static void _sg_pull__nullfree(SG_context* pCtx, _sg_pull** ppMyPull) { if (ppMyPull && *ppMyPull) { _sg_pull* pMyPull = *ppMyPull; SG_VHASH_NULLFREE(pCtx, pMyPull->pvhFragballRequest); SG_ERR_IGNORE( _free_instance_data(pCtx, pMyPull->pPullInstance) ); SG_NULLFREE(pCtx, pMyPull); *ppMyPull = NULL; } }