ostree.git
8 years agolib: Add a helper to convert struct stat → GFileInfo
Colin Walters [Wed, 28 Jun 2017 20:09:37 +0000 (16:09 -0400)]
lib: Add a helper to convert struct stat → GFileInfo

It's more natural for a few calling places. Prep for patches to go the other
way, which in turn are prep for adding a commit filter v2 that takes `struct
stat`.

`ot_gfile_type_for_mode()` was only used in this function, so inline it here.

Closes: #974
Approved by: jlebon

8 years agocmdline/pull: Print final status even if noninteractive
Colin Walters [Thu, 29 Jun 2017 14:23:32 +0000 (10:23 -0400)]
cmdline/pull: Print final status even if noninteractive

Previously, `ostree pull` was silent if not on a tty.  I don't
see a reason not to print the final status line at least.  This
is prep for more work in the test suite, so I can write assertions
on the output.

But it should also be nicer for people who e.g. do an `ostree pull` in a Jenkins
job or whatever.

Closes: #981
Approved by: jlebon

8 years agotree-wide: Replace various uses of `archive-z2` → `archive`
Colin Walters [Thu, 29 Jun 2017 02:52:40 +0000 (22:52 -0400)]
tree-wide: Replace various uses of `archive-z2` → `archive`

The `-z2` is annoying now since it's really a legacy; we've long
since supported typing `archive`.  Convert the docs fully and
explain that.

Also do some (but not all) of the tests just to encourage newer tests to use
`archive` too.

Closes: #980
Approved by: jlebon

8 years agolib/pull: Don't fetch detached metadata twice for local pulls
Colin Walters [Thu, 29 Jun 2017 02:23:17 +0000 (22:23 -0400)]
lib/pull: Don't fetch detached metadata twice for local pulls

Obviously very minor, but I noticed this while working on `pull --reference`. If
we have a local repo, we'll have already done a hardlink and copied the detached
metadata too, so there's no reason to request it again via the fetcher path.

Closes: #978
Approved by: jlebon

8 years agotests: Fix assert_files_hardlinked
Colin Walters [Thu, 29 Jun 2017 01:39:16 +0000 (21:39 -0400)]
tests: Fix assert_files_hardlinked

It was always succeeding because we were trying to stat the inode number, and
failing, and thus getting the empty string for both, which compared as true.

Regression from:
<https://github.com/ostreedev/ostree/commit/74e3581e>

Noticed this while working on
<https://github.com/ostreedev/ostree/pull/974>
and looking at the test results.

Closes: #976
Approved by: jlebon

8 years agolib/pull: Some small style porting
Colin Walters [Thu, 29 Jun 2017 02:28:29 +0000 (22:28 -0400)]
lib/pull: Some small style porting

I'd mostly been avoiding this file since there's always patches outstanding, but
these few functions shouldn't conflict much.

Closes: #979
Approved by: jlebon

8 years agolib/repo: Port bareuser-conversion stat to bare load
Colin Walters [Thu, 29 Jun 2017 01:50:10 +0000 (21:50 -0400)]
lib/repo: Port bareuser-conversion stat to bare load

I noticed this is a simple call that's useful to port to the new internal-only
non-allocating API.

Closes: #977
Approved by: jlebon

8 years agolib/deltas: More porting to new code style
Colin Walters [Wed, 28 Jun 2017 17:55:19 +0000 (13:55 -0400)]
lib/deltas: More porting to new code style

Just noticed some of this while working on the previous tmpfile bits.

Closes: #973
Approved by: jlebon

8 years agolib/commit: Refactor non-failable size indexing function
Colin Walters [Wed, 28 Jun 2017 17:54:00 +0000 (13:54 -0400)]
lib/commit: Refactor non-failable size indexing function

It can't throw, so remove the `GError` machinery.

Closes: #973
Approved by: jlebon

8 years agolibutil: Add a helper for O_TMPFILE + mmap()
Colin Walters [Wed, 28 Jun 2017 17:41:52 +0000 (13:41 -0400)]
libutil: Add a helper for O_TMPFILE + mmap()

I added `glnx_open_anonymous_tmpfile()`, but then later noticed
that the usage of this was really to be combined with `mmap()`,
and we had two versions of that in the delta code.  Add a helper.

(Bigger picture...how is this different from glibc's "mmap() of /dev/zero"
 approach for large chunks? One advantage is the storage can be "swapped" to
 `/var/tmp`, but still deleted automatically, rather than requiring swap space)

Closes: #973
Approved by: jlebon

8 years agoci: unconditionally turn on -Werror
Jonathan Lebon [Wed, 28 Jun 2017 15:59:36 +0000 (08:59 -0700)]
ci: unconditionally turn on -Werror

Closes: #971
Approved by: cgwalters

8 years agocodebase: start using GLNX_HASH_TABLE_FOREACH macros
Jonathan Lebon [Wed, 28 Jun 2017 15:06:50 +0000 (08:06 -0700)]
codebase: start using GLNX_HASH_TABLE_FOREACH macros

Use the new macros introduced recently in libglnx to make iterating over
hash tables cleaner. This is just a start, it does not migrate the whole
tree.

Update submodule: libglnx

Closes: #971
Approved by: cgwalters

8 years agotree-wide: Misc porting to newer libglnx APIs
Colin Walters [Wed, 28 Jun 2017 01:26:17 +0000 (21:26 -0400)]
tree-wide: Misc porting to newer libglnx APIs

 - Use the new tmpfile bits
 - `glnx_try_fallocate`
 - `glnx_renameat()`

Depends: https://github.com/GNOME/libglnx/pull/57

Update submodule: libglnx

Closes: #970
Approved by: jlebon

8 years agoPort to GLnxTmpfile
Colin Walters [Sat, 24 Jun 2017 14:06:53 +0000 (14:06 +0000)]
Port to GLnxTmpfile

There's lots of mechanically replacing `OtTmpFile` with `GLnxTmpfile`;
the biggest changes are in the commit path.  Symlink commits are now
very clearly separated from regular files.  Symlinks are `OtCleanupUnlinkat`,
and regular files are `GLnxTmpfile`.

The commit codepath separates those as `_ostree_repo_commit_path_final()` and
`_ostree_repo_commit_tmpf_final()`. A nice aspect of all of this is that they
both *consume* the temporary on success. This avoids an extra spurious
`unlink()` call.

One of the biggest bits of code motion is in `commit_loose_regfile_object()`,
which no longer needs to care about symlinks. For the most parth though it's
just removing conditionals.

Update submodule: libglnx

Closes: #958
Approved by: jlebon

8 years agotest-switchroot.sh: skip if no busybox
Jonathan Lebon [Tue, 27 Jun 2017 21:25:56 +0000 (14:25 -0700)]
test-switchroot.sh: skip if no busybox

Closes: #968
Approved by: cgwalters

8 years agopapr: build and test on c7
Jonathan Lebon [Tue, 27 Jun 2017 20:39:27 +0000 (13:39 -0700)]
papr: build and test on c7

Start testing on CentOS 7 as well to cover kernel differences (e.g.
O_TMPFILE support).

Closes: #968
Approved by: cgwalters

8 years agoci: Actually run installed tests again
Colin Walters [Tue, 27 Jun 2017 21:07:11 +0000 (17:07 -0400)]
ci: Actually run installed tests again

We did it *again* 😭

Closes: #969
Approved by: jlebon

8 years agolib/pull: Use ostree_repo_verify_summary() to verify summary on pull
Philip Withnall [Fri, 23 Jun 2017 15:10:03 +0000 (16:10 +0100)]
lib/pull: Use ostree_repo_verify_summary() to verify summary on pull

Rather than duplicating the code. This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #961
Approved by: cgwalters

8 years agolib/pull: Check whether summary is in normal form when loading it
Philip Withnall [Mon, 19 Jun 2017 14:58:08 +0000 (15:58 +0100)]
lib/pull: Check whether summary is in normal form when loading it

Check that it’s in normal form and has the correct type when loading it,
since it could come from an untrusted source.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #961
Approved by: cgwalters

8 years agolib/pull: Don’t cache summary file until its signature is verified
Philip Withnall [Mon, 19 Jun 2017 14:26:50 +0000 (15:26 +0100)]
lib/pull: Don’t cache summary file until its signature is verified

This makes no difference to the validity of the code, since any summary
file loaded from the cache will be verified before being read anyway;
but it will make some upcoming changes a little simpler.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #961
Approved by: cgwalters

8 years agoostree/summary: Add support for adding additional metadata
Philip Withnall [Thu, 22 Jun 2017 14:16:53 +0000 (15:16 +0100)]
ostree/summary: Add support for adding additional metadata

When updating a summary file, parse additional arguments to the `ostree
summary` command as additional metadata to be put into the summary.

Add some tests for this.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #961
Approved by: cgwalters

8 years agotests: Fix incorrect `summary --update` usage in test-local-pull.sh
Philip Withnall [Fri, 23 Jun 2017 20:44:29 +0000 (21:44 +0100)]
tests: Fix incorrect `summary --update` usage in test-local-pull.sh

Previously the spurious ‘update’ atom was ignored; now that `ostree
summary --update` accepts extra arguments as additional metadata, it’s
causing an error. Drop it.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #961
Approved by: cgwalters

8 years agolib/repo: Fix a typo in a documentation comment
Philip Withnall [Mon, 19 Jun 2017 22:29:55 +0000 (23:29 +0100)]
lib/repo: Fix a typo in a documentation comment

Looks like a copy-paste error.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #961
Approved by: cgwalters

8 years agopull: Check free space when pulling deltas
Colin Walters [Mon, 26 Jun 2017 19:10:57 +0000 (15:10 -0400)]
pull: Check free space when pulling deltas

Computing download/storage size for `archive` pulls is hard; there's
`OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES` which was from a
pre-static-deltas effort by Endless, but we aren't currently making use of this
much.

Static deltas were designed to solve this problem; we have the total
uncompressed size. Let's check free space before doing a delta pull.

Related: https://github.com/ostreedev/ostree/issues/962

Closes: #963
Approved by: jlebon

8 years agobuild: Don't scan ostree-remote.h for introspection if !experimental-api
Colin Walters [Tue, 27 Jun 2017 16:57:47 +0000 (12:57 -0400)]
build: Don't scan ostree-remote.h for introspection if !experimental-api

It's a bit unfortunate that the scanner doesn't error on this, but
anyways

Closes: https://github.com/ostreedev/ostree/issues/966
Closes: #967
Approved by: jlebon

8 years agolib/deltas: Some style porting
Colin Walters [Mon, 26 Jun 2017 22:07:44 +0000 (18:07 -0400)]
lib/deltas: Some style porting

Just a few functions to keep up momentum.

Closes: #964
Approved by: jlebon

8 years agoci: Make introspection warnings fatal
Colin Walters [Mon, 26 Jun 2017 22:12:33 +0000 (18:12 -0400)]
ci: Make introspection warnings fatal

Closes: #965
Approved by: pwithnall

8 years agolib/ref: Suppress more collection ref methods from introspection
Colin Walters [Mon, 26 Jun 2017 22:11:40 +0000 (18:11 -0400)]
lib/ref: Suppress more collection ref methods from introspection

This squashes some warnings.

Closes: #965
Approved by: pwithnall

