lib/checkout: Fix regression in subpath for regular files
This is what caused the merge of https://github.com/projectatomic/rpm-ostree/pull/652 to blow up, since https://github.com/ostreedev/ostree/pull/848 landed right before we tried to merge it. When I was writing that PR I remember having an uncertain feeling since we were doing a `mkdirat` above, but at the time I thought we'd have test suite coverage...turns out we didn't. For backwards compatibility, we need to continue to do a `mkdirat` here of the parent. However...I can't think of a reason anyone would *want* that behavior. Hence, let's add a special trick - if the destination name is `.`, we skip `mkdirat()`. That way rpm-ostree for example can open a dfd for `/etc` and avoid the `mkdir`. Fold the subpath tests into `test-basic.sh` since it's not worth a separate file. Add a test case for checking out a file. Closes: #854 Approved by: jlebon
This commit is contained in:
1 parent
b83d509e78
commit
a195888b0f
4 files changed
+37
-41
No files matched your search
@@ -812,11 +812,31 @@ checkout_tree_at (OstreeRepo *self,
|
||||
|
||||
/* Special case handling for subpath of a non-directory */
|
||||
if (g_file_info_get_file_type (source_info) != G_FILE_TYPE_DIRECTORY)
|
||||
return checkout_one_file_at (self, options, &state,
|
||||
ostree_repo_file_get_checksum (source),
|
||||
destination_parent_fd,
|
||||
g_file_info_get_name (source_info),
|
||||
cancellable, error);
|
||||
{
|
||||
/* For backwards compat reasons, we do a mkdir() here. However, as a
|
||||
* special case to allow callers to directly check out files without an
|
||||
* intermediate root directory, we will skip mkdirat() if
|
||||
* `destination_name` == `.`, since obviously the current directory
|
||||
* exists.
|
||||
*/
|
||||
int destination_dfd = destination_parent_fd;
|
||||
glnx_fd_close int destination_dfd_owned = -1;
|
||||
if (strcmp (destination_name, ".") != 0)
|
||||
{
|
||||
if (mkdirat (destination_parent_fd, destination_name, 0700) < 0
|
||||
&& errno != EEXIST)
|
||||
return glnx_throw_errno_prefix (error, "mkdirat");
|
||||
if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE,
|
||||
&destination_dfd_owned, error))
|
||||
return FALSE;
|
||||
destination_dfd = destination_dfd_owned;
|
||||
}
|
||||
return checkout_one_file_at (self, options, &state,
|
||||
ostree_repo_file_get_checksum (source),
|
||||
destination_dfd,
|
||||
g_file_info_get_name (source_info),
|
||||
cancellable, error);
|
||||
}
|
||||
|
||||
/* Cache any directory metadata we read during this operation;
|
||||
* see commit b7afe91e21143d7abb0adde440683a52712aa246
|
||||
|
||||
Reference in new issue
Block a user