コード例 #1
0
void sg_wc_db__debug__tne_row__print(SG_context * pCtx, sg_wc_db__tne_row * pTneRow)
{
	SG_int_to_string_buffer bufui64_a;
	SG_int_to_string_buffer bufui64_b;
		
	SG_ERR_IGNORE(  SG_console(pCtx, SG_CS_STDERR,
							   "sg_wc_db:tne_row: [gid %s][par %s][hid %s] %s\n",
							   SG_uint64_to_sz(pTneRow->p_s->uiAliasGid,       bufui64_a),
							   SG_uint64_to_sz(pTneRow->p_s->uiAliasGidParent, bufui64_b),
							   pTneRow->p_d->pszHid,
							   pTneRow->p_s->pszEntryname)  );
}
コード例 #2
0
void sg_wc_db__gid__get_or_insert_alias_from_gid(SG_context * pCtx,
												 sg_wc_db * pDb,
												 const char * pszGid,
												 SG_uint64 * puiAliasGid)
{
	SG_bool bNotAlreadyPresent;
	
	sg_wc_db__gid__get_alias_from_gid(pCtx, pDb, pszGid, puiAliasGid);
	bNotAlreadyPresent = SG_CONTEXT__HAS_ERR(pCtx);

	if (bNotAlreadyPresent)
	{
		SG_context__err_reset(pCtx);

		SG_ERR_CHECK(  sg_wc_db__gid__insert(pCtx, pDb, pszGid)  );
		SG_ERR_CHECK(  sg_wc_db__gid__get_alias_from_gid(pCtx, pDb, pszGid, puiAliasGid)  );
	}

#if TRACE_WC_GID
	{
		SG_int_to_string_buffer bufui64;

		SG_ERR_IGNORE(  SG_console(pCtx, SG_CS_STDERR,
								   "GID: get_or_insert [%s] ==> %s [new %d]\n",
								   pszGid,
								   SG_uint64_to_sz(*puiAliasGid,bufui64),
								   bNotAlreadyPresent)  );
	}
#endif

fail:
	return;
}
コード例 #3
0
void sg_wc_db__gid__prepare_toggle_tmp_stmt(SG_context * pCtx,
											sg_wc_db * pDb,
											SG_uint64 uiAliasGid,
											SG_bool bIsTmp,
											sqlite3_stmt ** ppStmt)
{
	sqlite3_stmt * pStmt = NULL;

#if TRACE_WC_DB
	{
		SG_int_to_string_buffer bufui64;

		SG_ERR_IGNORE(  SG_console(pCtx, SG_CS_STDERR, "sg_wc_db__gid__prepare_toggle_tmp_stmt: %s --> %c\n",
								   SG_uint64_to_sz(uiAliasGid, bufui64),
								   ((bIsTmp) ? 'T' : 'F'))  );
	}
#endif

	SG_ERR_CHECK(  sg_sqlite__prepare(pCtx, pDb->psql, &pStmt,
									  ("UPDATE tbl_gid SET tmp = ? WHERE alias_gid = ?"))  );
	SG_ERR_CHECK(  sg_sqlite__bind_int( pCtx, pStmt, 1, bIsTmp)  );
	SG_ERR_CHECK(  sg_sqlite__bind_int64(pCtx, pStmt, 2, uiAliasGid)  );

	*ppStmt = pStmt;
	return;

fail:
	SG_ERR_IGNORE(  sg_sqlite__finalize(pCtx, pStmt)  );
}
コード例 #4
0
void sg_wc_db__gid__get_gid_from_alias(SG_context * pCtx,
									   sg_wc_db * pDb,
									   SG_uint64 uiAliasGid,
									   char ** ppszGid)
{
	char * pszGid = NULL;
	int rc;

	// TODO 2011/08/01 Should this check for "*null*" and offer to return NULL ?

	//Caching the prepared statement is a pretty huge performance win.
	if (pDb->pSqliteStmt__get_gid_from_alias == NULL)
	{
		SG_ERR_CHECK(  sg_sqlite__prepare(pCtx, pDb->psql, &pDb->pSqliteStmt__get_gid_from_alias,
									  ("SELECT gid FROM tbl_gid WHERE alias_gid = ?"))  );
	}
	SG_ERR_CHECK(  sg_sqlite__bind_int64(pCtx, pDb->pSqliteStmt__get_gid_from_alias, 1, uiAliasGid)  );

	if ((rc=sqlite3_step(pDb->pSqliteStmt__get_gid_from_alias)) != SQLITE_ROW)
	{
		SG_int_to_string_buffer bufui64;
		SG_ERR_THROW2(  SG_ERR_SQLITE(rc),
						(pCtx, "sg_wc_db:tbl_gid can't find alias %s.",
						 SG_uint64_to_sz(uiAliasGid, bufui64))  );
	}

	SG_ERR_CHECK(  SG_STRDUP(pCtx, (const char *)sqlite3_column_text(pDb->pSqliteStmt__get_gid_from_alias, 0), &pszGid)  );
	SG_ERR_CHECK(  sg_sqlite__reset(pCtx, pDb->pSqliteStmt__get_gid_from_alias)  );
	SG_ERR_CHECK(  sg_sqlite__clear_bindings(pCtx, pDb->pSqliteStmt__get_gid_from_alias)  );

	*ppszGid = pszGid;
	return;

fail:
	SG_ERR_IGNORE(  sg_sqlite__reset(pCtx, pDb->pSqliteStmt__get_gid_from_alias)  );
	SG_ERR_IGNORE(  sg_sqlite__clear_bindings(pCtx, pDb->pSqliteStmt__get_gid_from_alias)  );
	SG_NULLFREE(pCtx, pszGid);
}
コード例 #5
0
void sg_wc_db__gid__get_gid_from_alias2(SG_context * pCtx,
										sg_wc_db * pDb,
										SG_uint64 uiAliasGid,
										char ** ppszGid,
										SG_bool * pbIsTmp)
{
	sqlite3_stmt * pStmt = NULL;
	char * pszGid = NULL;
	int rc;
	SG_bool bIsTmp;

	// TODO 2011/08/01 Should this check for "*null*" and offer to return NULL ?

	SG_ERR_CHECK(  sg_sqlite__prepare(pCtx, pDb->psql, &pStmt,
									  ("SELECT gid,tmp FROM tbl_gid WHERE alias_gid = ?"))  );
	SG_ERR_CHECK(  sg_sqlite__bind_int64(pCtx, pStmt, 1, uiAliasGid)  );

	if ((rc=sqlite3_step(pStmt)) != SQLITE_ROW)
	{
		SG_int_to_string_buffer bufui64;
		SG_ERR_THROW2(  SG_ERR_SQLITE(rc),
						(pCtx, "sg_wc_db:tbl_gid can't find alias %s.",
						 SG_uint64_to_sz(uiAliasGid, bufui64))  );
	}

	SG_ERR_CHECK(  SG_STRDUP(pCtx, (const char *)sqlite3_column_text(pStmt, 0), &pszGid)  );
	bIsTmp = (sqlite3_column_int(pStmt, 1) != 0);
	SG_ERR_CHECK(  sg_sqlite__finalize(pCtx, pStmt)  );

	*ppszGid = pszGid;
	*pbIsTmp = bIsTmp;
	return;

fail:
	SG_ERR_IGNORE(  sg_sqlite__finalize(pCtx, pStmt)  );
	SG_NULLFREE(pCtx, pszGid);
}
コード例 #6
0
/**
 * Get the TNE Row for the (uiAliasGirParent, pszEntryname) pair.
 * This should not have any of the entryname ambiguity problems
 * that such a request on the live view might have.
 *
 */