8 years agolib/commit: Fix fallocate size for bare-user symlinks
Colin Walters [Mon, 26 Jun 2017 16:30:21 +0000 (12:30 -0400)]
lib/commit: Fix fallocate size for bare-user symlinks

We need to account for the trailing NUL.

Closes: #957
Approved by: jlebon

8 years agolib: Use OtTmpFile for static delta processing
Colin Walters [Sat, 24 Jun 2017 14:28:09 +0000 (10:28 -0400)]
lib: Use OtTmpFile for static delta processing

The `OstreeRepoContentBareCommit` struct was basically an `OtTmpFile`, so let's
make it one. I moved the "convert to `GOutputStream`" logic into the callers,
since that bit can't fail; it makes the implementation much simpler since we can
just return the result of `ot_open_tmpfile_linkable_at()`.

Prep for `GLnxTmpfile` porting.

Closes: #957
Approved by: jlebon

8 years agolib: Hoist unlinkat() cleanup API to fsutil, use in pull
Colin Walters [Sat, 24 Jun 2017 13:30:02 +0000 (09:30 -0400)]
lib: Hoist unlinkat() cleanup API to fsutil, use in pull

The pull code also could make use of this in both the metadata and content
paths. I changed it to own the tempfile malloc (just like `GLnxTmpFile`), since
there's no reason to have different lifetimes for the filename and the file, and
that way we only have one variable rather than two.

The content path turns out to be a special case though, where
at least for mirroring archives, we directly pass the file *path*
down into `_ostree_repo_commit_loose_final()`.

This is prep for `GLnxTmpFile` porting.

Closes: #957
Approved by: jlebon

8 years agolib/commit: Clean up commit file type handling variables
Colin Walters [Fri, 23 Jun 2017 21:13:15 +0000 (17:13 -0400)]
lib/commit: Clean up commit file type handling variables

The variables here were duplicative; we don't need two booleans to distinguish
between symlinks and regular files. What we do need to handle is the "physical"
state versus the "object" state. Symlinks objects are stored as regular files in
`bare-user` and `archive`.

Prep for more cleanup.

Closes: #957
Approved by: jlebon

8 years agolib/refs: Add runtime error checking for collection ID validity
Philip Withnall [Fri, 23 Jun 2017 14:55:19 +0000 (15:55 +0100)]
lib/refs: Add runtime error checking for collection ID validity

Instead of treating it as a programming error — given that it’s user
input, that’s not really appropriate. This modifies write_ref() and
list_collection_refs() to implement validation.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agotests: Add integration tests for collections
Philip Withnall [Tue, 13 Jun 2017 17:55:53 +0000 (18:55 +0100)]
tests: Add integration tests for collections

Test various pieces of core and command line utility functionality
relating to the newly-introduced concept of collections. Mostly focussed
around the find-remotes utility, and around handling of collection–refs.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agoostree/builtins: Add support for collection–refs to a few utilities
Philip Withnall [Fri, 9 Jun 2017 17:45:39 +0000 (18:45 +0100)]
ostree/builtins: Add support for collection–refs to a few utilities

These utilities were not needed for the initial port to support
OstreeCollectionRef, so have been delayed a bit and, in some cases, left
as FIXME comments for follow up later.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agoostree/dump: Include collection IDs and mirrored refs in summary dumps
Philip Withnall [Wed, 7 Jun 2017 13:53:58 +0000 (14:53 +0100)]
ostree/dump: Include collection IDs and mirrored refs in summary dumps

If a repository’s summary file includes a collection ID, output that. If
it includes refs from other collections (in the ‘collection map’), output
those and include the same metadata detail as for refs in the summary
file’s main refs map.

If collection IDs are specified in the summary file, this changes the
output format from `ostree summary -v` to use (collection ID, ref name)
tuples.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agorefs: Add a --collections argument to the built-in refs command
Philip Withnall [Wed, 7 Jun 2017 13:51:58 +0000 (14:51 +0100)]
refs: Add a --collections argument to the built-in refs command

Rather than change the output format used by the existing refs command
to output collection IDs in addition to ref names, this functionality has
been hidden behind an --collections argument. If it’s not specified `ostree
refs` will output the same content as before for a given repository. If
it is specified, the collection ID for each ref will be included in the
output as (collection ID, ref name).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agoremote-add: Add a --collection-id argument to the built-in add command
Philip Withnall [Wed, 7 Jun 2017 13:50:51 +0000 (14:50 +0100)]
remote-add: Add a --collection-id argument to the built-in add command

This allows newly configured remotes to have their collection ID specified,
so that refs from them can be downloaded from peers as well as the
upstream collection, using the remote’s configuration.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agoinit: Add a --collection-id argument to the built-in init command
Philip Withnall [Wed, 7 Jun 2017 13:48:35 +0000 (14:48 +0100)]
init: Add a --collection-id argument to the built-in init command

This allows new repositories to be configured with a collection ID which
can be used to uniquely identify refs which originated from this
repository.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agofind-remotes: Add pull support to the find-remotes built-in command
Philip Withnall [Thu, 4 May 2017 09:47:23 +0000 (10:47 +0100)]
find-remotes: Add pull support to the find-remotes built-in command

This will pull the remotes after finding them. This potentially needs to
go in its own pull-from-remotes built-in command, but it will be fine
here for now.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agofind-remotes: Add a find-remotes built-in command
Philip Withnall [Tue, 25 Apr 2017 18:10:04 +0000 (19:10 +0100)]
find-remotes: Add a find-remotes built-in command

This is a wrapper around the new ostree_repo_find_remotes() method; it
tries to find available remotes which can serve updates for the
user-provided refs.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/repo-finder: Add Avahi based OstreeRepoFinder implementation
Philip Withnall [Tue, 18 Apr 2017 23:13:28 +0000 (00:13 +0100)]
lib/repo-finder: Add Avahi based OstreeRepoFinder implementation

