Commit Graph

3855 Commits

Author SHA1 Message Date
Colin Walters
0e0fe85922 bin/status: Inline metadata parsing for versions
Pull out the commit metadata explicitly; still just rendering the version, but
this is prep for rendering other metadata keys.

Closes: #1296
Approved by: jlebon
2017-10-23 14:19:41 +00:00
Colin Walters
32357cef4d bin/status: Port to new style
No functional changes; prep for more work.

Closes: #1296
Approved by: jlebon
2017-10-23 14:19:41 +00:00
Colin Walters
4cda9f14fb docs/related-projects: Add Google Usenix link
Closes: https://github.com/ostreedev/ostree/issues/1284

Closes: #1299
Approved by: cgwalters
2017-10-21 14:12:02 +00:00
Colin Walters
1222c2271b repo: Add wrapper function for setting devino cache on checkout opts
I was trying to use this with pygobject for an OCI+ostree project, and pygobject
rejected simply assigning to the field (understandably, since it can't bind the
lifetime together).

Add a wrapper function, which is still unsafe, but hides that unsafety
where most people shouldn't find it.  And if they do...well, sorry,
Rust wasn't invented when ostree was started.

Closes: #1295
Approved by: pwithnall
2017-10-20 18:20:19 +00:00
Colin Walters
b8251d26bd lib/checkout: For "process whiteouts" mode, replace directories too
I'm playing around with some ostree ⇔ OCI/Docker bits, and ran
into this while importing an OCI image that built from the Fedora
base image where `/home` is a regular directory, and I added a layer
that did the ostree bits of moving it to `/var` and leaving a symlink.

OCI/Docker supports this.  Now since "process whiteouts" is really the
"enable OCI/Docker" mode, let's only replace dirs if that's enabled.
This leaves the `UNION_FILES` targeted for its original use case
which is unioning components/packages.  (Although that use case itself
is now a bit superceded by `UNION_IDENTICAL`, but eh).

Closes: #1294
Approved by: jlebon
2017-10-20 13:20:27 +00:00
Ruixin Bao
9166605e5a ostree: provide command description in a better place
This is similar idea as
5c0bf88915,

The duplicated description is now removed, and the description
of the command is now displayed beneath the Usage.

For example:
ostree cat -h will output the following:

"Usage:
  ostree cat [OPTION?] COMMIT PATH...

Concatenate contents of files"

Closes: #1267
Approved by: cgwalters
2017-10-20 12:59:33 +00:00
Ruixin Bao
298c151fd8 ostree: move flags into command struct, pass down through builtins
This is a similar approach as
12c34bb249.

One thing to note is when we parse the admin related functions,
we still keep the old admin related flags, and added a new parameter
to represent the command struct.

This allows us to identify the caller of the function, making it
easier for us to possibly deduplicate the subcommand handling in
the future. A similar approach is done in rpm-ostree:
83aeb018c1

This also makes it easier for us to change the prototype of the function.
If we want to add something new in the future, we won't need to touch every prototype.

Closes: #1267
Approved by: cgwalters
2017-10-20 12:59:33 +00:00
Ruixin Bao
3c360a720f ostree: Describe subcommands in help output
Added a description argument to all type
of commands. Now when we include -h or --help
for commands that contain subcommands, the description
for those subcommands are shown.

The added subcommands help will be provided to the following commands:
- ostree -h
- ostree admin -h
- ostree admin instutil -h
- ostree remote -h
- ostree static-delta -h

Closes: #1267
Approved by: cgwalters
2017-10-20 12:59:32 +00:00
Philip Withnall
2531d8fe63 lib/repo-finder: Add OstreeRepoFinderOverride
This is another OstreeRepoFinder implementation; it returns results from
a given set of URIs. It’s designed to be used for implementing user
overrides to other repo-finders, or for implementing unit tests.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #1281
Approved by: mwleeds
2017-10-19 19:11:58 +00:00
Philip Withnall
a1f020ffa4 lib/repo-finder-avahi: Fix a leak in a GVariantIter loop
Use g_variant_iter_loop() rather than next(), since it automatically
handles freeing the child memory each iteration. Previously, we leaked
it for all but the last iteration.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #1293
Approved by: cgwalters
2017-10-19 13:16:59 +00:00
Colin Walters
e466e482b1 Disallow refs starting with a non-letter or digit
Change the regexp for validating refs to require at least one letter or digit
before allowing the other special chars in the set `[.-_]`. Names that start
with `.` are traditionally Unix hidden files; let's ignore them under the
assumption they're metadata for some other tool, and we don't want to
potentially conflict with the special `.` and `..` Unix directory entries.
Further, names starting with `-` are problematic for Unix cmdline option
processing; there's no good reason to support that. Finally, disallow `_` just
on general principle - it's simpler to say that ref identifiers must start with
a letter or digit.

