checkout: Save errno when re-throwing
authorColin Walters <walters@verbum.org>
Thu, 26 Aug 2021 19:16:37 +0000 (15:16 -0400)
committerColin Walters <walters@verbum.org>
Thu, 26 Aug 2021 19:17:36 +0000 (15:17 -0400)
I was seeing an `EPERM`  here which was confusing.
It turned out the real error was `EEXIST`.

Since we're referring to the original error, but we do a
lot of computation in the middle, we need to save errno.

src/libostree/ostree-repo-checkout.c

index eaa33a286658cbedf9faea4efe6c3ac3b2c8b2f5..bdd93e7c08bbf4fb1468b8b946d5b2265743ca33 100644 (file)
@@ -481,6 +481,7 @@ checkout_file_hardlink (OstreeRepo                          *self,
     }
   else if (errno == EEXIST)
     {
+      int saved_errno = errno;
       /* When we get EEXIST, we need to handle the different overwrite modes. */
       switch (options->overwrite_mode)
         {
@@ -566,6 +567,7 @@ checkout_file_hardlink (OstreeRepo                          *self,
             else
               {
                 g_assert_cmpint (options->overwrite_mode, ==, OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL);
+                errno = saved_errno;
                 return glnx_throw_errno_prefix (error, "Hardlinking %s to %s", loose_path, destination_name);
               }
             break;