This is a more complex implementation of OstreeRepoFinder which resolves
ref names to remote URIs by looking for refs advertised by peers on the
local network using DNS-SD records and mDNS (Avahi). The idea is to
allow OS and app updates to be propagated over local networks, without
the internet.

It requires an OSTree server and code to generate the DNS-SD adverts in
order to be fully functional — support for this will be added
separately.

Unit tests are included.

Includes fixes by Krzesimir Nowak <krzesimir@kinvolk.io>.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/bloom: Add an internal bloom filter implementation
Philip Withnall [Tue, 18 Apr 2017 23:11:28 +0000 (00:11 +0100)]
lib/bloom: Add an internal bloom filter implementation

This will be used in an upcoming commit. It adds a basic bloom filter
implementation, using the SipHash family of hash functions.

The implementation (including its parameter choices and hash functions)
will become a protocol detail in future, so must not be changed so that
its output is bitwise incompatible between OSTree versions.

Unit tests are included.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/repo-finder: Add mount based OstreeRepoFinder implementation
Philip Withnall [Tue, 18 Apr 2017 23:07:51 +0000 (00:07 +0100)]
lib/repo-finder: Add mount based OstreeRepoFinder implementation

This is a basic implementation of OstreeRepoFinder which resolves ref
names to remote URIs by looking for them on any currently mounted
removable storage volumes. The idea is to support OS and app updates via
USB stick.

Unit tests are included.

This bumps libostree’s maximum GLib dependency from 2.44 to 2.50 for
g_drive_is_removable(). If GLib 2.50 is not available, the call which
needs it will be omitted and the OstreeRepoFinderMount implementation
will scan all volumes (not just removable ones); this is a performance
hit, but not a functionality hit.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/repo-finder: Add config-file based OstreeRepoFinder implementation
Philip Withnall [Tue, 18 Apr 2017 23:05:06 +0000 (00:05 +0100)]
lib/repo-finder: Add config-file based OstreeRepoFinder implementation

This is a basic implementation of OstreeRepoFinder which resolves ref
names to remote URIs by looking their collection IDs up in the local
configuration of remotes who have their collection-id key set.

Unit tests are included.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/repo-finder: Add basic support for finding remote URIs by ref name
Philip Withnall [Tue, 18 Apr 2017 22:59:33 +0000 (23:59 +0100)]
lib/repo-finder: Add basic support for finding remote URIs by ref name

Add an initial OstreeRepoFinder interface (but no implementations),
which will find remote URIs by ref names and collection IDs, the
combination of which is globally unique.

The new API is used in a new ostree_repo_find_updates() function, which
resolves a list of ref names to update into a set of remote URIs to pull
them from, which can be treated as mirrors. It is an attempt to
generalise resolution of the URIs to pull from, and to generalise
determination of the order and parallelisation which they should be
downloaded from in.

Includes fixes by Krzesimir Nowak <krzesimir@kinvolk.io>.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/pull: Add collection support to ostree_repo_pull_with_options()
Philip Withnall [Wed, 7 Jun 2017 13:42:22 +0000 (14:42 +0100)]
lib/pull: Add collection support to ostree_repo_pull_with_options()

This adds a new collection-refs option of type a(sss), giving a list of
(collection ID, ref name, checksum) tuples to pull from the given remote.
This option is intended to supersede the refs and override-commit-ids
options, so is mutually exclusive with them.

This includes support for resolving the refs from the remote’s summary
file, or from its refs/heads and refs/mirrors directories.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/refs: Add methods for setting/listing collection–refs
Philip Withnall [Wed, 7 Jun 2017 13:25:59 +0000 (14:25 +0100)]
lib/refs: Add methods for setting/listing collection–refs

These are tuples of (collection ID, ref name) which are a globally-unique
form of local ref. They use OstreeCollectionRef as an identifier, and hence
need to be accessed using new API, as the existing API uses string
identifiers and sometimes accepts refspecs. Remote names are not
supported as part an OstreeCollectionRef.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/repo: Add collection ID support to OstreeRepo
Philip Withnall [Wed, 7 Jun 2017 11:38:59 +0000 (12:38 +0100)]
lib/repo: Add collection ID support to OstreeRepo

Add {get,set}_collection_id() methods to OstreeRepo and some documentation
about the concept of a collection ID which globally identifies an
upstream repository. See the documentation for more details.

This will be used in future commits. For now, the new API is marked as
experimental (--enable-experimental-api).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/ref: Add OstreeCollectionRef type for globally unique refs
Philip Withnall [Wed, 7 Jun 2017 14:27:10 +0000 (15:27 +0100)]
lib/ref: Add OstreeCollectionRef type for globally unique refs

This is a type representing the tuple (collection ID, ref name), which is
guaranteed to be globally unique. It will be used in upcoming commits.

It introduces the concept of a ‘collection’ which is a unique, curated
set of refs which lie in the same trust domain (i.e. all signed by the
same key and validated by the same developer). Flathub might be a
collection, for example; or the set of OS refs coming from a particular
OS vendor.

It includes a function for validating collection IDs.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agolib/repo: Split out ref handling from regenerate_summary()
Philip Withnall [Fri, 9 Jun 2017 08:50:38 +0000 (09:50 +0100)]
lib/repo: Split out ref handling from regenerate_summary()

This will make some future additions to regenerate_summary() easier.
This commit introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

8 years agotests: add a syntax-check rule for glnx_prefix_error()
Colin Walters [Fri, 23 Jun 2017 20:26:44 +0000 (16:26 -0400)]
tests: add a syntax-check rule for glnx_prefix_error()

Same as the errno variant; the colon-space `: ` thing got me in a different
patch.

Closes: #956
Approved by: jlebon

8 years agocmd/fsck: Port to new style
Colin Walters [Fri, 23 Jun 2017 20:09:32 +0000 (16:09 -0400)]
cmd/fsck: Port to new style

Happened to look at this code too, it's a straightforward port.

Closes: #955
Approved by: jlebon

8 years agolib/deltas: Port to more to new code style
Colin Walters [Fri, 23 Jun 2017 19:29:45 +0000 (15:29 -0400)]
lib/deltas: Port to more to new code style

Looking at the uses of `ostree_repo_load_file()` here.

Closes: #953
Approved by: jlebon

8 years agolib/repo: More cleanup of load_file() internals
Colin Walters [Fri, 23 Jun 2017 16:14:07 +0000 (12:14 -0400)]
lib/repo: More cleanup of load_file() internals

This is followon work from previous cleanups.  Basically
`stat_bare_content_object()` was the `fstatat()` logic
and `ostree_repo_read_bare_fd()` was the `openat()` implementation;
they duplicated some bits to find the object in staging, recurse
into parent etc.

Further, I wanted an internal-only version of this API which didn't allocate
`GFileInfo`/`GInputStream` but used a plain `fd` and `struct stat` to avoid
mallocs.

The end version here I think looks a lot nicer, since we deduplicate the various
`open()` calls in the different cases for example.

Closes: #952
Approved by: jlebon

8 years agolib/repo: Split archive/bare file parsing
Colin Walters [Thu, 22 Jun 2017 17:03:14 +0000 (13:03 -0400)]
lib/repo: Split archive/bare file parsing

Prep for future cleanup patches (in particular I want an internal-only
version at first that uses a fd+`struct stat`) to avoid allocations.

The new version avoids lots of deep nesting of conditionals as well
by hoisting the "not found" handling to an early return.

There's a bit of code duplication between the two cases but it's
quite worth the result.

Closes: #951
Approved by: jlebon

8 years agolib/core: Avoid NULL deref in content_file_parse() if out variable unset
Colin Walters [Thu, 22 Jun 2017 17:01:50 +0000 (13:01 -0400)]
lib/core: Avoid NULL deref in content_file_parse() if out variable unset

Prep for a change in `ostree_repo_load_file()`.  We would crash if a
caller had `out_file_info = NULL`, because we deref `ret_file_info`
below it.

Closes: #951
Approved by: jlebon

8 years agobuild: Always include ostree-trivial-httpd.xml in tarballs
Simon McVittie [Wed, 21 Jun 2017 09:26:03 +0000 (10:26 +0100)]
build: Always include ostree-trivial-httpd.xml in tarballs

Signed-off-by: Simon McVittie <smcv@debian.org>
Closes: #949
Approved by: cgwalters

8 years agolib/remote: Fix ‘Since’ line for OstreeRemote
Philip Withnall [Wed, 21 Jun 2017 11:54:28 +0000 (12:54 +0100)]
lib/remote: Fix ‘Since’ line for OstreeRemote

There was a typo in it when it was first introduced. Let’s not live in
the past.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #950
Approved by: cgwalters

8 years agolib/sym: Fix symbol versions for 2017.7 experimental symbols
Philip Withnall [Wed, 21 Jun 2017 11:53:48 +0000 (12:53 +0100)]
lib/sym: Fix symbol versions for 2017.7 experimental symbols

There was a typo in the group name. It should be OK to change the
version since this is all hidden behind the --enable-experimental-api
configure option.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #950
Approved by: cgwalters

8 years agolib/core: Fix ‘Since’ line for ostree_validate_remote_name()
Philip Withnall [Wed, 21 Jun 2017 11:37:12 +0000 (12:37 +0100)]
lib/core: Fix ‘Since’ line for ostree_validate_remote_name()

This was missed when cherry-picking it out of
https://github.com/ostreedev/ostree/pull/924#discussion_r123097919.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #950
Approved by: cgwalters

8 years agoci: Enable -Werror=maybe-uninitialized
Colin Walters [Tue, 20 Jun 2017 21:19:01 +0000 (17:19 -0400)]
ci: Enable -Werror=maybe-uninitialized

We don't want to inject this warning by default for every build
like the other ones in `configure.ac`, since it can be spruriously
wrong.  But there's no reason not to have a more extended set of
warnings for well-known toolchains (e.g. f25).

Closes: #943
Approved by: jlebon

8 years agorepo: Squash a gcc `-Wmaybe-uninitialized` warning
Colin Walters [Mon, 19 Jun 2017 14:54:05 +0000 (10:54 -0400)]
repo: Squash a gcc `-Wmaybe-uninitialized` warning

It's spurious, but unfortunately GCC doesn't currently understand that it will
always be set.

Closes: #943
Approved by: jlebon

8 years agolib/core: Add ostree_validate_remote_name() for remote names
Philip Withnall [Wed, 14 Jun 2017 11:28:52 +0000 (12:28 +0100)]
lib/core: Add ostree_validate_remote_name() for remote names

There are a few places in the code where ad-hoc validation was being
performed. Might as well formalise it a bit more.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #948
Approved by: cgwalters

8 years agobuild: Add ‘devel’ or ‘release’ to OSTREE_FEATURES for test-symbols.sh
Philip Withnall [Tue, 20 Jun 2017 16:38:15 +0000 (17:38 +0100)]
build: Add ‘devel’ or ‘release’ to OSTREE_FEATURES for test-symbols.sh

test-symbols.sh was looking for the DevelBuild string, which is actually
part of the output from `ostree --version`, not $OSTREE_FEATURES.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #948
Approved by: cgwalters

8 years agoci: add ci-release-build.sh
Jonathan Lebon [Mon, 19 Jun 2017 15:25:25 +0000 (11:25 -0400)]
ci: add ci-release-build.sh

Add a check that verifies that `is_release_build` is `yes` only for
release commits. And also verify that the commit message has the correct
version.

Closes: #945
Approved by: cgwalters

8 years agobuild-sys: Post-release version bump
Colin Walters [Mon, 19 Jun 2017 14:37:19 +0000 (10:37 -0400)]
build-sys: Post-release version bump

Closes: #944
Approved by: jlebon

8 years agomain: DevelBuild=yes to `ostree --version` for devel builds
Colin Walters [Mon, 19 Jun 2017 15:23:45 +0000 (11:23 -0400)]
main: DevelBuild=yes to `ostree --version` for devel builds

And use it in `test-symbols.sh`, to fix the `distcheck` case;
the previous change stopped distributing `libostree-devel.sym`
in release builds.

Closes: #944
Approved by: jlebon

8 years agoRelease 2017.7
Colin Walters [Mon, 19 Jun 2017 14:34:35 +0000 (10:34 -0400)]
Release 2017.7

Closes: #942
Approved by: jlebon

8 years agobuild-sys: Add "release build" flag, use for symbol versioning
Colin Walters [Mon, 19 Jun 2017 14:23:21 +0000 (10:23 -0400)]
build-sys: Add "release build" flag, use for symbol versioning

I was trying to do a release and move the symbols from `-devel.sym` into
`-release.sym`, but it turns out that at least GNU binutils `ld` treats an empty
version script as a syntax error.  Fix this by adding a "release build"
flag, and only include `-devel` in non-release builds.

This would also make it easier to inject that flag into our `.pc` and
`ostree-version.h` and `ostree --version` metadata, but I didn't do that yet.

EDIT: Turns out a simpler fix is just to add an empty section. However I kept
this commit since it's a useful sanity check for whether we should include
`-devel.sym` in builds, and we may want to inject the metadata later.

Closes: #942
Approved by: jlebon

8 years agolib/repo: Fix annotations for out parameters
David Shea [Sat, 17 Jun 2017 16:08:41 +0000 (12:08 -0400)]
lib/repo: Fix annotations for out parameters

Change the annotation of the out parameters on ostree_repo_load_file
from `(allow-none)` to `(optional) (nullable)`. `allow-none` is
ambiguous, since these parameters can be both NULL on input and set to
NULL on return.

Closes: #939
Approved by: cgwalters

8 years agostatic delta apply: Work on bare-user-only repos
Alexander Larsson [Mon, 19 Jun 2017 09:06:30 +0000 (11:06 +0200)]
static delta apply: Work on bare-user-only repos

Flatpak make check is failing when applying a static delta
to a bare-user-only repo due to an assert. The fix is to add
bare-user-only to the assert check.

Closes: #940
Approved by: giuseppe

8 years agotests: Fix previous commit for selinux testing
Colin Walters [Fri, 16 Jun 2017 15:26:43 +0000 (11:26 -0400)]
tests: Fix previous commit for selinux testing

I only checked the test passed, I didn't read the output closely, and
made it succeed without testing anything.

Fix the absolute/relative `/etc` references.

Closes: #937
Approved by: jlebon

8 years agopull: When mirroring, only replace summary if we're doing a full mirror
Alexander Larsson [Fri, 16 Jun 2017 08:07:44 +0000 (10:07 +0200)]
pull: When mirroring, only replace summary if we're doing a full mirror

We're hitting this in flathub, where we have a bunch of local builds,
but we also mirror a few refs from the gnome runtime repo into it.
Its fixable by re-doing the summary, but for a short time the
wrong version is visible.

Fixes https://github.com/ostreedev/ostree/issues/846

Closes: #935
Approved by: cgwalters

8 years agocheckout: Fix SELinux policy labeling when recursing
Colin Walters [Fri, 16 Jun 2017 14:36:28 +0000 (10:36 -0400)]
checkout: Fix SELinux policy labeling when recursing

The code here tried to truncate the string to the previous length,
but that doesn't work when recursing, since further calls change the
length.

What actually ended up happening was the string would get corrupted
after the first level of recursion.

Closes: #936
Approved by: jlebon

8 years agolib: Split symbol versioning into -released and -devel
Colin Walters [Thu, 15 Jun 2017 01:44:04 +0000 (21:44 -0400)]
lib: Split symbol versioning into -released and -devel

So far a lot of submitted PR have added symbols into the first
section.  Split the file into `-released` and `-devel` to make
this more obvious.

To further enforce things, we hardcode a checksum of the `-released`
file in `test-symbols.sh`.  Only release commits should update that
checksum.

Did you notice I like checksums?

Closes: #931
Approved by: pwithnall

8 years agoostreee-version.h.in: Added Since: version annotations
Tristan Van Berkom [Thu, 15 Jun 2017 09:00:27 +0000 (18:00 +0900)]
ostreee-version.h.in: Added Since: version annotations

This is especially interesting for the versioning symbols themselves,
as it is an indicator of when applications using introspection information
can start to use a symbol in the library to check if they have a
recent enough version of OSTree to use.

Closes: #932
Approved by: cgwalters

8 years agolib/pull: Extend BAREUSERONLY_FILES flag to HTTP requests
Colin Walters [Wed, 14 Jun 2017 21:55:11 +0000 (17:55 -0400)]
lib/pull: Extend BAREUSERONLY_FILES flag to HTTP requests

For the flatpak PR: https://github.com/flatpak/flatpak/pull/849

It's really more convenient if this works for HTTP pulls as well, since flatpak
does various types of pulling, and we can just set the flag everywhere.

Further, we might as well reject the content as early as possible.

Closes: #930
Approved by: alexlarsson

8 years agolib/sysroot: Add some g_prefix_error() for ostree_sysroot_cleanup()
Colin Walters [Wed, 14 Jun 2017 15:31:52 +0000 (11:31 -0400)]
lib/sysroot: Add some g_prefix_error() for ostree_sysroot_cleanup()

We saw this fail in a CI run. We've been trying to add strategic error prefixing
as a general rule, and this specific instance may help debug.

Closes: #929
Approved by: pwithnall

8 years agobuild-sys: post-release version bump
Colin Walters [Tue, 13 Jun 2017 18:52:46 +0000 (14:52 -0400)]
build-sys: post-release version bump

Per request by flatpak.

Closes: #928
Approved by: alexlarsson

8 years agolib/sysroot: Add API to get pending/rollback for given stateroot
Anton Gerasimov [Thu, 1 Jun 2017 10:43:50 +0000 (12:43 +0200)]
lib/sysroot: Add API to get pending/rollback for given stateroot

This imports a function that is used in rpm-ostree, and it's also intended for
use by https://github.com/advancedtelematic/aktualizr to display
what deployment we're going to boot next after the reboot.

Updated-by: Colin Walters <walters@verbum.org>
Closes: #897
Approved by: OYTIS

8 years agolib/checkout: Add bareuseronly_dirs option
Colin Walters [Tue, 13 Jun 2017 17:26:33 +0000 (13:26 -0400)]
lib/checkout: Add bareuseronly_dirs option

This is a continuation of https://github.com/ostreedev/ostree/pull/926
for directories instead of files.

See: https://github.com/flatpak/flatpak/issues/845

This option suppresses mode bits outside of `0775` for directory
checkouts.  I think most people should start doing this by default,
and use explicit overrides for e.g. `/tmp` if doing a recommit based
on a checkout.

Closes: #927
Approved by: alexlarsson

8 years agolib/pull: Add OSTREE_REPO_PULL_FLAGS_BAREUSERONLY_FILES
Colin Walters [Mon, 12 Jun 2017 19:06:19 +0000 (15:06 -0400)]
lib/pull: Add OSTREE_REPO_PULL_FLAGS_BAREUSERONLY_FILES

This is an option which is intended mostly for flatpak;
see: https://github.com/flatpak/flatpak/issues/845

We're adding an option for pulling into *all*
repo modes that has an effect similar to the `bare-user-only`
change from https://github.com/ostreedev/ostree/pull/909

This way one can pull content into e.g. a root-owned `bare` repository and
ensure that there aren't any setuid or world-writable files.

Closes: #926
Approved by: alexlarsson

8 years agolib/repo: Support hardlink conversions from bare-user to bu-only
Colin Walters [Mon, 12 Jun 2017 17:59:33 +0000 (13:59 -0400)]
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

8 years agolib/repo: Import metadata via hardlink even for distinct repo modes
Colin Walters [Mon, 12 Jun 2017 17:38:52 +0000 (13:38 -0400)]
lib/repo: Import metadata via hardlink even for distinct repo modes

Our previous logic for import-via-hardlink only tried if the repo modes match,
but we *can* hardlink metadata between e.g. `archive` and `bare-user` repos, and
that's quite useful thing to do. Our documentation encourages converting to/from
those repo modes locally for build systems.

Closes: #922
Approved by: alexlarsson

8 years agolib/repo: Skip import via hardlink if repo owners don't match
Colin Walters [Mon, 12 Jun 2017 17:20:42 +0000 (13:20 -0400)]
lib/repo: Skip import via hardlink if repo owners don't match

Before this, if one had repos of matching mode but different owners,
which could happen if one e.g. makes a `bare` non-root repo in
`/ostree/deploy/$stateroot/var/tmp`, every time we tried to call `linkat()`
we'd get `EPERM` and fall back to a copy.

Fix this by saving the repo owner uid, and avoid trying to call `linkat()` if we
know it's going to fail. Of course most commonly in this scenario we'll
immediately fail trying to `chown` the files to `0`, but this is prep for a
future patch to improve `bare-user` → `bare-user-only` imports where we'll be a
bit more sophisticated.

Closes: #922
Approved by: alexlarsson

8 years agolib/pull: Fix construction of a refspec to use the correct separator
Philip Withnall [Wed, 7 Jun 2017 13:29:55 +0000 (14:29 +0100)]
lib/pull: Fix construction of a refspec to use the correct separator

This code looks like it was supposed to build a refspec, but it used a
slash as a separator rather than a colon. The following code does
recover by supporting prefix matching with slashes, but it seems like
this was perhaps not the intention.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #912
Approved by: cgwalters

8 years agolib/repo: Always look in staging directory for objects
Alexander Larsson [Thu, 8 Jun 2017 07:43:23 +0000 (09:43 +0200)]
lib/repo: Always look in staging directory for objects

Its often the case that we want to look at objects inside a commit,
before the objects the transaction is finished. For instance:
  https://github.com/flatpak/flatpak/pull/837
Which tries to verify the file permissions before committing the
transaction.

And:
  https://github.com/flatpak/flatpak/commit/1e5ffa926a25acb655af7889b679b140bf44870b
Which collects the storage size of the objects so that we can
put the total download size in the commit metadata.

I tried to find all the places where we did reads from the
object directories, and in particular this fixes:

 - `ostree_repo_load_file()` for `bare` repos (`archive` was already working).
 - `ostree_repo_query_object_storage_size()`
 - Applying deltas that reference not-yet-commited objects

Closes: #916
Approved by: cgwalters

8 years agolib/repo: Refactor object copy import function
Colin Walters [Mon, 12 Jun 2017 19:36:16 +0000 (15:36 -0400)]
lib/repo: Refactor object copy import function

This came up in: https://github.com/ostreedev/ostree/pull/881

Basically doing streaming for metadata is dumb. Split up the metadata/content
paths so we pass metadata around as `GVariant`. This drops the last internal
caller of `ostree_repo_write_metadata_stream_trusted()` which was the dumb
function mentioned.

Closes: #923
Approved by: jlebon

8 years agolib/checkout: Ignore world-writable dirs for bare-user-only checkout
Colin Walters [Wed, 7 Jun 2017 18:21:59 +0000 (14:21 -0400)]
lib/checkout: Ignore world-writable dirs for bare-user-only checkout

See https://github.com/ostreedev/ostree/pull/909 for more information on the
rationale. Basically there's no reason for flatpak (which uses `bare-user-only`)
to have world-writable dirs. Particularly with the presence of the system
helper.

An approach I considered instead was to parse and validate directory metadata
objects at commit time. We still may do that in addition; for file objects we *had*
to do it that way because the actual files would be laid down suid.  But directories
live only as inert `.dirmeta` objects until we do a checkout (i.e. `mkdir()`), so
we can solve the problem at checkout time.

Closes: #914
Approved by: alexlarsson

8 years agolib/commit: Drop some conditionals/clarify code in content path
Colin Walters [Wed, 7 Jun 2017 17:56:47 +0000 (13:56 -0400)]
lib/commit: Drop some conditionals/clarify code in content path

Both callers of `commit_loose_object_trusted()` were passing
`OSTREE_OBJECT_TYPE_FILE`, so drop that parameter.  This in turn
allows us to drop lots of checking of that inside the function.

Add a doc comment, and rename to `commit_loose_content_object()` for clarity.

Closes: #914
Approved by: alexlarsson

8 years agolib/commit: Port final object writing function to new code style
Colin Walters [Wed, 7 Jun 2017 17:42:15 +0000 (13:42 -0400)]
lib/commit: Port final object writing function to new code style

I noticed my previous patches incorrectly started doing `return glnx_throw*`
inside a `goto out;` function. Fix this by porting forward consistently to new
style. We just do the error prefixing in the caller.

Closes: #914
Approved by: alexlarsson

8 years agorepo: Fix leak of superblock fds when generating summary
Colin Walters [Mon, 12 Jun 2017 14:05:02 +0000 (10:05 -0400)]
repo: Fix leak of superblock fds when generating summary

Related: https://github.com/ostreedev/ostree/issues/920

Closes: #921
Approved by: alexlarsson

8 years agoci: Add CentOS 7 build
Colin Walters [Fri, 9 Jun 2017 14:57:40 +0000 (10:57 -0400)]
ci: Add CentOS 7 build

For similar reasons as https://github.com/projectatomic/rpm-ostree/pull/824

Closes: #919
Approved by: jlebon

8 years agoci: Update to match current rpm-ostree
Colin Walters [Thu, 8 Jun 2017 17:47:20 +0000 (13:47 -0400)]
ci: Update to match current rpm-ostree

This copies the `ci/` directory from rpm-ostree, with much the same rationale;
among other things we don't want to depend on the Docker hub.

The specific reason I'm doing this is that I want to add a CentOS7 build, but
that means we can't use `projectatomic/ostree-tester`, and at that point we
might as well unwind it all.

Closes: #917
Approved by: jlebon

8 years agorepo: After renaming in all loose objects, ensure metadata is stable
Alexander Larsson [Mon, 14 Dec 2015 09:58:53 +0000 (10:58 +0100)]
repo: After renaming in all loose objects, ensure metadata is stable

When a transaction is finished and we have moved all the staged loose
objects into the repo we fsync all the object directory, to ensure the
filenames are stable before we update the refs files to point to the
new commits.

With out this an unclean shutdown after the transaction is finished
could result in a refs file that points to an incomplete commit.

https://bugzilla.gnome.org/show_bug.cgi?id=759442

Closes: #918
Approved by: cgwalters

8 years agorepo/commit: Support group-writable files for bare-user-only
Colin Walters [Wed, 7 Jun 2017 17:18:04 +0000 (13:18 -0400)]
repo/commit: Support group-writable files for bare-user-only

These exist in the wild for flatpak, and aren't really a problem. The canonical
permissions are still either `0755` or `0644`, we just support the additional
writable bit for the group (i.e. extend the set to include `0775` and `0664`)
now to avoid breaking some flatpak content.

Closes: #913
Approved by: alexlarsson

8 years agotests: Add a test for bare-user-only failing to commit suid content
Colin Walters [Wed, 7 Jun 2017 17:12:08 +0000 (13:12 -0400)]
tests: Add a test for bare-user-only failing to commit suid content

We didn't have coverage of this before, and adding the test infrastructure will
help ensure we have coverage for more changes here.

Closes: #913
Approved by: alexlarsson

8 years agolib/repo: For bare-user, mask content object modes with 0775
Colin Walters [Mon, 5 Jun 2017 15:32:52 +0000 (11:32 -0400)]
lib/repo: For bare-user, mask content object modes with 0775

Having every object in a bare-user repo (and checkouts) be executable
is ugly.  I can't think of a good reason to do that; they should only
be executable if their input is.  This does
for `bare-user` what we did for `bare-user-only` in
https://github.com/ostreedev/ostree/pull/909
It's also a stronger version of what we do with `checkout -U` in suppressing
suid - here we also strip world-writable files and the sticky bit (even though
that's meaningless today, it might not be in the future).

Closes: https://github.com/ostreedev/ostree/issues/907
Closes: #908
Approved by: alexlarsson

8 years agolib/repofile: Follow symlinks for `g_file_read()`
Colin Walters [Wed, 7 Jun 2017 19:25:21 +0000 (15:25 -0400)]
lib/repofile: Follow symlinks for `g_file_read()`

This avoids `ostree cat /path/to/symlink` crashing, a longstanding embarassing
issue.

Closes: #915
Approved by: jlebon