patch commited to gnome-build



Hi,

I just commited this patch to gnome-build.  It solves some issues when
adding a source to a project.

Gustavo

? .tm_project.cache
? autom4te.cache
? stamp-h1
? idl/Makefile
? idl/Makefile.in
? src/backends/libgbf_am/gbf-am-parse
? src/backends/libgbf_am/gbf-am-project.c.patch
? src/backends/libgbf_am/GBF/Makefile
? src/backends/libgbf_am/GBF/Makefile.in
? src/controls/gbf-project-model.c
? src/controls/gbf-project-model.h
? src/controls/gbf-project-tree.c.sort
? src/controls/gbf-project-view.c
? src/controls/gbf-project-view.h
? src/controls/test-project-view
? src/controls/test-project-view.c
? src/lib/gnome-build-common.c
? src/lib/gnome-build-skels.c
? src/lib/gnome-build-stubs.c
? src/lib/gnome-build.h
? src/lib/test
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-build/ChangeLog,v
retrieving revision 1.106
diff -u -r1.106 ChangeLog
--- ChangeLog	13 Sep 2002 14:39:53 -0000	1.106
+++ ChangeLog	17 Sep 2002 13:07:27 -0000
@@ -1,3 +1,12 @@
+2002-09-17  Gustavo Giráldez <gustavo giraldez gmx net>
+
+	* src/backends/libgbf_am/gbf-am-project.c (write_source): Change
+	the source's root path to the project root directory.
+	(impl_add_source): Check that the source we're adding is inside
+	the project tree.
+	* src/lib/gbf-project.c (gbf_project_error_quark): use
+	g_quark_from_string instead of g_quark_from_static_string.
+
 2002-09-13  Gustavo Giráldez  <gustavo giraldez gmx net>
 
 	* configure.in: Add BACKEND_DIR define instead of hardcoding it in
Index: src/backends/libgbf_am/gbf-am-project.c
===================================================================
RCS file: /cvs/gnome/gnome-build/src/backends/libgbf_am/gbf-am-project.c,v
retrieving revision 1.27
diff -u -r1.27 gbf-am-project.c
--- src/backends/libgbf_am/gbf-am-project.c	13 Sep 2002 14:39:54 -0000	1.27
+++ src/backends/libgbf_am/gbf-am-project.c	17 Sep 2002 13:07:33 -0000
@@ -296,16 +296,49 @@
 	return trg;
 }
 
+/**
+ * chroot_path:
+ * @root: root path
+ * @path: the path which must be inside @root for which the root-changed path is wanted
+ * 
+ * If @root is the parent of @path, returns an absolute path as if the
+ * root of the hierarchy was @root.
+ * 
+ * Return value: a pointer to the root-changed path inside @path
+ **/
+static const gchar *
+chroot_path (const gchar *root, const gchar *path)
+{
+	gint root_length;
+
+	g_return_val_if_fail (root != NULL, NULL);
+	g_return_val_if_fail (path != NULL, NULL);
+	
+	root_length = strlen (root);
+	if (strncmp (root, path, root_length))
+		/* @root is not parent of @path */
+		return NULL;
+
+	/* check for trailing path separator in root... we need it to
+	 * make the returned path absolute */
+	if (root [root_length - 1] == '/')
+		root_length--;
+
+	return path + root_length;
+}
+	     
 static xmlNodePtr
 write_source (GbfAmProject *prj, xmlDocPtr doc, xmlNodePtr node, GbfAmTargetSource *source)
 {
 	xmlNodePtr src;
+	const gchar *filename;
 
 	src = xmlNewDocNode (doc, NULL, "source", NULL);
 	g_assert (prj->priv->project_dir);
-	/* FIXME: actually check that the source uri is inside the project root */
-	/* skip file:/// and the project root from the uri */
-	xmlSetProp (src, "uri", source->uri + 7 + strlen (prj->priv->project_dir));
+
+	/* FIXME: make this work with generalized URIs */
+	filename = chroot_path (prj->priv->project_dir, source->uri);
+	xmlSetProp (src, "uri", filename);
 	xmlAddChild (node, src);
 
 	return src;
@@ -1995,9 +2028,17 @@
 	GbfAmProject *prj = GBF_AM_PROJECT (project);
 	GbfAmTargetSource *source;
 	xmlDocPtr doc;
-	char id[1024];
 
-	/* FIXME: check that the source is inside the project dir */
+	/* Check that the source uri is inside the project root */
+	if (strncmp (prj->priv->project_dir, uri, strlen (prj->priv->project_dir))) {
+		g_warning ("file must be in the project directory");
+		if (error) {
+			*error = g_error_new (GBF_PROJECT_ERROR,
+					      GBF_PROJECT_ERROR_DOESNT_EXIST,
+					      _("Source file must be inside the project directory"));
+		}
+		return NULL;
+	}
 	
 	/* --- FIXME: this should not be done here.  Instead we should
 	   read the output of the script for changes in the group */
@@ -2007,8 +2048,7 @@
 	source->uri = g_strdup (uri);
 
 	/* Compute the id */
-	g_snprintf (id, 1024, "%s%s", target_id, source->uri);
-	source->id = g_strdup (id);
+	source->id = g_strdup_printf ("%s%s", target_id, source->uri);
 	source->target = g_hash_table_lookup (prj->priv->targets, target_id);
 
 	/* Create the update xml */
Index: src/lib/gbf-project.c
===================================================================
RCS file: /cvs/gnome/gnome-build/src/lib/gbf-project.c,v
retrieving revision 1.2
diff -u -r1.2 gbf-project.c
--- src/lib/gbf-project.c	1 Sep 2002 20:53:25 -0000	1.2
+++ src/lib/gbf-project.c	17 Sep 2002 13:07:34 -0000
@@ -360,7 +360,7 @@
 	static GQuark quark = 0;
 
 	if (quark == 0)
-		quark = g_quark_from_static_string ("gbf-project-quark");
+		quark = g_quark_from_string ("gbf-project-quark");
 
 	return quark;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]