forked from Mirrors/flatpak-builder
git: When mirroring a new repo, use a temporary destination
This way, if anything fails during the initial pull we can remove it and not be confused by a partial repo on the next run. Closes: #98 Approved by: alexlarssontingping/wmclass
parent
9b4f14cd45
commit
63e0722cb0
|
@ -440,6 +440,8 @@ builder_git_mirror_repo (const char *repo_location,
|
|||
{
|
||||
g_autoptr(GFile) cache_mirror_dir = NULL;
|
||||
g_autoptr(GFile) mirror_dir = NULL;
|
||||
g_autoptr(GFile) real_mirror_dir = NULL;
|
||||
g_autoptr(FlatpakTempDir) tmp_mirror_dir = NULL;
|
||||
g_autofree char *current_commit = NULL;
|
||||
g_autoptr(GHashTable) refs = NULL;
|
||||
gboolean already_exists = FALSE;
|
||||
|
@ -466,6 +468,15 @@ builder_git_mirror_repo (const char *repo_location,
|
|||
|
||||
if (!g_file_query_exists (mirror_dir, NULL))
|
||||
{
|
||||
g_autofree char *tmpdir = g_strconcat (flatpak_file_get_path_cached (mirror_dir), "-XXXXXX", NULL);
|
||||
|
||||
if (g_mkdtemp_full (tmpdir, 0755) == NULL)
|
||||
return flatpak_fail (error, "Can't create temporary directory");
|
||||
|
||||
tmp_mirror_dir = g_file_new_for_path (tmpdir);
|
||||
real_mirror_dir = g_steal_pointer (&mirror_dir);
|
||||
mirror_dir = g_object_ref (tmp_mirror_dir);
|
||||
|
||||
if (!git (NULL, NULL, 0, error,
|
||||
"init", "--bare",
|
||||
(char *)flatpak_file_get_path_cached (mirror_dir), NULL))
|
||||
|
@ -605,6 +616,14 @@ builder_git_mirror_repo (const char *repo_location,
|
|||
}
|
||||
}
|
||||
|
||||
if (real_mirror_dir)
|
||||
{
|
||||
if (!flatpak_file_rename (mirror_dir, real_mirror_dir, NULL, error))
|
||||
return FALSE;
|
||||
g_clear_object (&mirror_dir);
|
||||
mirror_dir = g_steal_pointer (&real_mirror_dir);
|
||||
}
|
||||
|
||||
if (flags & FLATPAK_GIT_MIRROR_FLAGS_MIRROR_SUBMODULES)
|
||||
{
|
||||
current_commit = git_get_current_commit (mirror_dir, ref, FALSE, context, error);
|
||||
|
|
Loading…
Reference in New Issue