lib/repo: Support hardlink conversions from bare-user to bu-only
Thinking about the problem of flatpak converting from `bare-user` to `bare-user-only` "in place" by creating a new repo and doing a `pull-local`, I realized that we can optimize this process by doing hardlinks for both metadata and regular files. The repo formats are *almost* compatible, the exception being symlinks. An earlier patch caused us to do hardlinks for metadata, this patch takes things to the next step and special cases this specific conversion. In this case we need to parse the source object to determine whether or not it's a symlink. Closes: #922 Approved by: alexlarsson
This commit is contained in:
1 parent
b614c65eab
commit
74e3581ed6
3 files changed
+89
-8
No files matched your search
@@ -3073,6 +3073,20 @@ copy_detached_metadata (OstreeRepo *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Special case between bare-user and bare-user-only,
|
||||
* mostly for https://github.com/flatpak/flatpak/issues/845
|
||||
* see below for any more comments.
|
||||
*/
|
||||
static gboolean
|
||||
import_is_bareuser_only_conversion (OstreeRepo *src_repo,
|
||||
OstreeRepo *dest_repo,
|
||||
OstreeObjectType objtype)
|
||||
{
|
||||
return src_repo->mode == OSTREE_REPO_MODE_BARE_USER
|
||||
&& dest_repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY
|
||||
&& objtype == OSTREE_OBJECT_TYPE_FILE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
import_one_object_link (OstreeRepo *self,
|
||||
OstreeRepo *source,
|
||||
@@ -3085,6 +3099,33 @@ import_one_object_link (OstreeRepo *self,
|
||||
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
|
||||
_ostree_loose_path (loose_path_buf, checksum, objtype, self->mode);
|
||||
|
||||
/* Hardlinking between bare-user → bare-user-only is only possible for regular
|
||||
* files, *not* symlinks, which in bare-user are stored as regular files. At
|
||||
* this point we need to parse the file to see the difference.
|
||||
*/
|
||||
if (import_is_bareuser_only_conversion (source, self, objtype))
|
||||
{
|
||||
g_autoptr(GFileInfo) finfo = NULL;
|
||||
|
||||
if (!ostree_repo_load_file (source, checksum, NULL, &finfo, NULL,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
switch (g_file_info_get_file_type (finfo))
|
||||
{
|
||||
case G_FILE_TYPE_REGULAR:
|
||||
/* This is OK, we'll drop through and try a hardlink */
|
||||
break;
|
||||
case G_FILE_TYPE_SYMBOLIC_LINK:
|
||||
/* NOTE early return */
|
||||
*out_was_supported = FALSE;
|
||||
return TRUE;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_ostree_repo_ensure_loose_objdir_at (self->objects_dir_fd, loose_path_buf, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
@@ -3157,6 +3198,11 @@ import_via_hardlink_is_possible (OstreeRepo *src_repo,
|
||||
/* Metadata is identical between all modes */
|
||||
if (OSTREE_OBJECT_TYPE_IS_META (objtype))
|
||||
return TRUE;
|
||||
/* And now a special case between bare-user and bare-user-only,
|
||||
* mostly for https://github.com/flatpak/flatpak/issues/845
|
||||
*/
|
||||
if (import_is_bareuser_only_conversion (src_repo, dest_repo, objtype))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user