[anjuta] am-project: Avoid a crash when parent group is missing
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] am-project: Avoid a crash when parent group is missing
- Date: Sat, 31 Mar 2012 20:54:50 +0000 (UTC)
commit 3cc4f777e5b52055de97a391e4355b335900a976
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Fri Mar 30 15:58:02 2012 +0200
am-project: Avoid a crash when parent group is missing
plugins/am-project/am-writer.c | 110 +++++++++++++++++++------------------
plugins/am-project/amp-group.c | 15 +++++-
plugins/am-project/tests/empty.at | 33 +++++++++--
3 files changed, 98 insertions(+), 60 deletions(-)
---
diff --git a/plugins/am-project/am-writer.c b/plugins/am-project/am-writer.c
index 5462e0e..eedb520 100644
--- a/plugins/am-project/am-writer.c
+++ b/plugins/am-project/am-writer.c
@@ -282,10 +282,10 @@ anjuta_token_find_target_property_position (AmpTargetNode *target,
pos = anjuta_token_insert_token_list (after, pos,
ANJUTA_TOKEN_EOL, "\n",
- NULL);
+ NULL);
pos = anjuta_token_insert_token_list (after, pos,
ANJUTA_TOKEN_EOL, "\n",
- NULL);
+ NULL);
amp_group_node_update_makefile (group, pos);
@@ -357,41 +357,44 @@ anjuta_token_find_group_property_position (AmpGroupNode *group,
after = TRUE;
}
- /* 3. Create new file */
- if (pos == NULL)
+ /* makefile can be NULL for the root node if there isn't any corresponding Makefile.am */
+ if (makefile != NULL)
{
- /* Empty file */
- pos = anjuta_token_new_string (ANJUTA_TOKEN_COMMENT | ANJUTA_TOKEN_ADDED, "## Process this file with automake to produce Makefile.in\n");
- anjuta_token_append_child (makefile, pos);
- amp_group_node_update_makefile (group, pos);
- }
+ /* 3. Create new file */
+ if (pos == NULL)
+ {
+ /* Empty file */
+ pos = anjuta_token_new_string (ANJUTA_TOKEN_COMMENT | ANJUTA_TOKEN_ADDED, "## Process this file with automake to produce Makefile.in\n");
+ anjuta_token_append_child (makefile, pos);
+ amp_group_node_update_makefile (group, pos);
+ }
- /* Find end of line */
- if (after)
- {
- while (pos != NULL)
+ /* Find end of line */
+ if (after)
{
- if (anjuta_token_get_type (pos) == ANJUTA_TOKEN_EOL) break;
- if (anjuta_token_next (pos) == NULL)
+ while (pos != NULL)
{
- pos = anjuta_token_insert_token_list (after, pos,
- ANJUTA_TOKEN_EOL, "\n",
- NULL);
+ if (anjuta_token_get_type (pos) == ANJUTA_TOKEN_EOL) break;
+ if (anjuta_token_next (pos) == NULL)
+ {
+ pos = anjuta_token_insert_token_list (after, pos,
+ ANJUTA_TOKEN_EOL, "\n",
+ NULL);
- break;
+ break;
+ }
+ pos = anjuta_token_next (pos);
}
- pos = anjuta_token_next (pos);
}
- }
-
- pos = anjuta_token_insert_token_list (after, pos,
- ANJUTA_TOKEN_EOL, "\n",
- NULL);
- pos = anjuta_token_insert_token_list (after, pos,
- ANJUTA_TOKEN_EOL, "\n",
- NULL);
- amp_group_node_update_makefile (group, pos);
+ pos = anjuta_token_insert_token_list (after, pos,
+ ANJUTA_TOKEN_EOL, "\n",
+ NULL);
+ pos = anjuta_token_insert_token_list (after, pos,
+ ANJUTA_TOKEN_EOL, "\n",
+ NULL);
+ amp_group_node_update_makefile (group, pos);
+ }
return pos;
}
@@ -439,6 +442,7 @@ amp_project_write_config_list (AmpProject *project)
ANJUTA_TOKEN_LIST, NULL,
ANJUTA_TOKEN_LAST, NULL,
RIGHT_PAREN, ")",
+ ANJUTA_TOKEN_EOL, "\n",
NULL);
return token;
@@ -511,9 +515,6 @@ amp_group_node_create_token (AmpProject *project, AmpGroupNode *group, GError *
}
if (sibling == NULL) after = TRUE;
- /* Create directory */
- g_file_make_directory (directory, NULL, NULL);
-
/* Create Makefile.am */
basename = amp_group_node_get_makefile_name (parent);
if (basename != NULL)
@@ -525,8 +526,6 @@ amp_group_node_create_token (AmpProject *project, AmpGroupNode *group, GError *
{
makefile = g_file_get_child (directory, "Makefile.am");
}
- g_file_replace_contents (makefile, "", 0, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, NULL);
-
/* Add in configure */
list = NULL;
@@ -571,14 +570,17 @@ amp_group_node_create_token (AmpProject *project, AmpGroupNode *group, GError *
{
list = anjuta_token_find_group_property_position (parent, AM_TOKEN_SUBDIRS);
- list = anjuta_token_insert_token_list (FALSE, list,
- AM_TOKEN_SUBDIRS, "SUBDIRS",
- ANJUTA_TOKEN_SPACE, " ",
- ANJUTA_TOKEN_OPERATOR, "=",
- ANJUTA_TOKEN_LIST, NULL,
- ANJUTA_TOKEN_LAST, NULL,
- NULL);
- list = anjuta_token_next (anjuta_token_next ( anjuta_token_next (list)));
+ if (list != NULL)
+ {
+ list = anjuta_token_insert_token_list (FALSE, list,
+ AM_TOKEN_SUBDIRS, "SUBDIRS",
+ ANJUTA_TOKEN_SPACE, " ",
+ ANJUTA_TOKEN_OPERATOR, "=",
+ ANJUTA_TOKEN_LIST, NULL,
+ ANJUTA_TOKEN_LAST, NULL,
+ NULL);
+ list = anjuta_token_next (anjuta_token_next ( anjuta_token_next (list)));
+ }
}
else
{
@@ -1149,11 +1151,11 @@ amp_source_node_create_token (AmpProject *project, AmpSourceNode *source, GErro
args = anjuta_token_insert_token_list (FALSE, var,
ANJUTA_TOKEN_LIST, NULL,
- ANJUTA_TOKEN_NAME, target_var,
- ANJUTA_TOKEN_SPACE, " ",
+ ANJUTA_TOKEN_NAME, target_var,
+ ANJUTA_TOKEN_SPACE, " ",
ANJUTA_TOKEN_OPERATOR, "=",
- ANJUTA_TOKEN_LIST, NULL,
- ANJUTA_TOKEN_SPACE, " ",
+ ANJUTA_TOKEN_LIST, NULL,
+ ANJUTA_TOKEN_SPACE, " ",
NULL);
args = anjuta_token_last_item (args);
@@ -1272,14 +1274,14 @@ amp_project_write_property_list (AmpGroupNode *group, AnjutaProjectNode *node, A
}
pos = anjuta_token_insert_token_list (FALSE, pos,
- info->token_type, NULL,
- ANJUTA_TOKEN_NAME, name,
- ANJUTA_TOKEN_SPACE, " ",
- ANJUTA_TOKEN_OPERATOR, "=",
- ANJUTA_TOKEN_SPACE, " ",
- ANJUTA_TOKEN_LIST, NULL,
- ANJUTA_TOKEN_SPACE, " ",
- NULL);
+ info->token_type, NULL,
+ ANJUTA_TOKEN_NAME, name,
+ ANJUTA_TOKEN_SPACE, " ",
+ ANJUTA_TOKEN_OPERATOR, "=",
+ ANJUTA_TOKEN_SPACE, " ",
+ ANJUTA_TOKEN_LIST, NULL,
+ ANJUTA_TOKEN_SPACE, " ",
+ NULL);
g_free (name);
diff --git a/plugins/am-project/amp-group.c b/plugins/am-project/amp-group.c
index fe8ea53..759347b 100644
--- a/plugins/am-project/amp-group.c
+++ b/plugins/am-project/amp-group.c
@@ -594,10 +594,23 @@ amp_group_node_save (AmpNode *group, AmpNode *parent, AmpProject *project, GErro
AnjutaTokenFile *tfile;
AnjutaProjectNode *child;
gboolean ok = TRUE;
+ GFile *directory;
+
+ /* Create directory */
+ directory = g_file_get_parent (AMP_GROUP_NODE (group)->makefile);
+ g_file_make_directory (directory, NULL, NULL);
+ g_object_unref (directory);
/* Save group */
tfile = AMP_GROUP_NODE (group)->tfile;
- if (tfile == NULL) return FALSE;
+ if (tfile == NULL)
+ {
+ /* Create an empty makefile */
+ g_file_replace_contents (AMP_GROUP_NODE (group)->makefile, "", 0, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, NULL);
+
+ return TRUE;
+ }
+
if (anjuta_token_file_is_dirty (tfile))
{
if (!anjuta_token_file_save (tfile, error)) return FALSE;
diff --git a/plugins/am-project/tests/empty.at b/plugins/am-project/tests/empty.at
index aa7d710..91cec10 100644
--- a/plugins/am-project/tests/empty.at
+++ b/plugins/am-project/tests/empty.at
@@ -1,17 +1,40 @@
AT_SETUP([Load empty project])
-AS_MKDIR_P([empty])
-AT_DATA([empty/configure.ac],
+AS_MKDIR_P([empty1])
+AT_DATA([empty1/configure.ac],
[[AC_CONFIG_FILES(Makefile)
]])
-AT_DATA([empty/Makefile.am],
+AT_DATA([empty1/Makefile.am],
[[
]])
AT_DATA([expect],
-[[ROOT (): empty
+[[ROOT (): empty1
SOURCE (): configure.ac
SOURCE (): Makefile.am
]])
-AT_PARSER_CHECK([load empty \
+AT_PARSER_CHECK([load empty1 \
list])
AT_CHECK([diff output expect])
+
+
+
+AS_MKDIR_P([empty2])
+AT_DATA([empty2/configure.ac],
+[[]])
+AT_DATA([empty2/Makefile.am],
+[[]])
+AT_DATA([expect],
+[[ROOT (): empty3
+ GROUP (): group1
+ SOURCE (): group1/Makefile.am
+ SOURCE (): configure.ac
+]])
+AT_PARSER_CHECK([load empty2 \
+ move empty3 \
+ add group 0 group1 \
+ save \
+ list])
+AT_CHECK([diff output expect])
+
+
+
AT_CLEANUP
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]