[patch iwhd 3/5] Drop slash from template names

Pete Zaitcev zaitcev at redhat.com
Tue Apr 5 22:51:29 UTC 2011


The 0.92 and HEAD produce an RHEV-M template with a name that starts
with a slash. Looks like another well-meaning change regressing.

---
 dc-rhev-image.c |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

commit c177ce9663751a8cb49e59c8267ac2a74e318bb5
Author: Pete Zaitcev <zaitcev at yahoo.com>
Date:   Tue Apr 5 16:10:44 2011 -0600

    Dispose of slash in image names after upload.

diff --git a/dc-rhev-image.c b/dc-rhev-image.c
index e944343..50fbdbd 100644
--- a/dc-rhev-image.c
+++ b/dc-rhev-image.c
@@ -231,6 +231,18 @@ static int path_exists(const char *path)
 	return access(path, R_OK) == 0;
 }
 
+/* This is basename(), but we handroll it to make sure, due to BSD. */
+static char *image_name(char *path)
+{
+	char *name;
+
+	if (!(name = strrchr(path, '/')) || name[1]==0)
+		name = path;
+	else
+		name++;
+	return name;
+}
+
 static void
 cfg_veripick(char **cfgval, const char *cfgname, json_t *jcfg,
 	     const char *cfgtag)
@@ -980,13 +992,8 @@ static void spitovf(struct config *cfg, struct stor_dom *sd,
 	rc = xmlTextWriterWriteAttribute(writer,
 	    BAD_CAST "ovf:size", BAD_CAST buf100);
 	if (rc < 0) goto err_xml;
-	/* This is basename(), but we handroll it to make sure, due to BSD. */
-	if (!(s = strrchr(cfg->image, '/')) || s[1]==0)
-		s = cfg->image;
-	else
-		s++;
 	rc = xmlTextWriterWriteAttribute(writer,
-	    BAD_CAST "ovf:description", BAD_CAST s);
+	    BAD_CAST "ovf:description", BAD_CAST image_name(cfg->image));
 	if (rc < 0) goto err_xml;
 	rc = xmlTextWriterEndElement(writer);	/* close <File> */
 	if (rc < 0) goto err_xml;
@@ -1070,7 +1077,7 @@ static void spitovf(struct config *cfg, struct stor_dom *sd,
 	    BAD_CAST "ovf:id", BAD_CAST "out");
 	if (rc < 0) goto err_xml;
 
-	if (!(s = strrchr(cfg->image, '/'))) s = cfg->image;
+	s = image_name(cfg->image);
 	rc = xmlTextWriterWriteElement(writer, BAD_CAST "Name", BAD_CAST s);
 	if (rc < 0) goto err_xml;
 


More information about the iwhd-devel mailing list