pkg

Check-in [2ae2c893a2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix repo schema updates.
Timelines: family | ancestors | descendants | both | trunk | gsoc2013
Files: files | file ages | folders
SHA1: 2ae2c893a29371fdaeaca232844e672b51754e64
User & Date: vsevolod@highsecure.ru 2014-05-31 15:55:09
Context
2014-06-04
12:18
Fix reinstallation. check-in: 0edc8928eb user: vsevolod@highsecure.ru tags: trunk, gsoc2013
2014-05-31
15:55
Fix repo schema updates. check-in: 2ae2c893a2 user: vsevolod@highsecure.ru tags: trunk, gsoc2013
15:33
LDNS support is now functional. check-in: 5a54b0b431 user: vsevolod@highsecure.ru tags: trunk, gsoc2013
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to libpkg/pkg_repo_update.c.

226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241






242
243
244
245
246
247
248
	struct pkg_manifest_key *keys = NULL;
	size_t linecap = 0;
	ssize_t linelen;
	char *map = MAP_FAILED;
	size_t len = 0;
	int hash_it = 0;
	time_t now, last;
	bool in_trans = false, new_repo = true, legacy_repo = false;

	if (access(name, R_OK) != -1)
		new_repo = false;

	pkg_debug(1, "Pkgrepo, begin incremental update of '%s'", name);
	if ((rc = pkgdb_repo_open(name, false, &sqlite)) != EPKG_OK) {
		return (EPKG_FATAL);
	}







	if ((rc = pkgdb_repo_init(sqlite)) != EPKG_OK) {
		goto cleanup;
	}

	if ((rc = pkg_repo_register(repo, sqlite)) != EPKG_OK)
		goto cleanup;







|





|


>
>
>
>
>
>







226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
	struct pkg_manifest_key *keys = NULL;
	size_t linecap = 0;
	ssize_t linelen;
	char *map = MAP_FAILED;
	size_t len = 0;
	int hash_it = 0;
	time_t now, last;
	bool in_trans = false, new_repo = true, legacy_repo = false, reuse_repo;

	if (access(name, R_OK) != -1)
		new_repo = false;

	pkg_debug(1, "Pkgrepo, begin incremental update of '%s'", name);
	if ((rc = pkgdb_repo_open(name, false, &sqlite, &reuse_repo)) != EPKG_OK) {
		return (EPKG_FATAL);
	}

	if (!reuse_repo) {
		pkg_debug(1, "Pkgrepo, need to re-create database '%s'", name);
		local_t = 0;
		*mtime = 0;
	}

	if ((rc = pkgdb_repo_init(sqlite)) != EPKG_OK) {
		goto cleanup;
	}

	if ((rc = pkg_repo_register(repo, sqlite)) != EPKG_OK)
		goto cleanup;

Changes to libpkg/pkgdb_repo.c.

315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330


331
332
333
334
335
336
337
...
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
			STMT(i) = NULL;
		}
	}
	return;
}

int
pkgdb_repo_open(const char *repodb, bool force, sqlite3 **sqlite)