We also ignore any existing files (that might be previously created refs) that
start with `.` in the `refs/` directory - there's a Red Hat tool for content
management that injects `.rsync` files, which is why this patch was first
written.

V1: Update to ban all refs starting with a non-letter/digit, and
    also add another call to `ostree_validate_rev` in the pull
    code.

Closes: https://github.com/ostreedev/ostree/issues/1285

Closes: #1286
Approved by: jlebon
2017-10-18 20:55:43 +00:00
Dan Nicholson
3f3d3d64ac build: Do *.am.inc substitutions from make correctly
The string needs to be escaped with a $ since we want to replace the
literal string $(path). Without this make will run the command with the
value of the variable, which won't match anything in the input Makefile
stub.

Closes: #1291
Approved by: smcv
2017-10-18 16:53:29 +00:00
Jonathan Lebon
18b85fa8bd lib/commit: fix checking flag with bitwise OR
Caught by Coverity.

Coverity CID: 1458339

Closes: #1290
Approved by: cgwalters
2017-10-18 14:27:20 +00:00
Colin Walters
a2f8315eae lib/commit: (refactor) Clean up delta bare write API
The way `_ostree_repo_open_content_bare()` did both looking for the object and
possibly creating a new fd was just weird and inconsistent with e.g. the pull
code where we always call `has_object()` first.

Just call `has_object()` in the delta paths that used this too, making the
implementation right now a thin wrapper around
`glnx_open_tmpfile_linkable_at()`, but this is prep for a later patch which does
more.

Closes: #1283
Approved by: jlebon
2017-10-18 14:07:55 +00:00
Colin Walters
40a0b9fb73 lib/repo: Update summary code to use newer hashing API
And drop the unnecessary wrapper.

Closes: #1287
Approved by: jlebon
2017-10-18 13:27:11 +00:00
Colin Walters
de5f781089 lib/pull: Update summary checksum code to use new checksum API
This is another case where making an input stream out of a memory buffer is a
bit silly; just hash the `GBytes` directly.

Closes: #1287
Approved by: jlebon
2017-10-18 13:27:11 +00:00
Marcus Folkesson
075e676eb6 docs: mention the $OSTREE_REPO environment variable
$OSTREE_REPO may be set to override the default location
of the repository.

Link: https://mail.gnome.org/archives/ostree-list/2017-October/msg00003.html

Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>

Closes: #1282
Approved by: cgwalters
2017-10-18 00:56:36 +00:00
Colin Walters
9955695da3 syntax-check: Add a rule to enforce glnx_autofd over glnx_fd_close
And fix the one final use.

Closes: #1280
Approved by: jlebon
2017-10-17 16:43:02 +00:00
Colin Walters
3577b4a6c6 lib/commit: Use direct fd xattr operations again on regular files
A side effect of commit 8fe4536257 is that
we started listing all xattrs even for files with device/inode matches;
further, we did that using the dfd/name which means we went through
the `/proc` path, which is slower and uglier.

Noticed this in strace while looking at adoption code.

Closes: #1280
Approved by: jlebon
2017-10-17 16:43:02 +00:00
Colin Walters
eeabd4baf7 lib/commit: Fix indentation in file commit code
No functional changes; the indentation was off here and it was
confusing me working on another patch.

Closes: #1280
Approved by: jlebon
2017-10-17 16:43:02 +00:00
Colin Walters
bc7ff2cd1d lib/commit: Avoid trying to delete . with _CONSUME flag
This helps port rpm-ostree.

Closes: #1278
Approved by: jlebon
2017-10-17 16:24:13 +00:00
Colin Walters
93457071cb lib/deltas: Use pread() instead of lseek()+read()
That's why the syscall was invented, so let's use it. Just noticed while reading
the code while working on another patch.

Closes: #1270
Approved by: jlebon
2017-10-17 15:20:08 +00:00
Colin Walters
bb05b187b6 lib/deltas: Use fastpath for regfile writes for bare-user-only
Noticed this omission while looking at the code while working on another patch.

Closes: #1270
Approved by: jlebon
2017-10-17 15:20:08 +00:00
Colin Walters
95afe2848d tests: Add test-pull-bareuseronly
I was going to fix a bug in the static deltas code and I noticed
we were missing `pull-test.sh` coverage for bareuseronly 🙈.

Obviously fixing this requires duplicating some of the bits we have in
`basic-test.sh`; need to hoist that into `libtest.sh`. For now though let's get
the coverage.

Closes: #1270
Approved by: jlebon
2017-10-17 15:20:08 +00:00
Colin Walters
464965e6b4 lib/sysroot: Fix error handling when mounting overlayfs fails
This isn't perfect, but at least we fix an error-overwrite error, and in
practice `ostree admin unlock` isn't wrapped by `rpm-ostree` yet, so spew to
stderr is OK.

Closes: https://github.com/ostreedev/ostree/issues/1273

Closes: #1279
Approved by: guyshapiro
2017-10-17 06:58:22 +00:00
Colin Walters
e744f2ad6f lib: Use a common helper function to compare checksums
So we get a consistent error message; came up in a PR review.

Closes: #1277
Approved by: jlebon
2017-10-17 05:06:07 +00:00
Colin Walters
16c31a9b58 lib/commit: Implement "adoption" with CONSUME flag
For checkouts that are on the same device, for regular files we can simply
"adopt" existing files. This is useful in the "build from subtrees" pattern that
happens with e.g. `rpm-ostree install` as well as flatpak and gnome-continuous.

New files are things like an updated `ldconfig` cache, etc. And particularly for
`rpm-ostree` we always regenerate the rpmdb, which for e.g. this workstation is
`61MB`.

We probably should have done this from the start, and instead had a `--copy`
flag to commit, but obviously we have to be backwards compatible.

There's more to do here - the biggest gap is probably for `bare-user` repos,
which are often used with things like `rpm-ostree compose tree` for host
systems. But we can do that later.

Closes: #1272
Approved by: jlebon
2017-10-16 18:22:09 +00:00
Colin Walters
729790bedc tests/basic: Add missing ${COMMIT_ARGS} for bare-user-only
I was working on "adopt" and hit corruption; turns out we were missing the
`--canonical-permissions` arg in this existing test.

(Need to abstract all of this more)

Closes: #1272
Approved by: jlebon
2017-10-16 18:22:09 +00:00
Dan Nicholson
9b3e01be30 build: Fix bsdiff Makefile circular dependency
The intended use was to have the .am.inc generated from the .am like the
libglnx one. Without this, make was detecting a circular dependency and
dropping the rule:

  make: Circular bsdiff/Makefile-bsdiff.am.inc <- bsdiff/Makefile-bsdiff.am.inc dependency dropped.

Closes: #1276
Approved by: jlebon
2017-10-16 16:40:11 +00:00
Colin Walters
1c108d1b68 lib/pull: Also do commit GPG verification before writing
I was working on a patch to do build on the work done to
import content objects async to do the same for metadata, but right
now we basically rely on writing them first to do the GPG verification
when scanning.

Things will be cleaner for that if we can pass the commit object directly into
`scan_commit_object()` and consistently use `gpg_verify_unwritten_commit()`.

We're careful here to continue to do it both ways (but at most one time), to
account for the case where a bad commit has been pulled and written - we need to
keep failing GPG verification there.

Closes: #1269
Approved by: jlebon
2017-10-16 15:32:39 +00:00
Colin Walters
22029d71c9 lib/pull: Drop duplicate/different error for GPG but no detached meta
Prep for a later patch to do GPG verification before writing commit objects;
`_ostree_repo_gpg_verify_with_metadata()` already handles this, and so dropping
this gives us consistent error messages.

Closes: #1269
Approved by: jlebon
2017-10-16 15:32:39 +00:00
Simon McVittie
e1357de275 Make sure *.am.inc are up to date before make dist
v2017.12 didn't include test-libglnx-shutil.c, but if you re-run
autogen.sh (as we do in Debian, to update the Autotools build system)
it will try to build it.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #1274
Approved by: cgwalters
2017-10-16 13:53:06 +00:00
Simon McVittie
a4723dafed Cope with xattr syscalls raising EOPNOTSUPP
ENOTSUP and EOPNOTSUPP are numerically equal on most Linux ports,
but inexplicably differ on PA-RISC (hppa) and possibly other
rare architectures.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #1275
Approved by: cgwalters
2017-10-16 13:08:06 +00:00
Jonathan Lebon
9503189362 lib/checkout: fallback to checksum for UNION_IDENTICAL
There's a subtle issue going on with the way we use `UNION_IDENTICAL`
now in rpm-ostree. Basically, the crux of the issue is that we checkout
the whole tree from the system repo, but then overlay packages by
checking out from the pkgcache repo. This is an easy way to break the
assumption that we will be merging hardlinks from the same repo.

This ends up causing issues like:
https://github.com/projectatomic/rpm-ostree/issues/1047

There, `vim-minimal` is already part of the host and has an object for
`/usr/share/man/man1/ex.1.gz`. `vim-common` has that same file, but
because it's unpacked in the pkgcache repo first, the hardlinks are not
the same.

There are a few ways we *could* work around this in rpm-ostree itself,
e.g. by re-establishing hardlinks when we do the content pull into the
system repo, but it still felt somewhat hacky. Let's just do this the
proper way and fall back to checksumming the target file if needed,
which is what librpm does as well in this case. Note that we only
checksum if they're not hard links, but they're the same size.

Closes: #1258
Approved by: cgwalters
2017-10-14 13:19:18 +00:00
Matthew Leeds
2a9c5efe1d lib/utils: Check for invalid UTF-8 in filenames
In case a filename contains invalid UTF-8 characters, libostree will
pass it to g_variant_builder_add() in create_tree_variant_from_hashes()
anyway, which leads to a critical warning from glib and an invalid
commit. This commit makes ostree print a useful error and exit instead.

Closes: #1271
Approved by: cgwalters
2017-10-14 00:47:40 +00:00
Colin Walters
a1986b1a80 lib/deltas: Check cancellable during processing
Let's react to `Ctrl-C` faster here. Noticed while I was doing an update on my
desktop and playing with cancellation.

Closes: #1266
Approved by: jlebon
2017-10-12 15:04:02 +00:00
Jonathan Lebon
077d2718ad lib/core: add ostree_checksum_file_at API
This is like `ostree_checksum_file` but fd-relative. This will be used
by https://github.com/ostreedev/ostree/pull/1258.

AFAICT, we actually didn't have any tests that check the `checksum` CLI.
Add a basic one here to test the old code as well as the new code.

Closes: #1263
Approved by: cgwalters
2017-10-12 12:53:01 +00:00
Jonathan Lebon
60b5925c54 ostree/checksum: port to new decl style
No functional changes, prep for patch. (Well, I did add a new `success`
member in the async struct so that we return `FALSE` if we failed).

Closes: #1263
Approved by: cgwalters
2017-10-12 12:53:01 +00:00
Jonathan Lebon
057482761b tests: drop unused variable
Closes: #1263
Approved by: cgwalters
2017-10-12 12:53:01 +00:00
Colin Walters
8f6ec62bfb lib/deploy: Use _exit() for FIFREEZE watchdog
This works around an (IMO) SpiderMonkey bug - it tries to
clean up in a shared library destructor, but doesn't install a
`pthread_atfork()` handler to unset its state.

Closes: https://github.com/ostreedev/ostree/issues/1262

Closes: #1264
Approved by: dbnicholson
2017-10-11 21:24:39 +00:00
Colin Walters
1825f03fe7 tree-wide: Update to new libglnx fd APIs
This ends up a lot better IMO.  This commit is *mostly* just
`s/glnx_close_fd/glnx_autofd`, but there's also a number of hunks like:

```
-  if (self->sysroot_fd != -1)
-    {
-      (void) close (self->sysroot_fd);
-      self->sysroot_fd = -1;
-    }
+  glnx_close_fd (&self->sysroot_fd);
```

Update submodule: libglnx

Closes: #1259
Approved by: jlebon
2017-10-11 19:26:10 +00:00
Colin Walters
3e3d28632d lib/commit: Make -path commit helper API private
It's no longer called directly by the pull code, so make it static.

The goal here is to have the pull and local-fs commit paths use higher level
more efficient APIs, and eventually make those APIs public.

Closes: #1257
Approved by: jlebon
2017-10-11 19:04:46 +00:00
Colin Walters
bb51a43d81 lib/core: Use GBytes for file headers
This simplifies a lot of code; the header function was structured
to write to an input stream, but many callers only wanted the checksum,
so it's simpler (and error-free) to simply allocate a whole buffer
and checksum that.

For the callers that want to write it, it's also still simpler to allocate the
buffer and write the whole thing rather than having this function do the
writing.

A lot of the complexity here again is a legacy of the packfile code, which is
dead.

This is prep for faster regfile commits where we can avoid `G{In,Out}putStream`.

Closes: #1257
Approved by: jlebon
2017-10-11 19:04:46 +00:00
Colin Walters
d10593e65d lib/core: Port a few functions to decl-after-stmt
No functional changes, just prep for more work.

Closes: #1257
Approved by: jlebon
2017-10-11 19:04:46 +00:00
Colin Walters
cd8fc8e37a lib/core: (refactor) Drop wrapper and unneeded args for variant writing
Nothing was using the `bytes_written` data (we always discard partially written
tmpfiles), so simplify everything by dropping it. Further, we always passed an
offset of `0`, so drop that argument too. (I believe that this was previously
used by the "pack files" code that we deleted long ago)

Second, we had an unnecessary internal wrapper for this function; drop that too.

Closes: #1257
Approved by: jlebon
2017-10-11 19:04:46 +00:00
Jonathan Lebon
22869e0b72 ci: compile f26/c7-primary with libcurl/openssl
This is how ostree is shipped in those distros. We already have
alternative testsuites for testing other HTTP & crypto backends.

Closes: #1261
Approved by: cgwalters
2017-10-11 16:05:52 +00:00
Jonathan Lebon
3604b8152a libotutil/checksum-utils: fix openssl compilation
Closes: #1261
Approved by: cgwalters
2017-10-11 16:05:52 +00:00
Dan Nicholson
a5b7660c94 lib/deploy: Ignore FIFREEZE/FITHAW errors when already in state
If the filesystem is already frozen, FIFREEZE returns EBUSY, and if the
filesystem is already thawed, FITHAW returns EINVAL. It's very unlikely
these issues would arise on a real ostree system since the sysroot would
be locked during the freeze/thaw cycle.

However, when multiple fake sysroots are used during the test suite (run
as root), the tests could race to run the freeze/thaw cycle without
locking. Furthermore, there's no reason why an independent process might
be trying to freeze the filesystem while ostree was deploying. Ignore
but warn for these errors since there's not much ostree can do about it,
anyways.

Closes: #1260
Approved by: cgwalters
2017-10-11 15:40:20 +00:00
Colin Walters
1c9975cbd1 lib: Add a lighter weight internal checksum wrapper
The faster (OpenSSL/GnuTLS) code lived in a `GInputStream` wrapper, and that
adds a lot of weight (GObject + vtable calls). Move it into a simple
autoptr-struct wrapper, and use it in the metadata path, so we're
now using the faster checksums there too.

This also drops a malloc there as the new API does hexdigest in place to a
buffer.

Prep for more work in the commit path to avoid `GInputStream` for local file
commits, and ["adopting" files](https://github.com/ostreedev/ostree/pull/1255).

Closes: #1256
Approved by: jlebon
2017-10-10 21:25:40 +00:00
Colin Walters
bba7eb8069 commit: Add _CONSUME modifier flag
For many cases of commit, we can actually optimize things by simply "adopting"
the object rather than writing a new copy. For example, in rpm-ostree package
layering.

We can only make that optimization though if we take ownership of the file. This
commit hence adds an API where a caller tells us to do so. For now, that just
means we `unlink()` the files/dirs as we go, but we can now later add the
"adopt" optimization.

Closes: #1255
Approved by: jlebon
2017-10-10 13:02:08 +00:00