socsvn commit: r254274 - in soc2013/mattbw/backend: . actions

mattbw at FreeBSD.org mattbw at FreeBSD.org
Sun Jul 7 02:25:57 UTC 2013


Author: mattbw
Date: Sun Jul  7 02:25:56 2013
New Revision: 254274
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254274

Log:
  more currently fruitless work on installfiles; fix getfiles

Modified:
  soc2013/mattbw/backend/actions/actions.h
  soc2013/mattbw/backend/actions/get-files.c
  soc2013/mattbw/backend/actions/install-files.c
  soc2013/mattbw/backend/pk-backend-pkgng.c

Modified: soc2013/mattbw/backend/actions/actions.h
==============================================================================
--- soc2013/mattbw/backend/actions/actions.h	Sun Jul  7 01:52:05 2013	(r254273)
+++ soc2013/mattbw/backend/actions/actions.h	Sun Jul  7 02:25:56 2013	(r254274)
@@ -31,8 +31,9 @@
 gboolean	get_details_thread(PkBackend *backend);
 gboolean	get_files_thread(PkBackend *backend);
 gboolean	get_repo_list_thread(PkBackend *backend);
-gboolean	install_packages_thread(PkBackend *backend);
 gboolean	install_files_thread(PkBackend *backend);
+gboolean	install_packages_thread(PkBackend *backend);
+gboolean	simulate_install_files_thread(PkBackend *backend);
 gboolean	simulate_install_packages_thread(PkBackend *backend);
 
 #endif				/* !_PKGNG_BACKEND_ACTIONS_H_ */

Modified: soc2013/mattbw/backend/actions/get-files.c
==============================================================================
--- soc2013/mattbw/backend/actions/get-files.c	Sun Jul  7 01:52:05 2013	(r254273)
+++ soc2013/mattbw/backend/actions/get-files.c	Sun Jul  7 02:25:56 2013	(r254274)
@@ -56,12 +56,11 @@
 {
 	gboolean	success;
 	int		err;
-	int		sb_err;
-	char           *filenames;
 	struct pkg_file *file;
 	struct sbuf    *sb;
 
 	success = FALSE;
+	file = NULL;
 
 	/*
 	 * Construct a string of the form ";file1;file2;file3;...". We'll get
@@ -71,22 +70,21 @@
 	for (HASH_FOR(err, pkg_files, pkg, &file))
 		sbuf_printf(sb, ";%s", pkg_file_path(file));
 
-	sb_err = sbuf_finish(sb);
-	if (sb_err) {
-		pk_backend_error_code(query_backend(q),
-				      PK_ERROR_ENUM_INTERNAL_ERROR,
-				      "couldn't construct filename string");
-		goto cleanup;
-	}
-
-	filenames = sbuf_data(sb);
-	/* Skip over any initial ; */
-	if (filenames[0] == ';')
-		filenames++;
+	if (sbuf_finish(sb) != 0)
+		(void)pk_backend_error_code(query_backend(q),
+		    PK_ERROR_ENUM_INTERNAL_ERROR,
+		    "couldn't construct filename string");
+	else {
+		char           *filenames;
+
+		filenames = sbuf_data(sb);
+		/* Skip over any initial ; */
+		if (filenames[0] == ';')
+			filenames++;
 
-	success = pk_backend_files(query_backend(q), id, filenames);
+		success = pk_backend_files(query_backend(q), id, filenames);
+	}
 
-cleanup:
 	sbuf_delete(sb);
 	return success;
 }

Modified: soc2013/mattbw/backend/actions/install-files.c
==============================================================================
--- soc2013/mattbw/backend/actions/install-files.c	Sun Jul  7 01:52:05 2013	(r254273)
+++ soc2013/mattbw/backend/actions/install-files.c	Sun Jul  7 02:25:56 2013	(r254274)
@@ -30,20 +30,114 @@
 
 #include "actions.h"		/* install_files_thread prototype */
 