{
	bool incremental = false;
	bool db_not_open;
	int reposcver;
	int retcode = EPKG_OK;

	if (access(repodb, R_OK) == 0)
		incremental = true;



	sqlite3_initialize();
	db_not_open = true;
	while (db_not_open) {
		if (sqlite3_open(repodb, sqlite) != SQLITE_OK) {
			sqlite3_shutdown();
			return (EPKG_FATAL);
................................................................................

		db_not_open = false;

		/* If the schema is too old, or we're forcing a full
			   update, then we cannot do an incremental update.
			   Delete the existing repo, and promote this to a
			   full update */
		if (!incremental)
			continue;
		retcode = get_repo_user_version(*sqlite, "main", &reposcver);
		if (retcode != EPKG_OK)
			return (EPKG_FATAL);
		if (force || reposcver != REPO_SCHEMA_VERSION) {
			if (reposcver != REPO_SCHEMA_VERSION)
				pkg_emit_error("re-creating repo to upgrade schema version "
						"from %d to %d", reposcver,
						REPO_SCHEMA_VERSION);
			sqlite3_close(*sqlite);
			unlink(repodb);
			incremental = false;
			db_not_open = true;
		}
	}

	sqlite3_create_function(*sqlite, "file_exists", 2, SQLITE_ANY, NULL,
	    file_exists, NULL, NULL);

	if (!incremental) {
		retcode = sql_exec(*sqlite, initsql, REPO_SCHEMA_VERSION);
		if (retcode != EPKG_OK)
			return (retcode);
	}

	return (EPKG_OK);
}







|
>

<





|
>
>







 







|











|







|







315
316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
...
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
			STMT(i) = NULL;
		}
	}
	return;
}

int
pkgdb_repo_open(const char *repodb, bool force, sqlite3 **sqlite,
	bool *incremental)
{

	bool db_not_open;
	int reposcver;
	int retcode = EPKG_OK;

	if (access(repodb, R_OK) == 0)
		*incremental = true;
	else
		*incremental = false;

	sqlite3_initialize();
	db_not_open = true;
	while (db_not_open) {
		if (sqlite3_open(repodb, sqlite) != SQLITE_OK) {
			sqlite3_shutdown();
			return (EPKG_FATAL);
................................................................................

		db_not_open = false;

		/* If the schema is too old, or we're forcing a full
			   update, then we cannot do an incremental update.
			   Delete the existing repo, and promote this to a
			   full update */
		if (!*incremental)
			continue;
		retcode = get_repo_user_version(*sqlite, "main", &reposcver);
		if (retcode != EPKG_OK)
			return (EPKG_FATAL);
		if (force || reposcver != REPO_SCHEMA_VERSION) {
			if (reposcver != REPO_SCHEMA_VERSION)
				pkg_emit_error("re-creating repo to upgrade schema version "
						"from %d to %d", reposcver,
						REPO_SCHEMA_VERSION);
			sqlite3_close(*sqlite);
			unlink(repodb);
			*incremental = false;
			db_not_open = true;
		}
	}

	sqlite3_create_function(*sqlite, "file_exists", 2, SQLITE_ANY, NULL,
	    file_exists, NULL, NULL);

	if (!*incremental) {
		retcode = sql_exec(*sqlite, initsql, REPO_SCHEMA_VERSION);
		if (retcode != EPKG_OK)
			return (retcode);
	}

	return (EPKG_OK);
}

Changes to libpkg/private/pkgdb.h.

68
69
70
71
72
73
74


75
76
77

78
79
80
81
82
83
84
void pkgshell_open(const char **r);

/**
 * Open repodb for specified path
 * @param repodb path of repodb
 * @param force create repository if not exists
 * @param sqlite destination db pointer


 * @return EPKG_OK if succeed
 */
int pkgdb_repo_open(const char *repodb, bool force, sqlite3 **sqlite);


/**
 * Init repository for pkgdb_repo* functions
 * @param sqlite sqlite object
 * @return EPKG_OK if succeed
 */
int pkgdb_repo_init(sqlite3 *sqlite);







>
>


|
>







68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
void pkgshell_open(const char **r);

/**
 * Open repodb for specified path
 * @param repodb path of repodb
 * @param force create repository if not exists
 * @param sqlite destination db pointer
 * @param incremental if this param is set to false, then database was re-created
 *  and thus needs to be updated
 * @return EPKG_OK if succeed
 */
int pkgdb_repo_open(const char *repodb, bool force, sqlite3 **sqlite,
	bool *incremental);

/**
 * Init repository for pkgdb_repo* functions
 * @param sqlite sqlite object
 * @return EPKG_OK if succeed
 */
int pkgdb_repo_init(sqlite3 *sqlite);