lib/repo: Don't delete new tmpdir if it can't be locked
authorDan Nicholson <nicholson@endlessm.com>
Fri, 17 Nov 2017 17:06:32 +0000 (17:06 +0000)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 17 Nov 2017 18:25:22 +0000 (18:25 +0000)
If a newly allocated tmpdir can't be locked, set initialized to FALSE so
that glnx_tmpdir_cleanup doesn't delete it when new_tmpdir goes out of
scope.

Closes: #1346
Approved by: cgwalters

src/libostree/ostree-repo.c

index 768c9ce71bf73cdd15d7618e9e0026ec8490d00c..6e3421256145ab6ed7a6d4499860e65878833864 100644 (file)
@@ -5004,7 +5004,16 @@ _ostree_repo_allocate_tmpdir (int tmpdir_dfd,
                                          error))
         return FALSE;
       if (!did_lock)
-        continue;
+        {
+          /* We raced and someone else already locked the newly created
+           * directory. Free the resources here and then mark it as
+           * uninitialized so glnx_tmpdir_cleanup doesn't delete the directory
+           * when new_tmpdir goes out of scope.
+           */
+          glnx_tmpdir_unset (&new_tmpdir);
+          new_tmpdir.initialized = FALSE;
+          continue;
+        }
 
       g_debug ("Using new tmpdir %s", new_tmpdir.path);
       ret_tmpdir = new_tmpdir; /* Transfer ownership */