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);
}
Example #2
0
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);
}
Example #3
0
static void _getDescriptorName(
	SG_context *pCtx,
	const _request_headers *pRequestHeaders,
	SG_string **ppRepoName)
{
	SG_pathname *pPathCwd = NULL;

	if (_startsWith("repos/", pRequestHeaders->pUri) && (strlen(pRequestHeaders->pUri) > 6))
	{
		const char *nameStart = pRequestHeaders->pUri + 6;
		const char *nameEnd = strchr(nameStart, '/');

		SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, ppRepoName)  );

		if (nameEnd == NULL)
			SG_ERR_CHECK(  SG_string__set__sz(pCtx, *ppRepoName, nameStart)  );
		else
			SG_ERR_CHECK(  SG_string__set__buf_len(pCtx, *ppRepoName, (const SG_byte *)nameStart,
												   (nameEnd - nameStart) * sizeof(char))  );
	}
	else
	{
		SG_ERR_CHECK(  SG_PATHNAME__ALLOC(pCtx, &pPathCwd)  );
		SG_ERR_CHECK(  SG_pathname__set__from_cwd(pCtx, pPathCwd)  );
		SG_ERR_CHECK(  SG_workingdir__find_mapping(pCtx, pPathCwd, NULL, ppRepoName, NULL)  );
	}

fail:
	SG_PATHNAME_NULLFREE(pCtx, pPathCwd);
}
/**
 * "Throws" SG_ERR_NOT_A_WORKING_COPY if the cwd's not inside a working copy.
 */
void SG_cmd_util__get_descriptor_name_from_cwd(SG_context* pCtx, SG_string** ppstrDescriptorName, SG_pathname** ppPathCwd)
{
	SG_pathname* pPathCwd = NULL;
	SG_string* pstrRepoDescriptorName = NULL;

	SG_ERR_CHECK(  SG_PATHNAME__ALLOC(pCtx, &pPathCwd)  );
	SG_ERR_CHECK(  SG_pathname__set__from_cwd(pCtx, pPathCwd)  );

	SG_ERR_CHECK(  SG_workingdir__find_mapping(pCtx, pPathCwd, NULL, &pstrRepoDescriptorName, NULL)  );

	SG_RETURN_AND_NULL(pstrRepoDescriptorName, ppstrDescriptorName);
	SG_RETURN_AND_NULL(pPathCwd, ppPathCwd);

	/* fall through */
fail:
	SG_PATHNAME_NULLFREE(pCtx, pPathCwd);
	SG_STRING_NULLFREE(pCtx, pstrRepoDescriptorName);
}
Example #5
0
void SG_workingdir__get_temp_path(SG_context* pCtx,
								  const SG_pathname* pPathWorkingDirectoryTopAsGiven,
								  SG_pathname** ppResult)
{
	SG_pathname * pPathname = NULL;

	SG_NULLARGCHECK_RETURN(ppResult);

	// I don't trust the given <wd-top>, get the actual one from the disk
	// using this as a starting point.

	SG_ERR_CHECK(  SG_workingdir__find_mapping(pCtx,pPathWorkingDirectoryTopAsGiven,&pPathname,NULL,NULL)  );
	SG_ERR_CHECK(  SG_pathname__append__from_sz(pCtx,pPathname,sg_WD_TEMP_DIRECTORY_NAME)  );

	*ppResult = pPathname;
	return;

fail:
	SG_PATHNAME_NULLFREE(pCtx, pPathname);
}
/**
 * Create a new repo and *always* create a WD for it.
 *
 */
void vv2__do_cmd_init_new_repo(SG_context * pCtx,
							  const char * pszRepoName,
							  const char * pszFolder,
							  const char * pszStorage,
							  const char * pszHashMethod,
							  const char * psz_shared_users)
{
	SG_pathname * pPathLocalDirectory = NULL;

	SG_ERR_CHECK(  SG_PATHNAME__ALLOC__SZ(pCtx, &pPathLocalDirectory, pszFolder)  );
	SG_workingdir__find_mapping(pCtx, pPathLocalDirectory, NULL, NULL, NULL);
	SG_ERR_CHECK_CURRENT_DISREGARD(SG_ERR_NOT_A_WORKING_COPY);

	SG_ERR_CHECK(  SG_vv2__init_new_repo(pCtx,
										 pszRepoName,
										 pszFolder,
										 pszStorage,
										 pszHashMethod,
										 SG_FALSE,			// bNoWD
										 psz_shared_users,
										 SG_FALSE,
										 NULL,
										 NULL)  );

fail:
	SG_PATHNAME_NULLFREE(pCtx, pPathLocalDirectory);

	// TODO 2010/10/25 Decide which error message we should try to provide a better error message for.
	// TODO            Candidates include
	// TODO SG_ERR_INVALID_REPO_NAME
	// TODO SG_ERR_AMBIGUOUS_ID_PREFIX
	// TODO SG_ERR_MULTIPLE_HEADS_FROM_DAGNODE
	// TODO
	// TODO            But we should look and see what the lower layers are throwing now.  Some of
	// TODO            of the messages that were here are now being handled.
	return;
}