]> granicus.if.org Git - p11-kit/commitdiff
tests: Fix temp file permission before deleting
authorDaiki Ueno <dueno@redhat.com>
Sun, 16 Jun 2019 09:06:35 +0000 (11:06 +0200)
committerDaiki Ueno <ueno@gnu.org>
Tue, 18 Jun 2019 12:17:28 +0000 (14:17 +0200)
On mingw64/wine, unlink fails if the file has no write bit.

trust/test-module.c

index 4024d81643842a12cd8e16dcbcd5489b01527560..227b483b29bafcdf246541c57811d8b8d8e70f4d 100644 (file)
@@ -70,6 +70,7 @@ struct {
        char *directory;
        p11_asn1_cache *cache;
        p11_parser *parser;
+       char *unreadable;
 } test;
 
 static void
@@ -119,6 +120,10 @@ teardown (void *unused)
        rv = test.module->C_Finalize (NULL);
        assert (rv == CKR_OK);
 
+       if (test.unreadable)
+               chmod (test.unreadable, 0644);
+       free (test.unreadable);
+
        if (test.directory)
                p11_test_directory_delete (test.directory);
        free (test.directory);
@@ -170,7 +175,7 @@ setup_unreadable (void *unused)
 {
        CK_C_INITIALIZE_ARGS args;
        const char *paths;
-       char *p, *pp, *anchors;
+       char *p, *anchors;
        FILE *f, *ff;
        char buffer[4096];
        char *arguments;
@@ -192,15 +197,14 @@ setup_unreadable (void *unused)
 #endif
                assert_fail ("mkdir()", anchors);
 
-       p = p11_path_build (anchors, "unreadable", NULL);
-       f = fopen (p, "w");
+       test.unreadable = p11_path_build (anchors, "unreadable", NULL);
+       f = fopen (test.unreadable, "w");
        fwrite ("foo", 3, 1, f);
        fclose (f);
-       chmod (p, 0);
-       free (p);
+       chmod (test.unreadable, 0);
 
-       pp = p11_path_build (anchors, "thawte", NULL);
-       ff = fopen (pp, "w");
+       p = p11_path_build (anchors, "thawte", NULL);
+       ff = fopen (p, "w");
        f = fopen (SRCDIR "/trust/fixtures/thawte.pem", "r");
        while (!feof (f)) {
                size_t size;
@@ -210,9 +214,9 @@ setup_unreadable (void *unused)
                                     SRCDIR "/trust/fixtures/thawte.pem");
                fwrite (buffer, 1, size, ff);
                if (ferror (ff))
-                       assert_fail ("write()", pp);
+                       assert_fail ("write()", p);
        }
-       free (pp);
+       free (p);
        fclose (ff);
        fclose (f);
        free (anchors);