+static gboolean	do_file(const gchar *path, PkBackend *backend, gboolean simulate);
+static gboolean	do_files(PkBackend *backend, gboolean simulate);
+
 /*
- * The thread that performs an InstallFiles operation. Should be invoked
- * by the pk_backend_install_files hook.
+ * The thread that performs an InstallFiles operation. Should be invoked by
+ * the pk_backend_install_files hook.
  */
 gboolean
 install_files_thread(PkBackend *backend)
 {
-	guint		len;
-	gchar         **package_ids;
+
+	return do_files(backend, FALSE);
+}
+
+/*
+ * The thread that performs a simulated InstallFiles operation. Should be
+ * invoked by the pk_backend_install_files hook.
+ */
+gboolean
+simulate_install_files_thread(PkBackend *backend)
+{
+
+	return do_files(backend, TRUE);
+}
+
+/*
+ * Installs a single package file, or pretends to.
+ */
+static gboolean
+do_file(const gchar *path, PkBackend *backend, gboolean simulate)
+{
+	gboolean	success;
+	struct pkg     *pkg;
+	struct pkg_manifest_key *keys;
+	struct pkgdb *db;
+
+	success = FALSE;
+	pkg = NULL;
+	keys = NULL;
+	db = NULL;
+
+	(void)pkg_manifest_keys_new(&keys);
+
+	if (simulate) {
+		(void)pk_backend_set_status(backend, PK_STATUS_ENUM_RUNNING);
+
+		if (pkg_open(&pkg, path, keys, PKG_FLAG_NONE) != EPKG_OK) {
+			(void)pk_backend_error_code(backend,
+			    PK_ERROR_ENUM_PACKAGE_CORRUPT,
+			    "could not open file");
+			goto cleanup;
+		}
+		pkgutils_emit(pkg, backend, pkgutils_pkg_install_state(pkg));
+
+		success = TRUE;
+	} else {
+		/* TODO: event hook */
+
+		if (open_remote_db(&db, backend) != EPKG_OK)
+			goto cleanup;
+		
+		(void)pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL);
+
+		if (pkg_add(db, path, PKG_FLAG_NONE, keys) != EPKG_OK) {
+			(void)pk_backend_error_code(backend,
+			    PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL,
+			    "could not install file");
+			goto cleanup;
+		}
+
+		success = TRUE;
+	}
+
+cleanup:
+	pkgdb_close(db);
+	pkg_free(pkg);
+	pkg_manifest_keys_free(keys);
 	
-	package_ids = pk_backend_get_strv(backend, "package_ids");
-	len = g_strv_length(package_ids);
+	return success;
+}
 
-	pk_backend_finished(backend);
+/*
+ * Does a file install operation, or a simulation thereof.
+ */
+static gboolean
+do_files(PkBackend *backend, gboolean simulate)
+{
+	gboolean	success;
+	gchar         **paths;
 
-	return FALSE;
+	success = FALSE;
+
+	paths = pk_backend_get_strv(backend, "full_paths");
+	if (paths == NULL)
+		(void)pk_backend_error_code(backend,
+		    PK_ERROR_ENUM_INTERNAL_ERROR,
+		    "could not get path vector");
+	else if (*paths == NULL)
+		(void)pk_backend_error_code(backend,
+		    PK_ERROR_ENUM_INTERNAL_ERROR,
+		    "path vector is empty");
+	else {
+		gchar   **p;
+
+		for (p = paths, success = TRUE; *p != NULL && success; p++)
+			success = do_file(*p, backend, simulate);
+	}
+
+	pk_backend_finished(backend);
+	return success;
 }

Modified: soc2013/mattbw/backend/pk-backend-pkgng.c
==============================================================================
--- soc2013/mattbw/backend/pk-backend-pkgng.c	Sun Jul  7 01:52:05 2013	(r254273)
+++ soc2013/mattbw/backend/pk-backend-pkgng.c	Sun Jul  7 02:25:56 2013	(r254274)
@@ -132,19 +132,21 @@
 
 	INTENTIONALLY_IGNORE(backend);
 
-	 /* (Backformed from pkg.h: pkg_formats) */
-	return g_strdup("application/x-gzip;"
-	    "application/x-tar;"
-	    "application/x-bzip2;"
-	    "application/x-xz;");
+	/*
+	 * (Backformed from pkg.h: pkg_formats) and using `gvfs-info filename
+	 * -a "standard::content-type"
+	 */
+	return g_strdup("application/x-tar;"
+	    "application/x-compressed-tar;"
+	    "application/x-bzip-compressed-tar;"
+	    "application/x-xz-compressed-tar;");
 }
 
 void
 pk_backend_get_repo_list(PkBackend *backend, PkBitfield filters)
 {
 
-	INTENTIONALLY_IGNORE(filters);		/* not yet supported */
-
+	INTENTIONALLY_IGNORE(filters);	/* not yet supported */
 	pk_backend_thread_create(backend, get_repo_list_thread);
 }
 
@@ -169,11 +171,17 @@
 }
 
 void
-pk_backend_simulate_install_packages(PkBackend *backend, gchar **package_ids)
+pk_backend_simulate_install_files(PkBackend *backend, gchar **full_paths)
 {
 
-	INTENTIONALLY_IGNORE(package_ids);
-
+	INTENTIONALLY_IGNORE(full_paths);	/* retrieved from backend */
 	pk_backend_thread_create(backend, simulate_install_packages_thread);
 }
 
+void
+pk_backend_simulate_install_packages(PkBackend *backend, gchar **package_ids)
+{
+
+	INTENTIONALLY_IGNORE(package_ids);	/* retrieved from backend */
+	pk_backend_thread_create(backend, simulate_install_packages_thread);
+}


More information about the svn-soc-all mailing list