void sg_wc_db__tne__get_row_by_parent_alias_and_entryname(SG_context * pCtx,
														  sg_wc_db * pDb,
														  const sg_wc_db__cset_row * pCSetRow,
														  SG_uint64 uiAliasGidParent,
														  const char * pszEntryname,
														  SG_bool * pbFound,
														  sg_wc_db__tne_row ** ppTneRow)
{
	sqlite3_stmt * pStmt = NULL;
	sg_wc_db__tne_row * pTneRow = NULL;
	int rc;

	SG_ERR_CHECK(  sg_sqlite__prepare(pCtx, pDb->psql, &pStmt,
									  ("SELECT"
									   "    alias_gid,"			// 0
									   "    hid,"				// 1
									   "    type,"				// 2
									   "    attrbits"			// 3
									   "  FROM %s"
									   "  WHERE alias_gid_parent = ?"
									   "    AND entryname = ?"),
									  pCSetRow->psz_tne_table_name)  );
	SG_ERR_CHECK(  sg_sqlite__bind_int64(pCtx, pStmt, 1, uiAliasGidParent)  );
	SG_ERR_CHECK(  sg_sqlite__bind_text(pCtx,  pStmt, 2, pszEntryname)  );

	if ((rc=sqlite3_step(pStmt)) != SQLITE_ROW)
	{
		SG_int_to_string_buffer bufui64;

		if ((rc == SQLITE_DONE) && pbFound)
		{
			*pbFound = SG_FALSE;
			*ppTneRow = NULL;
			goto done;
		}

		SG_ERR_THROW2(  SG_ERR_SQLITE(rc),
						(pCtx, "sg_wc_db:%s can't find tne row for parent alias %s and entryname '%s'.",
						 pCSetRow->psz_tne_table_name,
						 SG_uint64_to_sz(uiAliasGidParent, bufui64),
						 pszEntryname)  );
	}

	SG_ERR_CHECK(  sg_wc_db__tne_row__alloc(pCtx, &pTneRow)  );

	pTneRow->p_s->uiAliasGid       = (SG_uint64)sqlite3_column_int64(pStmt, 0);
	pTneRow->p_s->uiAliasGidParent = uiAliasGidParent;
	SG_ERR_CHECK(  SG_STRDUP(pCtx, (const char *)sqlite3_column_text(pStmt, 1), &pTneRow->p_d->pszHid)  );
	pTneRow->p_s->tneType          = (SG_uint32)sqlite3_column_int(pStmt, 2);
	pTneRow->p_d->attrbits         = (SG_uint64)sqlite3_column_int64(pStmt, 3);
	SG_ERR_CHECK(  SG_STRDUP(pCtx, pszEntryname, &pTneRow->p_s->pszEntryname)  );

    SG_ERR_CHECK(  sg_sqlite__nullfinalize(pCtx, &pStmt)  );

#if TRACE_WC_DB
	SG_ERR_IGNORE(  SG_console(pCtx, SG_CS_STDERR, "sg_wc_db__tne__get_row_by_parent_alias_and_entryname: found:\n")  );
	SG_ERR_IGNORE(  sg_wc_db__debug__tne_row__print(pCtx, pTneRow)  );
#endif

	if (pbFound)
		*pbFound = SG_TRUE;
	*ppTneRow = pTneRow;
	return;

fail:
	SG_WC_DB__TNE_ROW__NULLFREE(pCtx, pTneRow);
done:
    SG_ERR_IGNORE(  sg_sqlite__nullfinalize(pCtx, &pStmt)  );
}
コード例 #7
0
int u0040_unc__stat_dir(SG_context * pCtx, const char * szDir)
{
	SG_pathname * pPathname = NULL;
	SG_pathname * pPathnameFile = NULL;
	SG_file * pf = NULL;
	SG_fsobj_stat fsobjStat;
	SG_bool bFileExists;
	SG_int_to_string_buffer bufSize;
	char bufDate[100];

	SG_context__err_reset(pCtx);

	//////////////////////////////////////////////////////////////////
	// stat the given directory.
	//////////////////////////////////////////////////////////////////

	INFOP("u0040_unc",("Inspecting [%s]",szDir));

	VERIFY_ERR_CHECK_RETURN(  SG_PATHNAME__ALLOC__SZ(pCtx,&pPathname,szDir)  );

	VERIFY_ERR_CHECK(  SG_fsobj__stat__pathname(pCtx,pPathname,&fsobjStat)  );
	VERIFY_COND("u0040_unc",(fsobjStat.type == SG_FSOBJ_TYPE__DIRECTORY));

	// TODO should we verify length == 0 ?
	// TODO should we verify modtime ?

	SG_uint64_to_sz(fsobjStat.size, bufSize);
	VERIFY_ERR_CHECK_DISCARD(  SG_time__format_utc__i64(pCtx,fsobjStat.mtime_ms,bufDate,SG_NrElements(bufDate))  );

	INFOP("u0040_unc",("Result: [perms %04o][type %d][size %s][mtime %s]",
					   fsobjStat.perms,fsobjStat.type,
					   bufSize,bufDate));

	//////////////////////////////////////////////////////////////////
	// create a unique file in the directory and stat it.
	//////////////////////////////////////////////////////////////////

	VERIFY_ERR_CHECK(  unittest__alloc_unique_pathname(pCtx,szDir,&pPathnameFile)  );

	INFOP("u0040_unc",("    Creating file [%s]",SG_pathname__sz(pPathnameFile)));

	VERIFY_ERR_CHECK(  SG_file__open__pathname(pCtx,pPathnameFile,SG_FILE_CREATE_NEW | SG_FILE_RDWR,0777,&pf)  );

	VERIFY_ERR_CHECK(  SG_fsobj__stat__pathname(pCtx,pPathnameFile,&fsobjStat)  );
	VERIFY_COND("u0040_unc",(fsobjStat.type == SG_FSOBJ_TYPE__REGULAR));
	VERIFY_COND("u0040_unc",(fsobjStat.size == 0));
	VERIFY_COND("u0040_unc",(SG_fsobj__equivalent_perms(fsobjStat.perms,0777)));
	// TODO should we verify modtime ?

	SG_uint64_to_sz(fsobjStat.size, bufSize);
	VERIFY_ERR_CHECK_DISCARD(  SG_time__format_utc__i64(pCtx,fsobjStat.mtime_ms,bufDate,SG_NrElements(bufDate))  );

	INFOP("u0040_unc",("    Result: [perms %04o][type %d][size %s][mtime %s]",
					   fsobjStat.perms,fsobjStat.type,
					   bufSize,bufDate));

	VERIFY_ERR_CHECK_DISCARD(  SG_file__close(pCtx, &pf)  );

	// delete the file and stat it again

	VERIFY_ERR_CHECK_DISCARD(  SG_fsobj__remove__pathname(pCtx,pPathnameFile)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_fsobj__exists__pathname(pCtx,pPathnameFile,&bFileExists,NULL,NULL)  );
	VERIFY_COND("u0040_unc",(!bFileExists));

	//////////////////////////////////////////////////////////////////
	// clean up
	//////////////////////////////////////////////////////////////////

	SG_PATHNAME_NULLFREE(pCtx, pPathnameFile);
	SG_PATHNAME_NULLFREE(pCtx, pPathname);
	return 1;

fail:
	SG_FILE_NULLCLOSE(pCtx, pf);
	SG_PATHNAME_NULLFREE(pCtx, pPathnameFile);
	SG_PATHNAME_NULLFREE(pCtx, pPathname);
	return 0;
}