]> xenbits.xensource.com Git - libvirt.git/commitdiff
test: storage: Initialize storage source to correct type
authorPeter Krempa <pkrempa@redhat.com>
Fri, 25 Apr 2014 19:44:06 +0000 (21:44 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 3 Jun 2014 07:27:23 +0000 (09:27 +0200)
Stat the path of the storage file being tested to set the correct type
into the virStorageSource. This will avoid breaking the test suite when
inquiring metadata of directory paths in the next patches.

tests/virstoragetest.c

index fb96c71d07644f49a3035006e0aad3aeb24aa58d..746bf63fc9215f4b7ada29acf65c6e1927508960 100644 (file)
@@ -98,6 +98,7 @@ testStorageFileGetMetadata(const char *path,
                            uid_t uid, gid_t gid,
                            bool allow_probe)
 {
+    struct stat st;
     virStorageSourcePtr ret = NULL;
 
     if (VIR_ALLOC(ret) < 0)
@@ -106,6 +107,15 @@ testStorageFileGetMetadata(const char *path,
     ret->type = VIR_STORAGE_TYPE_FILE;
     ret->format = format;
 
+    if (stat(path, &st) == 0) {
+        if (S_ISDIR(st.st_mode)) {
+            ret->type = VIR_STORAGE_TYPE_DIR;
+            ret->format = VIR_STORAGE_FILE_DIR;
+        } else if (S_ISBLK(st.st_mode)) {
+            ret->type = VIR_STORAGE_TYPE_BLOCK;
+        }
+    }
+
     if (VIR_STRDUP(ret->relPath, path) < 0)
         goto error;