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 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 MyFn(create_repo)(SG_context * pCtx, SG_repo** ppRepo) { SG_repo* pRepo = NULL; SG_pathname* pPath_repo = NULL; char buf_repo_id[SG_GID_BUFFER_LENGTH]; char buf_admin_id[SG_GID_BUFFER_LENGTH]; SG_vhash* pvhPartialDescriptor = NULL; 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)) ); /* Get our paths fixed up */ VERIFY_ERR_CHECK( SG_PATHNAME__ALLOC(pCtx, &pPath_repo) ); VERIFY_ERR_CHECK( SG_pathname__set__from_cwd(pCtx, pPath_repo) ); VERIFY_ERR_CHECK( SG_pathname__append__from_sz(pCtx, pPath_repo, "repo") ); SG_fsobj__mkdir__pathname(pCtx, pPath_repo); SG_context__err_reset(pCtx); // Create the repo VERIFY_ERR_CHECK( SG_VHASH__ALLOC(pCtx, &pvhPartialDescriptor) ); VERIFY_ERR_CHECK_DISCARD( SG_localsettings__get__sz(pCtx, SG_LOCALSETTING__NEWREPO_DRIVER, NULL, &pszRepoImpl, NULL) ); if (pszRepoImpl) { 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(pPath_repo)) ); VERIFY_ERR_CHECK( SG_repo__create_repo_instance(pCtx,NULL,pvhPartialDescriptor,SG_TRUE,NULL,buf_repo_id,buf_admin_id,&pRepo) ); *ppRepo = pRepo; // Fall through to common cleanup fail: SG_VHASH_NULLFREE(pCtx, pvhPartialDescriptor); SG_PATHNAME_NULLFREE(pCtx, pPath_repo); SG_NULLFREE(pCtx, pszRepoImpl); }
void SG_sync_remote__push_clone__begin( SG_context* pCtx, const char* psz_repo_descriptor_name, const SG_vhash* pvhRepoInfo, const char** ppszCloneId) { const char* psz_repo_id = NULL; const char* psz_admin_id = NULL; const char* psz_hash_method = NULL; const char* pszRefValidatedName = NULL; SG_vhash* pvhFullDescriptor = NULL; // pNewRepo owns this. Don't free. SG_vhash* pvhDescriptorPartial = NULL; SG_closet_descriptor_handle* ph = NULL; SG_repo* pNewRepo = NULL; const char* pszRefCloneId = NULL; SG_NULLARGCHECK_RETURN(ppszCloneId); SG_ERR_CHECK_RETURN( _remote_clone_allowed(pCtx) ); /* We'll create a descriptor and empty repo immediately, so that we validate and claim the name * before a potentially long upload. */ SG_ERR_CHECK_RETURN( SG_vhash__get__sz(pCtx, pvhRepoInfo, SG_SYNC_REPO_INFO_KEY__REPO_ID, &psz_repo_id) ); SG_ERR_CHECK_RETURN( SG_vhash__get__sz(pCtx, pvhRepoInfo, SG_SYNC_REPO_INFO_KEY__ADMIN_ID, &psz_admin_id) ); SG_ERR_CHECK_RETURN( SG_vhash__get__sz(pCtx, pvhRepoInfo, SG_SYNC_REPO_INFO_KEY__HASH_METHOD, &psz_hash_method) ); SG_ERR_CHECK( SG_closet__descriptors__add_begin(pCtx, psz_repo_descriptor_name, NULL, psz_repo_id, psz_admin_id, &pszRefValidatedName, &pvhDescriptorPartial, &ph) ); SG_ERR_CHECK( SG_repo__create_repo_instance(pCtx, pszRefValidatedName, pvhDescriptorPartial, SG_TRUE, psz_hash_method, psz_repo_id, psz_admin_id, &pNewRepo) ); SG_VHASH_NULLFREE(pCtx, pvhDescriptorPartial); SG_ERR_CHECK_RETURN( SG_staging__clone__create(pCtx, psz_repo_descriptor_name, pvhRepoInfo, &pszRefCloneId) ); /* We temporarily add the clone ID to the repo descriptor so that we can verify * we're committing to the correct repo later, when the fragball's been uploaded. */ SG_ERR_CHECK( SG_repo__get_descriptor__ref(pCtx, pNewRepo, &pvhFullDescriptor) ); SG_ERR_CHECK( SG_vhash__add__string__sz(pCtx, pvhFullDescriptor, SG_SYNC_DESCRIPTOR_KEY__CLONE_ID, pszRefCloneId) ); SG_ERR_CHECK( SG_closet__descriptors__add_commit(pCtx, &ph, pvhFullDescriptor, SG_REPO_STATUS__CLONING) ); SG_REPO_NULLFREE(pCtx, pNewRepo); *ppszCloneId = pszRefCloneId; return; fail: SG_VHASH_NULLFREE(pCtx, pvhDescriptorPartial); SG_REPO_NULLFREE(pCtx, pNewRepo); SG_ERR_IGNORE( SG_closet__descriptors__add_abort(pCtx, &ph) ); }