]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
vboxsnapshotxmltest: Don't write to a file in abs_srcdir
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 1 Jul 2014 13:23:36 +0000 (15:23 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 1 Jul 2014 14:46:29 +0000 (16:46 +0200)
In the test, the snapshot XML is written into a file that's located
under:

  abs_srcdir/vboxsnapshotxmldata/testResult.vbox

However, the abs_srcdir doesn't have to be necessarily writable. It
should have been abs_builddir instead. Moreover, the label in the func
creating the file is called 'fail' while it fulfils the duty of
'cleanup' label.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
tests/vboxsnapshotxmltest.c

index 7795688e61b82d373dd4d7df352308ac4f7f1257..4ee75375c2d68e812fa4974b588a3a0d5bde8a89 100644 (file)
@@ -59,38 +59,41 @@ testCompareXMLtoXMLFiles(const char *xml)
     char *pathResult = NULL;
     int ret = -1;
     virVBoxSnapshotConfMachinePtr machine = NULL;
-    if (virAsprintf(&pathResult, "%s/vboxsnapshotxmldata/testResult.vbox",
-                    abs_srcdir) < 0)
+
+    if (VIR_STRDUP(pathResult,
+                   abs_builddir "/vboxsnapshotxmldata/testResult.vbox") < 0)
         return -1;
 
+    if (virFileMakePath(abs_builddir "/vboxsnapshotxmldata") < 0)
+        goto cleanup;
+
     if (virtTestLoadFile(xml, &xmlData) < 0)
-        goto fail;
+        goto cleanup;
 
     if (!(machine = virVBoxSnapshotConfLoadVboxFile(xml, (char*)"")))
-        goto fail;
+        goto cleanup;
 
     if (virVBoxSnapshotConfSaveVboxFile(machine, pathResult) < 0)
-        goto fail;
+        goto cleanup;
 
     if (virtTestLoadFile(pathResult, &actual) < 0)
-        goto fail;
-
-    if (unlink(pathResult) < 0)
-        goto fail;
+        goto cleanup;
 
     if (!(actual = testFilterXML(actual)))
-        goto fail;
+        goto cleanup;
     if (!(xmlData = testFilterXML(xmlData)))
-        goto fail;
+        goto cleanup;
 
     if (STRNEQ(actual, xmlData)) {
         virtTestDifference(stderr, xmlData, actual);
-        goto fail;
+        goto cleanup;
     }
 
     ret = 0;
 
- fail:
+ cleanup:
+    unlink(pathResult);
+    rmdir(abs_builddir "/vboxsnapshotxmldata");
     VIR_FREE(xmlData);
     VIR_FREE(actual);
     virVBoxSnapshotConfMachineFree(machine);