Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libarchive: Add support for translating paths during commit #1105

Closed
wants to merge 1 commit into from

Conversation

cgwalters
Copy link
Member

For rpm-ostree, I want to move RPM files in /boot to /usr/lib/ostree-boot.
This is currently impossible without forking the libarchive code. Supporting
this is pretty straightforward; we already had pathname translation in
the libarchive code, we just need to expose it as an option.

On the command line side, I chose to wrap this as a regexp. That should be good
enough for a lot of use cases; sophisticated users should as always be making
use of the API. Note that this required some new #ifdef LIBARCHIVE bits to use
the new API. Following previous patterns here, we use the new API only if a
relevant option is enabled, ensuring unit test coverage of both paths.

For the test cases, I ended up changing the accounting to avoid having to
multiply the test count.

* Since: 2017.11
*/
typedef char *(*OstreeRepoImportArchiveTranslatePathname) (OstreeRepo *repo,
GFileType file_type,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just pass the stat buffer directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that originally, but then we'd need to #include <sys/stat.h> in ostree.h. Which...is probably fine but takes us a bit farther down the unix-only path. OK, so libglnx already makes us linux-specific...yeah, I'll make that change back.

* will be freed via `g_free()`.
*
* This pathname translation will be performed *before* any processing from an
* active `OstreeRepoCommitModifier`. Will be invoked for all directory and file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document how this relates to use_ostree_convention here.

@@ -95,6 +97,7 @@ static GOptionEntry options[] = {
{ "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Do not import extended attributes", NULL },
{ "link-checkout-speedup", 0, 0, G_OPTION_ARG_NONE, &opt_link_checkout_speedup, "Optimize for commits of trees composed of hardlinks into the repository", NULL },
{ "tar-autocreate-parents", 0, 0, G_OPTION_ARG_NONE, &opt_tar_autocreate_parents, "When loading tar archives, automatically create parent directories as needed", NULL },
{ "tar-pathname-filter", 0, 0, G_OPTION_ARG_STRING, &opt_tar_pathname_filter, "When loading tar archives, use REGEX,REPLACEMENT against path names", "REGEX,REPLACEMENT" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it should be a G_OPTION_ARG_STRING_ARRAY instead, where the first filter that applies wins. Though since it's fully backwards compatible, we can do that later if we feel there's a use case for having CLI support for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed; let's consider this later, in the end I think we want to encourage use of the API.

{
g_assert_no_error (tmp_error);
g_assert_not_reached ();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the replacement didn't make any changes, we should return NULL, no? At least so we test the fallback behaviour.

if (ret)
return ret;
/* Fall through */
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say we add an else here. I.e. if translate_pathname is active, use_ostree_convention has no effect. Otherwise, it's odd thinking that there's a difference between returning NULL and returning the exact same string.

For rpm-ostree, I want to move RPM files in `/boot` to `/usr/lib/ostree-boot`.
This is currently impossible without forking the libarchive code.  Supporting
this is pretty straightforward; we already had pathname translation in
the libarchive code, we just need to expose it as an option.

On the command line side, I chose to wrap this as a regexp. That should be good
enough for a lot of use cases; sophisticated users should as always be making
use of the API. Note that this required some new `#ifdef LIBARCHIVE` bits to use
the new API. Following previous patterns here, we use the new API only if a
relevant option is enabled, ensuring unit test coverage of both paths.

For the test cases, I ended up changing the accounting to avoid having to
multiply the test count.
@cgwalters
Copy link
Member Author

Updated for comments ⬆️

@jlebon
Copy link
Member

jlebon commented Aug 30, 2017

@rh-atomic-bot r+ 49f55c7

@rh-atomic-bot
Copy link

⌛ Testing commit 49f55c7 with merge 138c4d7...

@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: jlebon
Pushing 138c4d7 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants