diff options
author | Alexander Larsson <alexl@redhat.com> | 2016-04-07 17:03:08 +0200 |
---|---|---|
committer | Colin Walters (automation) <walters+githubbot@verbum.org> | 2016-04-07 15:15:39 +0000 |
commit | 91734a8a18e714d68529ea0fecbc526dafe9977e (patch) | |
tree | 008299a0fe13f2c3300dbc1beeed8e544bfdd9e7 | |
parent | 984bf91826187140682947fb8e0a2cc0a8a3f355 (diff) | |
download | ostree-91734a8a18e714d68529ea0fecbc526dafe9977e.tar.gz |
Support pathnames for --subpath=...
This allows you to pull a single file, rather than just a directory.
Closes: #244
Approved by: cgwalters
-rw-r--r-- | src/libostree/ostree-repo-pull.c | 15 | ||||
-rwxr-xr-x | tests/test-pull-subpath.sh | 4 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 4d8b6138..a6272b17 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -448,12 +448,7 @@ scan_dirtree_object (OtPullData *pull_data, files_variant = g_variant_get_child_value (tree, 0); dirs_variant = g_variant_get_child_value (tree, 1); - /* Skip files if we're traversing a request only directory */ - if (pull_data->dir) - n = 0; - else - n = g_variant_n_children (files_variant); - + n = g_variant_n_children (files_variant); for (i = 0; i < n; i++) { const char *filename; @@ -466,6 +461,14 @@ scan_dirtree_object (OtPullData *pull_data, if (!ot_util_filename_validate (filename, error)) goto out; + /* Skip files if we're traversing a request only directory, unless it exactly + * matches the path */ + if (pull_data->dir && + /* Should always an initial slash, we assert it in scan_dirtree_object */ + pull_data->dir[0] == '/' && + strcmp (pull_data->dir+1, filename) != 0) + continue; + file_checksum = ostree_checksum_from_bytes_v (csum); if (!ostree_repo_has_object (pull_data->repo, OSTREE_OBJECT_TYPE_FILE, file_checksum, diff --git a/tests/test-pull-subpath.sh b/tests/test-pull-subpath.sh index 8d20341e..b0bf4839 100755 --- a/tests/test-pull-subpath.sh +++ b/tests/test-pull-subpath.sh @@ -44,6 +44,10 @@ assert_file_has_content err.txt "Couldn't find file object" rev=$(${CMD_PREFIX} ostree --repo=repo rev-parse origin:main) assert_has_file repo/state/${rev}.commitpartial +# Test pulling a file, not a dir +${CMD_PREFIX} ostree --repo=repo pull --subpath=/firstfile origin main +${CMD_PREFIX} ostree --repo=repo ls origin:main /firstfile + ${CMD_PREFIX} ostree --repo=repo pull origin main assert_not_has_file repo/state/${rev}.commitpartial ${CMD_PREFIX} ostree --repo=repo fsck |