Revision: 77746
http://sourceforge.net/p/brlcad/code/77746
Author: brlcad
Date: 2020-11-18 23:46:20 +0000 (Wed, 18 Nov 2020)
Log Message:
-----------
make mvall continue even when source doesn't exist
previously, mvall would halt early if the source object doesn't exist,
but per the documentation, the command is supposed to update all
objects and references. thus the only error condition should be if
there is no object AND no references or some other error condition
exists.
Modified Paths:
--------------
brlcad/trunk/src/libged/move_all/move_all.c
Modified: brlcad/trunk/src/libged/move_all/move_all.c
===================================================================
--- brlcad/trunk/src/libged/move_all/move_all.c 2020-11-18 22:06:26 UTC (rev
77745)
+++ brlcad/trunk/src/libged/move_all/move_all.c 2020-11-18 23:46:20 UTC (rev
77746)
@@ -45,11 +45,11 @@
struct rt_comb_internal *comb;
struct bu_ptbl stack;
- /* rename the record itself */
- if ((dp = db_lookup(gedp->ged_wdbp->dbip, old_name, LOOKUP_NOISY)) ==
RT_DIR_NULL)
- return GED_ERROR;
+ /* check the old_name source and new_name target */
- if (db_lookup(gedp->ged_wdbp->dbip, new_name, LOOKUP_QUIET) !=
RT_DIR_NULL) {
+ dp = db_lookup(gedp->ged_wdbp->dbip, old_name, LOOKUP_NOISY);
+
+ if (dp && db_lookup(gedp->ged_wdbp->dbip, new_name, LOOKUP_QUIET) !=
RT_DIR_NULL) {
bu_vls_printf(gedp->ged_result_str, "%s: already exists", new_name);
return GED_ERROR;
}
@@ -57,49 +57,56 @@
/* if this was a sketch, we need to look for all the extrude
* objects that might use it.
*
- * This has to be done here, before we rename the (possible) sketch object
- * because the extrude will do a rt_db_get on the sketch when we call
- * rt_db_get_internal on it.
+ * This has to be done here, before we rename the (possible)
+ * sketch object because the extrude will do a rt_db_get on the
+ * sketch when we call rt_db_get_internal on it.
*/
- if (dp->d_major_type == DB5_MAJORTYPE_BRLCAD && \
- dp->d_minor_type == DB5_MINORTYPE_BRLCAD_SKETCH) {
-
+ if (dp
+ && dp->d_major_type == DB5_MAJORTYPE_BRLCAD
+ && dp->d_minor_type == DB5_MINORTYPE_BRLCAD_SKETCH)
+ {
struct directory *dirp;
for (i = 0; i < RT_DBNHASH; i++) {
for (dirp = gedp->ged_wdbp->dbip->dbi_Head[i]; dirp != RT_DIR_NULL;
dirp = dirp->d_forw) {
+ struct rt_extrude_internal *extrude;
- if (dirp->d_major_type == DB5_MAJORTYPE_BRLCAD && \
- dirp->d_minor_type == DB5_MINORTYPE_BRLCAD_EXTRUDE) {
- struct rt_extrude_internal *extrude;
+ if (dirp->d_major_type != DB5_MAJORTYPE_BRLCAD || \
+ dirp->d_minor_type != DB5_MINORTYPE_BRLCAD_EXTRUDE) {
+ continue;
+ }
- if (rt_db_get_internal(&intern, dirp, gedp->ged_wdbp->dbip,
(fastf_t *)NULL, &rt_uniresource) < 0) {
- bu_log("Can't get extrude %s?\n", dirp->d_namep);
- continue;
- }
- extrude = (struct rt_extrude_internal *)intern.idb_ptr;
- RT_EXTRUDE_CK_MAGIC(extrude);
+ if (rt_db_get_internal(&intern, dirp, gedp->ged_wdbp->dbip,
(fastf_t *)NULL, &rt_uniresource) < 0) {
+ bu_log("WARNING: Can't get extrude %s?\n", dirp->d_namep);
+ continue;
+ }
- if (BU_STR_EQUAL(extrude->sketch_name, old_name)) {
- if (nflag) {
- bu_vls_printf(gedp->ged_result_str, "%s ",
dirp->d_namep);
- rt_db_free_internal(&intern);
- } else {
- bu_free(extrude->sketch_name, "sketch name");
- extrude->sketch_name = bu_strdup(new_name);
+ extrude = (struct rt_extrude_internal *)intern.idb_ptr;
+ RT_EXTRUDE_CK_MAGIC(extrude);
- if (rt_db_put_internal(dirp, gedp->ged_wdbp->dbip,
&intern, &rt_uniresource) < 0) {
- bu_log("oops\n");
- }
- }
- } else
- rt_db_free_internal(&intern);
+ if (!BU_STR_EQUAL(extrude->sketch_name, old_name)) {
+ rt_db_free_internal(&intern);
+ continue;
}
+
+ if (nflag) {
+ bu_vls_printf(gedp->ged_result_str, "%s ", dirp->d_namep);
+ rt_db_free_internal(&intern);
+ continue;
+ }
+
+ bu_free(extrude->sketch_name, "sketch name");
+ extrude->sketch_name = bu_strdup(new_name);
+
+ if (rt_db_put_internal(dirp, gedp->ged_wdbp->dbip, &intern,
&rt_uniresource) < 0) {
+ bu_log("INTERNAL ERROR: unable to write sketch [%s] during
mvall\n", new_name);
+ }
+ rt_db_free_internal(&intern);
}
}
}
- if (!nflag) {
+ if (!nflag && dp) {
/* Change object name in the directory. */
if (db_rename(gedp->ged_wdbp->dbip, dp, new_name) < 0) {
bu_vls_printf(gedp->ged_result_str, "error in rename to %s,
aborting", new_name);
@@ -106,7 +113,7 @@
return GED_ERROR;
}
- /* Change name in the file */
+ /* Change object name on disk */
if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t
*)NULL, &rt_uniresource) < 0) {
bu_vls_printf(gedp->ged_result_str, "Database read error,
aborting");
return GED_ERROR;
@@ -120,7 +127,6 @@
bu_ptbl_init(&stack, 64, "combination stack for wdb_mvall_cmd");
-
/* Examine all COMB nodes */
for (i = 0; i < RT_DBNHASH; i++) {
for (dp = gedp->ged_wdbp->dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp =
dp->d_forw) {
@@ -128,10 +134,14 @@
union tree *comb_leaf;
int done=0;
- if (!(dp->d_flags & RT_DIR_COMB)) continue;
- if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip,
(fastf_t *)NULL, &rt_uniresource) < 0) continue;
+ if (!(dp->d_flags & RT_DIR_COMB))
+ continue;
+ if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip,
(fastf_t *)NULL, &rt_uniresource) < 0)
+ continue;
+
comb = (struct rt_comb_internal *)intern.idb_ptr;
bu_ptbl_reset(&stack);
+
/* visit each leaf in the combination */
comb_leaf = comb->tree;
if (comb_leaf) {
@@ -159,7 +169,8 @@
rt_db_free_internal(&intern);
} else {
int comb_mvall_status = db_comb_mvall(dp, gedp->ged_wdbp->dbip,
old_name, new_name, &stack);
- if (!comb_mvall_status) continue;
+ if (!comb_mvall_status)
+ continue;
if (comb_mvall_status == 2) {
bu_ptbl_free(&stack);
bu_vls_printf(gedp->ged_result_str, "Database write error,
aborting");
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits