Cope with the non-atomic behaviour of rename on MS-Windows
authorJ. Ali Harlow <ali@juiblex.co.uk>
Mon, 12 Jan 2009 18:53:02 +0000 (18:53 +0000)
committerJ. Ali Harlow <ali@juiblex.co.uk>
Mon, 12 Jan 2009 18:53:02 +0000 (18:53 +0000)
and add some error checking to razor_set_commit.

librazor/root.c

index 32d01c8..13bfceb 100644 (file)
@@ -275,14 +275,22 @@ razor_root_update(struct razor_root *root, struct razor_set *next)
 RAZOR_EXPORT int
 razor_root_commit(struct razor_root *root)
 {
+       int retval;
        assert (root != NULL);
 
        /* Make it so. */
-       rename(root->new_path, root->path);
-       printf("renamed %s to %s\n", root->new_path, root->path);
-       razor_set_destroy(root->system);
        close(root->fd);
+#ifdef MSWIN_API
+       /* Rename is not atomic under MS-Windows */
+       remove(root->path);
+#endif
+       retval = rename(root->new_path, root->path);
+       if (retval)
+               perror(root->path);
+       else
+               printf("renamed %s to %s\n", root->new_path, root->path);
+       razor_set_destroy(root->system);
        free(root);
 
-       return 0;
+       return retval;
 }