Commit Graph

2111 Commits

Author SHA1 Message Date
Simon McVittie 1fc2a1202e ostree_repo_pull_with_options: clear dirs array
Leak found with valgrind memcheck.

Signed-off-by: Simon McVittie <smcv@debian.org>

Closes: #556
Approved by: cgwalters
2016-10-30 22:11:15 +00:00
Simon McVittie 4739709742 keyfile_set_from_vardict: free the string array
g_variant_get_strv is (transfer container): the caller is expected to
free the array, but not the individual strings.

Leak found with valgrind memcheck.

Signed-off-by: Simon McVittie <smcv@debian.org>

Closes: #556
Approved by: cgwalters
2016-10-30 22:11:15 +00:00
Simon McVittie c8a6b037ef _ostree_sysroot_write_deployments_internal: stop leaking hash table
It appears the result of assign_bootserials() is never actually used,
but I haven't changed it to return void right now.

Leak found with valgrind memcheck.

Signed-off-by: Simon McVittie <smcv@debian.org>

Closes: #556
Approved by: cgwalters
2016-10-30 22:11:15 +00:00
Simon McVittie ff28ac4a30 ostree_sysroot_upgrader_finalize: free new_revision
Leak found with valgrind memcheck.

Signed-off-by: Simon McVittie <smcv@debian.org>

Closes: #556
Approved by: cgwalters
2016-10-30 22:11:15 +00:00
Simon McVittie 4c32344b8e ostree_admin_option_context_parse: explicitly clean up when exiting early
The cleanup attribute doesn't clean up before calling a noreturn
function like exit(). Explicitly clean up the pointer variables
(but don't assume that a simple g_object_unref() would be OK either,
in case the behaviour of the cleanup attribute changes).

This isn't a real leak since we're about to exit anyway, but if we
don't fix it then valgrind memcheck will make the tests fail.

Signed-off-by: Simon McVittie <smcv@debian.org>

Closes: #559
Approved by: cgwalters
2016-10-30 21:37:38 +00:00
Simon McVittie 213d5013ce ostree_builtin_pull: consistently set free-function on refs_to_fetch
We are relying on the GPtrArray to free its contents, but we only
give it a free-function on one code path.

Found by valgrind memcheck.

Signed-off-by: Simon McVittie <smcv@debian.org>

Closes: #559
Approved by: cgwalters
2016-10-30 21:37:38 +00:00
Simon McVittie 22ed96d23c ot_admin_builtin_set_origin: don't leak options GVariant
Found by valgrind memcheck.

Signed-off-by: Simon McVittie <smcv@debian.org>

Closes: #559
Approved by: cgwalters
2016-10-30 21:37:38 +00:00
Simon McVittie e757f736e7 _ostree_kernel_args_replace_take: don't leak when replacing
If !existed, then we add arg to kargs->order, where it will be freed
by that array's free-function. However, if the kernel argument did
already exist, we have to either free arg ourselves (and make sure
the old key is what appears in the hash table), or do a linear search
on kargs->order to replace the old key with the new.

Leak found by valgrind memcheck.

Signed-off-by: Simon McVittie <smcv@debian.org>

Closes: #559
Approved by: cgwalters
2016-10-30 21:37:37 +00:00
Colin Walters 05dc77d7e5 remote-refs: Add NULL terminator to options array
Caught by `-fsanitize=undefined`.

Closes: #552
Approved by: jlebon
2016-10-28 17:47:50 +00:00
Giuseppe Scrivano c4c8937b20 static-delta: find a similar filename using what is before '.' or '-'
Improve the heuristic to use only the part before the first '.' when
looking for a similar file in the current directory.

last versions of dracut generate reproducible initramfs files, but we
still fallback to the full file download if there is any minimal
change that causes a different checksum and file name.

This change extends that case to deal better with similar files that
have a different suffix.

This is the difference generating a static delta from
fedora-atomic/f24/x86_64/docker-host to fedora-atomic/f24/x86_64/testing/docker-host

before the patch:

fallback for 111ec866aa7ce3688407fa4a1ae7c9fca93dcee0b851fc9434c59ff947830cc7 (47.0 MB)
fallback for c6a898265de22b02c89ea2f35d132628d0ee1c0a058052ed14fee5799c17904c (47.0 MB)
fallback for fbce656249ece77260887ed873e445561b9d43bcb28a32e759c0b1bab89e7137 (6.6 MB)
fallback for cfdb51457e47e0a0fe0bac38991a21279d2646ff2f019630c7b52a0cd3451397 (6.6 MB)
part 0 n:1972 compressed:11239809 uncompressed:33747412
part 1 n:1079 compressed:9683681 uncompressed:55641397
part 2 n:1507 compressed:15050265 uncompressed:44448838
part 3 n:101 compressed:1865881 uncompressed:31896086
part 4 n:278 compressed:2452585 uncompressed:52811323
part 5 n:18 compressed:67621 uncompressed:100220
uncompressed=218645276 compressed=40359842 loose=545102
rollsum=49 objects, 2117254 bytes
bsdiff=4067 objects

after the patch:

part 0 n:843 compressed:19844109 uncompressed:95443178
part 1 n:1223 compressed:11188609 uncompressed:33330401
part 2 n:990 compressed:15762905 uncompressed:61214132
part 3 n:1441 compressed:20614573 uncompressed:31534195
part 4 n:163 compressed:2734997 uncompressed:51356423
part 5 n:285 compressed:2480813 uncompressed:52902904
part 6 n:14 compressed:59125 uncompressed:75341
uncompressed=325856574 compressed=72685131 loose=533283
rollsum=51 objects, 57235332 bytes
bsdiff=4073 objects

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #554
Approved by: cgwalters
2016-10-28 17:04:25 +00:00
Jonathan Lebon 0333260559 delta: return valid enum member
If we can't figure out what endianness a delta is, we should just throw
ENDIAN_INVALID.

Resolves: #550

Closes: #553
Approved by: cgwalters
2016-10-27 22:16:32 +00:00
Colin Walters 7f2960db43 Define an initializer for GVariant{Builder,Dict}
So we build warning-free on GLib (< 2.50, >= 2.50).  This
is a band aid until we hard-require >= 2.50.

Closes: #547
Approved by: jlebon
2016-10-27 18:49:15 +00:00
Colin Walters 835d97d659 deploy: Suppress unused variable warning for fscreatecon cleanup
Fixes the clang build.

Closes: #551
Approved by: jlebon
2016-10-27 17:50:56 +00:00
Colin Walters cbbfb5369f parse-datetime: Use labs() for long input value
Fixes a compliation warning with CLang, I didn't study it to
see whether this was a major issue or not.

Closes: #548
Approved by: jlebon
2016-10-27 17:02:01 +00:00
Colin Walters 21ca60f987 otutil: Note that ot_log_structured takes a printf format
This notably fixes compilation with CLang.

Closes: #548
Approved by: jlebon
2016-10-27 17:02:01 +00:00
Colin Walters b77edf24a3 tree-wide: Remove unused variables detected by CLang
CLang finds these, whereas GCC treats having
`__attribute__((cleanup))` as a use.

This obsoletes https://github.com/ostreedev/ostree/pull/411

Closes: #548
Approved by: jlebon
2016-10-27 17:02:01 +00:00
Alexander Larsson d0e74cf3af Fix pruning of partial commits
If we have a partial commit it is not an error for a dirmeta to be
missing (in fact, that is likely), so instead of returning a not-found
error from ostree_repo_traverse_commit() we ignore the error and
continue.

In particular, this means we don't stop early at the first
missing dirmeta, which previously caused ostree_repo_prune() to
thing the dirmetas after that to be unreached and thus purged.

Also, we remove the special casing in ostree_repo_prune() to
not report errors for commitpartial, because these should not
be reported anymore.

This fixes https://github.com/ostreedev/ostree/issues/541

Closes: #542
Approved by: cgwalters
2016-10-24 17:48:19 +00:00
Colin Walters d3f14f02e3 Release 2016.12
Closes: #540
Approved by: cgwalters
2016-10-21 19:24:31 +00:00
Alexander Larsson 67bddf76f7 detached metadata: Put these in transaction
If there is a transaction active, then we put writes to detached
metadata into the staging dir, and when reading it we look there
first. This allows transactions to be aborted half-way without
writing the detached metadata into the repository (possibly
overwriting any old metadata from there).

This fixes https://github.com/ostreedev/ostree/issues/526

Closes: #539
Approved by: giuseppe
2016-10-21 10:50:41 +00:00
Alexander Larsson d43c121675 ostree_repo_read_commit_detached_metadata: Handle parent repo
If the detached metadata is not in the repo, try in the parent
repo if that is set.

Without this a commit will not gpg validate in the child repo

Closes: #539
Approved by: giuseppe
2016-10-21 10:50:41 +00:00
Alexander Larsson cf6ec1bbbc Fix regression for symlinks in bare-user repos
Commit 1d4f1b8878 started using hardlinks
checkouts of symlinks. However, symlinks are not stored as symlink in the
repo for bare-user repos, so this breaks user-mode checkouts of such repos.

We fix this by checking for !is_symlink in the bare-user case.

This fixes:
     https://github.com/ostreedev/ostree/issues/537

Closes: #538
Approved by: giuseppe
2016-10-21 09:24:27 +00:00
Colin Walters 1d4f1b8878 core: Do create hardlinks to symlinks for checkouts
I was noticing a recent performance issue with checkouts
which seemed to be mostly us going back to doing a `fsync()` on
directories.

Regardless, while looking at that, I saw we were spending time
creating new symlinks. Even though symlinks are small, it's still
better to hardlink them.

Going way back in time, the reason we weren't doing this is
because we were hitting `EMFILE` on ext4, but that was for
gnome-continuous which creates *many* build roots.  Even
there though, they're just a cache, and we handle `EMFILE`.

For ostree-for-host-system, we don't expect to have many roots (just 3
at most transiently), so hardlinking symlinks does make sense.

Closes: #521
Approved by: jlebon
2016-10-17 20:40:15 +00:00
Jonathan Lebon a660e5650d OstreeFetcher: provide proxy credentials if needed
There seems to be an issue in libsoup which causes basic auth
credentials to not be passed to the proxy during requests. We thus have
to handle PROXY_UNAUTHORIZED responses and provide the auth ourselves.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1370558
Related: https://bugzilla.gnome.org/show_bug.cgi?id=772932

Closes: #529
Approved by: cgwalters
2016-10-14 16:06:08 +00:00
Jonathan Lebon a0598cb494 ostree-sysroot-deploy.c: delete redundant check
Just noticed this while inspecting the code. The deployments retrieved
by `_ostree_sysroot_list_deployment_dirs_for_os` will forcibly already
have a matching osname since it indirectly uses that same variable to
construct them. Having a check there makes it look like there may be
subtle corner cases, when there aren't.

Closes: #529
Approved by: cgwalters
2016-10-14 16:06:08 +00:00
Alexander Larsson ee484697cd pull: Support multiple specifications of --subpath
I need this in flatpak to avoid doing multiple pulls when doing
locale subsetting.

Closes: #523
Approved by: cgwalters
2016-10-11 16:41:03 +00:00
Alexander Larsson 0446cdb0d3 pull: Support inherit-transaction
If this is true, don't initiate, abort of commit a transaction, instead
it is assumed that the caller initiated the transaction, and that it
will eventually be commited.

This allows you to do multiple pulls or a combination of pulls and
commits in a single transaction.

Closes: #525
Approved by: cgwalters
2016-10-07 19:34:47 +00:00
Colin Walters a0e1344cf8 Release 2016.11
Closes: #524
Approved by: cgwalters
2016-10-07 19:21:41 +00:00
Colin Walters 54621d9e53 libglnx: Update to latest
This pulls in a new compilation flag for wrpseudo compatibility.  Also
note we need to add some includes since glnx-libcontainer went away,
and with it some includes for `sys/mount.h` etc.

Closes: #522
Approved by: cgwalters
2016-10-06 11:54:39 +00:00
Colin Walters 524d2d5cb2 trivial-httpd: Port mostly to fd-relative
We were seeing some weird potential memory corruption in this code
when using it for `rpm-ostree-toolbox installer`, which is almost
certainly not its fault, but let's use it as an excuse to port
(mostly) to fd-relative and away from GFile.

Dropping the last GFile use here is a bit tricky as it does have a
nice high level wrapper around inotify.

Closes: #512
Approved by: jlebon
2016-10-05 21:48:41 +00:00
Colin Walters a981e5fd76 checkout: Fix fsync defaults for new API to be off for real
My previous change in https://github.com/ostreedev/ostree/pull/425
actually broke things so we basically used the repository defaults =(

This is a subtle mess since we're only trying to flip things off
for the *new* API.

Clean this up so that the "default repo inheritance" lives only in one
place - in the compat layer for the old checkout API.  The new
checkout API defaults to off period, so the repository state is
irrelevant.

Closes: #520
Approved by: jlebon
2016-10-05 21:34:57 +00:00
Dan Nicholson 6c84fa4366 admin: Allow running status unlocked
It's useful to let non-root see the current system status.

Closes: #515

Closes: #516
Approved by: jlebon
2016-09-30 18:29:26 +00:00
Jonathan Lebon 318430dc70 ostree_sysroot_init_osname: also create /var/log
/var/log is another one of those core directories that should be made
available and properly labeled during early boot before tmpfiles.d
starts up.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1265295

Closes: #513
Approved by: cgwalters
2016-09-20 18:03:57 +00:00
Colin Walters 450361d89b boot: Ensure we remount /var writable before systemd does journal flush
Otherwise, we may not get a persistent journal for the first boot.
https://bugzilla.redhat.com/show_bug.cgi?id=1265295

Closes: #511
Approved by: jlebon
2016-09-15 19:41:44 +00:00
Colin Walters f2b6afd2df sysroot: Drop an unnecessary fsync
While looking at a slow update issue (which I'm guessing is
unpredictable I/O latency in an OpenStack instance), I noticed
in one of the traces we were inside a fsync here.

Dropping the fsync here is just another of a long series of unwinding
them - we `syncfs()` the sysroot fd and `/boot` and we have a big
`sync()` anyways.

Closes: #508
Approved by: jlebon
2016-09-14 19:14:46 +00:00
Colin Walters 4f736ac33e sysroot: Drop an fsync for origin file when writing deployments
More fsync pruning.  Since we have a public API for writing the origin
file and it did a fsync before, let's preserve that.  But when writing
deployments as part of a full transaction, we rely on the global
`syncfs()`, so add an internal function for origin file writing that
doesn't.

Closes: #509
Approved by: giuseppe
2016-09-14 10:26:39 +00:00
Colin Walters fcffb73280 sysroot: Port origin writing code to fd-relative
Just preparatory cleanup for a next patch which makes
the fsyncing configurable.

Closes: #509
Approved by: giuseppe
2016-09-14 10:26:39 +00:00
Colin Walters 84a9d61e15 sysroot: Port some small cleanup code to fd-relative
Just a quick patch since I saw this function scroll by in Emacs and it
was too ugly not to be rewritten.

Closes: #510
Approved by: giuseppe
2016-09-14 10:13:12 +00:00
Owen W. Taylor a8301b909c ostree_sysroot.c: Don't close sysroot_fd twice.
If ostree_sysroot_unload() was called explicitly, then sysroot_fd
would be closed again at finalization time, possibly closing a
random file descriptor belonging to some other part of the
application.

Closes: #507
Approved by: cgwalters
2016-09-13 13:19:10 +00:00
Owen W. Taylor a5af1cb688 ostree-repo.c: Fix file descriptor cleanup
0 was used as an "unset" flag for tmp_dir_fd, which is technically
incorrect. For cache_dir_fd, -1 was used as the sentinal but 0
was checked for, resulting in close(-1).

Closes: #507
Approved by: cgwalters
2016-09-13 13:19:10 +00:00
Colin Walters 5893b68ef7 pull: Do allow executing deltas when mirroring into bare{,-user}
In https://github.com/ostreedev/ostree/pull/408 we fixed a
bug where we would crash when trying to execute deltas into
an archive repo (which isn't presently supported).

But that was overly aggressive - we obviously *can* execute deltas
when mirroring into a bare repo.  This should fix a regression with
the way flatpak uses mirroring to pull from a user repo into the
system.

Closes: #506
Approved by: alexlarsson
2016-09-12 12:50:34 +00:00
Jonathan Lebon 12e916466c static-delta: add some error handling
We make _ostree_parse_delta_name() a bit more defensive since it handles
user input.

Closes: #504

Closes: #505
Approved by: cgwalters
2016-09-09 19:06:11 +00:00
Colin Walters 36e8ba124e Release 2016.10
Closes: #502
Approved by: cgwalters
2016-09-09 00:28:02 +00:00
Colin Walters 916684ba0d core: Make OSTREE_TIMESTAMP public API
This way e.g. flatpak can detect which timestamp it should use.
See `flatpak/common/flatpak-utils.c:flatpak_zero_mtime`.

Closes: #501
Approved by: cgwalters
2016-09-09 00:10:21 +00:00
Colin Walters 30aaffa995 sysroot: Avoid double cleanup, and ensure no cleanup if specified
Since forever, we've been doing two cleanups.  In
8ece4d6d51
I thought we were doing just one and wanted to go to zero (if specified),
but I actually just dropped one cleanup.

In https://github.com/projectatomic/rpm-ostree/pull/452
@jlebon pointed out the duplication.  Fix this by creating a new internal
deploy wrapper that takes cleanup flags.

(Since we already had the "piecemeal cleanup" API internally, let's
 frame it in terms of that, rather than passing down a boolean).

Closes: #500
Approved by: jlebon
2016-09-08 20:42:09 +00:00
Colin Walters 82b756783b fetcher: Fix another finalization deadlock
If the current repo is already up to date (we have no content to
fetch), it's possible for the fetcher to not request any URIs.  So
create and then finalize it quickly.

Finalization involves calling `g_main_loop_quit()` +
`g_thread_wait()`.  However, if `g_main_loop_quit()` is run *before*
`g_main_loop_run()`, we'll deadlock because GMainLoop assumes in
`_run()` to start things.

This is a common trap - ideally, GMainLoop would record if `_quit()`
was called before `_run()` or something, but doing that now would
likely break people who are expecting quit() -> run() to restart.

In general, we've moved in various GLib-consuming apps to an
explicit "main context iteration with termination condition" model;
see `pull_termination_condition()` in the pull code.

This fixes this race condition.

I verified that an assertion in `_finalize` that more than
zero URIs were requested was hit in multiple test cases, and this patch
has survived a while of make check loops.

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

Closes: #499
Approved by: jlebon
2016-09-08 20:09:07 +00:00
Colin Walters 23b4b58d57 delta: Unreference files we've processed
This should help avoid address space exhaustion on 32 bit systems,
and in general is obviously going to improve efficiency.

Closes: #498
Approved by: alexlarsson
2016-09-08 15:21:41 +00:00
Colin Walters e127070550 repo: Only use mmap() for metadata > 16k
See http://stackoverflow.com/questions/258091/when-should-i-use-mmap-for-file-access
and
https://lwn.net/Articles/591978/

I didn't really notice much performance difference in some small
tests, but I happened to be stracing and realized we were `mmap()`ing
even for 50 bytes which is not very useful, so let's not do it.

Closes: #489
Approved by: alexlarsson
2016-09-08 14:56:30 +00:00
Colin Walters 8dbb104cdc delta: Add missing `goto out` for failure to mmap()
This was hit in practice when generating a delta for a flatpak app on ARM
it looks like.

Closes: #497
Approved by: alexlarsson
2016-09-08 14:34:04 +00:00
Colin Walters 845dc65196 repo: Revert default timestamp from 1 back to 0
Quoting Dan Nicholson in

  <https://github.com/ostreedev/ostree/pull/330#issuecomment-245499099>

  mtime of 0 has been the semantics of ostree deployments from basically
  the beginning of the project. We (and others, see
  flatpak/flatpak@b5204c9) rely on that fact when generating trees.

  In particular, this affects caches that use the mtime of the
  associated file or directory to determine if the cache is valid. By
  arbitrarily changing the mtime of the files to something else, all
  the caches we setup in the build are now invalidated. Preseeding
  caches is really important to the user experience as it avoids
  having the user wait while they're regenerated on first run.

  Now, we could change our build infrastructure to preset all the
  mtimes to 1 to match this change, but what does that do for our
  existing users who are on an ostree that deploys with mtimes of 0?
  We could just revert this change at Endless (and the associated one
  in Flatpak), and that would be fine for our users. However, if we
  point non-Endless users to our apps, they'll have the great
  experience of waiting 10 seconds the first time they launch it while
  the fontconfig cache is rebuilt unnecessarily.

Closes: #495
Approved by: jlebon
2016-09-08 13:35:59 +00:00
Giuseppe Scrivano f760a4612a gpg: do not segfault when the algorithm name is not known
Reported by: Patrick Uiterwijk
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #494
Approved by: cgwalters
2016-09-08 11:19:20 +00:00
William Manley 2aacc6912b ostree-prepare-root: Fix running with musl
musl libc's implementation of `realpath` works by opening the path and then
doing a lookup in `/proc/self/fd` to find the canonical path.  This fails
if `/proc` is not mounted.  This causes problems for us if
`ostree-prepare-root` is `init` as `/proc` won't be mounted.

We have to mount `/proc` anyway for `/proc/cmdline` so this fix just
expands the scope over which `/proc` is mounted to include both our
`realpath` calls.

See also:

* http://www.openwall.com/lists/musl/2016/06/08/2 and
* http://git.musl-libc.org/cgit/musl/tree/src/misc/realpath.c?id=e738b8cbe64b6dd3ed9f47b6d4cd7eb2c422b38d

Closes: #485
Approved by: cgwalters
2016-09-01 20:17:58 +00:00
William Manley 5424404813 ostree-prepare-root: Error if realpath fails
I've seen it fail with musl which needs `/proc` to be mounted for it to
work.  The error messages we're rather confusing before.  At least this
now points to the right location.

Closes: #485
Approved by: cgwalters
2016-09-01 20:17:58 +00:00
Jonathan Lebon 3b55db9661 pull code: clean up mirrorlist hack
While converting the mirrorlist code from using GSList to GPtrArray, I
completely missed the fact that there is now a much cleaner way to do
this.

Closes: #484
Approved by: cgwalters
2016-08-31 18:54:59 +00:00
Jonathan Lebon 157d878ce1 pull: add mirrorlist support
This commit adds mirrorlist support to the fetcher. Users can now
prepend url or/and contenturl by mirrorlist= to interpret the link as a
mirrorlist.

If an object is not found, the fetcher will automatically try the next
mirror in the order given in the list (assuming the order returned by
the server is significant).

Closes: #469
Approved by: cgwalters
2016-08-31 16:52:12 +00:00
Jonathan Lebon 9546b93382 pull: drop fetching_sync_uri
This made sense back when we used a main loop even when we needed to
fetch objects synchronously. Nowadays, we no longer actually update
progress before the FETCHING_OBJECTS phase, which is only for async
requests.

This allows us to get rid of fetch_uri_contents_membuf_sync() and to
generalize fetch_uri_contents_utf8_sync() so that it only requires a
fetcher. This will be needed later.

Closes: #469
Approved by: cgwalters
2016-08-31 16:52:12 +00:00
Jonathan Lebon bfa8eaccd3 trivial-httpd: prepend timestamp in log file
I've found this useful when monitoring multiple logs at the same time to
test the upcoming content & meta URL splitting.

Closes: #469
Approved by: cgwalters
2016-08-31 16:52:12 +00:00
Jonathan Lebon 8d9d3a1d4a pull code: support contenturl setting
Allow users to pass a --contenturl during `remote add` and store it in
the remote config.

Fish out the contenturl setting from the remote config and use it when
downloading static deltas and objects (except for commit signatures).
The idea here is that items in the trust chain (summary & sigs) can be
fetched from a more secure e.g. TLS-pinned location, while objects
themselves are fetched from another location. Once mirrorlist support is
added, this use-case will become even more advantageous.

Closes: #469
Approved by: cgwalters
2016-08-31 16:52:12 +00:00
Colin Walters dd71999dc9 Release 2016.9
Closes: #481
Approved by: jlebon
2016-08-31 16:36:19 +00:00
Georges Basile Stavracas Neto cafc517c6b repo-pull: properly store the cancellable
OSTree function ostree_repo_pull_with_options starts a
series of operations that makes heavy use of the PullData's
cancellable.

This isn't effective, however, since nowhere in the code
the OtPullData.cancellable field is set. This is visible,
for example, when trying to cancel a Flatpak pull and nothing
happens, because the cancellable is not properly passed
to the pull data.

Fix that by setting the cancellable field of the pull data. It
owns a reference for safety reasons, and unreferences it at the
end of the operation.

ostreedev/ostree#482

Closes: #483
Approved by: cgwalters
2016-08-31 15:21:06 +00:00
William Manley 1dc69dc879 switchroot: Move `path_is_on_readonly_fs` to header file
This simplifies the build system by removing the need for
`libswitchroot-mountutil.la`.

Original idea by @cgwalters in #477.

Closes: #478
Approved by: cgwalters
2016-08-30 22:41:27 +00:00
William Manley a128abd9bc switchroot: Replace custom error printing with err/warn functions from libc
The `warn()` libc extension has exactly the same behaviour as our own
`perrorv` function, but is available in (at least) glibc and musl.  As an
added bonus the similar function `err()` which will exit with an error
code afterwards.

This implementation is tidier and allows us to get rid of our own
`perrorv`.  It paves the way to removing `ostree-mount-util.c` to simplify
the build scripts.

Original idea by @cgwalters in #477.

Closes: #478
Approved by: cgwalters
2016-08-30 22:41:27 +00:00
William Manley faee3df8ae switchroot: Fix building with musl libc
POSIX and GNU define conflicting versions of `strerror_r`.  The GNU
version returns the string but doesn't necessilary write into buf.
The POSIX version writes into buf and returns the length but doesn't
necessilary append a terminate the string with a NUL if it's too long
to fit in buf.

This commit fixes building ostree-prepare-root with musl libc.  The
stripped static build with musl on my machine is 30K vs. 724K with glibc
static and 11K with glibc shared.

Closes: #477
Approved by: cgwalters
2016-08-30 20:50:33 +00:00
Colin Walters a269075724 commit: Don't delete tmp/cache dir
We hold a fd open on this, and it's basically now expected
to be immortal.  Confer that status.

This was showing up in flatpak crashers, because we'd get
an unexpected errno.

(I didn't test this fixes the crasher, but it's clearly right)

https://bugzilla.redhat.com/show_bug.cgi?id=1347293

Closes: #476
Approved by: alexlarsson
2016-08-29 17:30:15 +00:00
Colin Walters 8ece4d6d51 sysroot: Add a flag to suppress post-deploy cleanup
I noticed seeing the output of `prune` twice in rpm-ostree, and had
always wondered why.  When reading the rpm-ostree code to fix
something else, reasons, I noticed the reason - we were pruning once
here, and then once after rpm-ostree regenerates its "base" refs.

There's no reason to clean twice, so let's add a flag so rpm-ostree
can suppress doing it inside libostree.

Closes: #474
Approved by: giuseppe
2016-08-29 07:45:24 +00:00
Colin Walters cfc3934e81 sysroot: Drop unnecessary `dup()` invocation
It's close-on-exec, not close-on-fork.  I was clearly confused when
writing this; it works just fine to reference the fd in the child and
`fchdir()` before exec.  So drop the unnecessary duplication.

Just noticed this while reading the code for a random other reason.

Closes: #473
Approved by: giuseppe
2016-08-28 13:56:03 +00:00
Gatis Paeglis b6ec7526b5 u-boot: Merge ostree's and systems uEnv.txt
This is a proper fix for:
https://bugzilla.gnome.org/show_bug.cgi?id=755787

With this patch, an admin (system builder) can now:

1) Edit /usr/lib/ostree-boot/uEnv.txt
2) Deploy the new tree. OSTree will append system's uEnv.txt
   to the OSTree's managed uEnv.txt (loader/uEnv.txt).

It is common for u-boot systems to read in an extra env
from external /uEnv.txt. The same file OSTree uses to pass
in its env. With this patch /uEnv.txt now contains OSTree's
env + custom env added by system builders.

Closes: #466
Approved by: cgwalters
2016-08-27 13:11:22 +00:00
Giuseppe Scrivano 47b0b4120a pull: use same name for parameter and documentation comment
Fixes this warning:

src/libostree/ostree-repo-pull.c:2162: Warning: OSTree: ostree_repo_pull_with_options: unknown parameter 'remote_name_or_baseurl' in documentation comment, should be 'remote_name'

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #472
Approved by: jlebon
2016-08-27 12:40:46 +00:00
Colin Walters 3ef4cc2e5b lib: Add an API to list only "our" objects, fix prune to use it
When doing a prune, we should not try to delete objects in parent
repos, since it'll fail.  There is a bigger discussion about the
semantics of `parent=` to be had, but this will fix trying to use
`ostree prune --repo=/ostree/repo/extensions/rpmostree/pkgcache`.

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

Closes: #471
Approved by: jlebon
2016-08-25 20:01:37 +00:00
Colin Walters 683e060099 repo: Add prefixes to errors for querying size/deleting
I hit these while causing errors in prune.  Let's add the specific
object we were looking for.

Closes: #471
Approved by: jlebon
2016-08-25 20:01:37 +00:00
Colin Walters 05ac14326c pull: Make .commitpartial files world readable
In CentOS, these happened to appear in a repo that is served
via rsync, and having them not be world-readable caused mirroring
tools to fail.

They aren't secret, so don't make them so.

Closes: #468
Approved by: giuseppe
2016-08-25 13:03:16 +00:00
Jonathan Lebon 76166cb52e pull_with_options: fix stray return FALSE
Closes: #465
Approved by: cgwalters
2016-08-18 14:45:01 +00:00
Jonathan Lebon 21d3063fcf pull_with_options: allow GPG verification override
We used to only look at the "gpg-verify" and "gpg-verify-summary"
options when we're passed a local URL. Make these options also have an
effect in the configured remote case.

Closes: #465
Approved by: cgwalters
2016-08-18 14:45:01 +00:00
Jonathan Lebon e005da74ef pull_with_options: fix remote parameter name & desc
Closes: #465
Approved by: cgwalters
2016-08-18 14:45:01 +00:00
Colin Walters 77af6844d8 rofiles-fuse: Rework to be based on nlink
Programs like `useradd` try to `open(/etc/passwd, O_RDWR)` to append,
which didn't work with rofiles-fuse.  Thinking about this, I realized
that there's a simpler algorithm for "can we write to this file" which
is "does it have a hardlink count <= 1"?

Switching to this both drops complexity (we no longer need to keep a
hash table of files we created), and also lets useradd work.

Closes: #462
Approved by: jlebon
2016-08-16 21:22:28 +00:00
Dan Nicholson b1d13bb356 repo: Really ignore progress changed user data
The documentation says this is ignored, implying that you should pass
NULL to it. However, the function immediately returns in this case even
though the argument isn't used anywhere.

Closes: #458
Approved by: cgwalters
2016-08-12 14:56:07 +00:00
Gatis Paeglis fd1a044d6e Move ostree-* executables to /usr/lib/ostree
Why not to use libexecdir?

Because this directory does not exist on some distros or paths
between distros varies. There are several reasons why a well
known path is prefered, for example when generating a kernel
command line:

init=${ostree}/usr/lib/ostree-boot/ostree-prepare-root

In addition this saves us some typing in a console when wanting
to access the "ostree" cmd line.

Closes: #449
Approved by: cgwalters
2016-08-11 14:04:59 +00:00
Dan Nicholson 1caef17c7f pull: Disable static deltas by default for local pulls
For local pulls there's no benefit pulling the static delta over the
individual object files since there's no HTTP overhead. Furthermore,
processing deltas always generates the objects whereas a standard pull
ensures that the exact object files are copied. Using deltas also
prevents hardlinking the objects if the repos exist on the same
filesystem.

Closes: #447

Closes: #448
Approved by: cgwalters
2016-08-10 10:54:46 +00:00
Dan Nicholson 80c573478b pull-local: Support requiring static deltas
Add the --require-static-deltas option like pull to ensure static deltas
are processed for local pulls.

Closes: #447

Closes: #448
Approved by: cgwalters
2016-08-10 10:54:46 +00:00
Dan Nicholson c3c07a2d49 deltas: Use F_DUPFD_CLOEXEC properly
You need to supply an argument to F_DUPFD_CLOEXEC or fcntl will return
EINVAL. Use 3 as the minimum fd number as is standard.

Closes: #454

Closes: #448
Approved by: cgwalters
2016-08-10 10:54:46 +00:00
Dan Nicholson 1e5ff71c49 deltas: Handle cleanup of fd array properly
If there's an early error, part_temp_fds will be NULL and dereferencing
the len member will segfault.

Closes: #454

Closes: #448
Approved by: cgwalters
2016-08-10 10:54:46 +00:00
Colin Walters 07ec35ef03 libostree.sym: Add 2016.9 section
We should remember to do this in the commit updating configure.ac.

Closes: #453
Approved by: jlebon
2016-08-09 20:00:24 +00:00
Colin Walters a29bb0ab6b Final excision of libgsystem dependency
Lots and lots of preparation led to this moment - when nothing
apparent changes for users!  Woo!

But seriously, having the extra dependency is a minor annoyance, and
in the big picture I think the libgsystem idea was wrong - we need to
land things in GLib, and use git submodules for API-unstable or
Linux-specific sharing.  For a lot of OSTree, the libgsystem `GFile*`
orientation was also wrong, we really want fd-relative.

Closes: #444
Approved by: jlebon
2016-08-09 15:36:09 +00:00
Colin Walters fd9536bb19 prune: Retain the tip of each ref even with date pruning
I hit an error with [CAHC](https://wiki.centos.org/SpecialInterestGroup/Atomic/Devel)
where we were doing time-based pruning.  `ostree summary -u` started failing,
and it took me a bit to realize it was because we were pruning
even the tip of old branches, which I was not at all expecting,
and I don't think users will too.

Perhaps in the future we could add some sort of --prune-ref-tips or
something if people wanted it, but I doubt it.

Closes: #445
Approved by: jlebon
2016-08-09 15:12:35 +00:00
Colin Walters d238683332 deploy: Use internal recursive copy rather than libgsystem
Since we already had a "recursive copy" implementation here, let's
reuse it rather than the libgsystem `gs_shutil_cp_a()`.  Part of the
libglnx porting.

Closes: #428
Approved by: jlebon
2016-08-08 14:16:34 +00:00
Colin Walters 686d0352e1 deploy: Port file copying code to GLnxDirFdIterator
It handles ownership of the `DIR*` for us more cleanly, and
is just a better API.

This is in preparation for further changes to this code to do SELinux
labeling while copying.

Closes: #428
Approved by: jlebon
2016-08-08 14:16:34 +00:00
Colin Walters 8dab17f6db repo: Fix an uninitialized variable
Closes: #431
Approved by: giuseppe
2016-08-08 11:13:06 +00:00
Colin Walters 6b089304bf repo: Drop more internally unused GFile members
I forgot to actually remove `config_file` in the previous
commit, the txn lock hasn't been used in a long time, and
for the uncompressed cache, everything uses the fd already.

Closes: #433
Approved by: giuseppe
2016-08-08 08:31:59 +00:00
Colin Walters d55655b096 repo: Drop internal GFile config_file
The remote parsing code still uses GFiles but this is a start.

Closes: #432
Approved by: giuseppe
2016-08-05 08:26:07 +00:00
Colin Walters 18a576c390 lib: Drop GFiles for self->{objects_dir,state_dir}
Everything that used to reference these is now fd-relative.

Closes: #432
Approved by: giuseppe
2016-08-05 08:26:07 +00:00
Colin Walters 308c75e281 repo: Port metadata writing code to fd-relative
It was the last thing referencing `self->objects_dir`.

Closes: #432
Approved by: giuseppe
2016-08-05 08:26:07 +00:00
Colin Walters cfd402e5f7 lib: Fix a compiler warning introduced from earlier patch
I think we'd end up closing stdin...yuck.  Need to investigate
having this be fatal, but CentOS 7 `gcc-4.8.5` doesn't understand
`-Werror=int-conversion`.

Closes: #430
Approved by: giuseppe
2016-08-05 07:38:09 +00:00
Colin Walters 30aa1ec668 lib: Use libglnx file replace API more consistently
We have a better API now, drop use of the internal helper, which also
depended on libgsystem.

This required bumping libglnx to pull in a fix.

Closes: #429
Approved by: giuseppe
2016-08-04 21:27:32 +00:00
Colin Walters 593effe2fb lib: Add padding booleans to OstreeRepoCheckoutAtOptions
Since this is a new API, and adding booleans is the most likely thing
we'll do, let's stick some explicit padding for them in here now.

We could use the `unused_ints[]` but it'd be out of order, and this
will more clearly remind people about the padding.  The efficiency hit
versus bitfields is annoying, but oh well, not a real world problem.

Closes: #427
Approved by: giuseppe
2016-08-04 12:18:28 +00:00
Colin Walters 18d826e3a5 repo: Flip the fsync default to off for new checkout API
Since we're adding a new API, we have the opportunity to fix
the defaults.  We expect clients to do a `syncfs()` or equivalent
on their own now, since it's way more efficient.

Flip the checkout fsync default to off.

Closes: #425
Approved by: giuseppe
2016-08-04 07:33:31 +00:00
Colin Walters f66906c401 deltas: Port compilation to libglnx/fd-relative
This was the last use of libgsystem tmpfile APIs.  The change here is
a bit uglier than it needs to be because we support creating the delta
in place as well as in the repo, so we needed to abstract over
locations.

Closes: #424
Approved by: giuseppe
2016-08-03 08:10:27 +00:00
Colin Walters a843d16de2 grub2: Port away from gs_file_sync_data()
Inlining this is uglier, but this code kind of sucks anyways =( We're
going to need to do some fd-relative porting in here at some point.

Closes: #424
Approved by: giuseppe
2016-08-03 08:10:27 +00:00
Colin Walters c671c1dd3e lib: Port away from gs_file_rename()
In one case, we already had relative fds and hence this was
nicer.  Unfortunately the other areas got uglier.  More fd-relative
porting to do later.

Closes: #424
Approved by: giuseppe
2016-08-03 08:10:27 +00:00
William Manley 78f99d4780 ostree-prepare-root: Fix typo in error message
Closes: #403
Approved by: cgwalters
2016-08-02 19:07:25 +00:00
William Manley 6356edaaba ostree-prepare-root: Make error message capitalisation consistent
There seemed to be more lower case first letters so I've standardised
on that.

Closes: #403
Approved by: cgwalters
2016-08-02 19:07:25 +00:00
William Manley 485a374b21 ostree-prepare-root: Use pivot_root if real sysroot is already mounted at /
This allows ostree-prepare-root outside of the initramfs context where the
real rootfs is already mounted at /.  We can't use `mount --move` in this
case because we would be trying to move / into a subdirectory of itself.

Closes: #403
Approved by: cgwalters
2016-08-02 19:07:25 +00:00
William Manley 83c0fdc352 Refactor ostree-prepare-root: Perform chdir to deploy directory earlier
...for simplicity.  This way we don't need to keep concatenating
deploy_path to everything.  We can just refer relative to the current
working directory.

We need to do this after bind-mounting it over itself otherwise our cwd
is still on the non-bind-mounted filesystem below.

Closes: #403
Approved by: cgwalters
2016-08-02 19:07:25 +00:00
William Manley 47e7afab27 ostree-prepare-root: Refactor: Create /sysroot.tmp much later
Typically we have our ready made-up up root at
`/sysroot/ostree/deploy/.../` (`deploy_path`) and the real rootfs at
`/sysroot` (`root_mountpoint`).  We want to end up with our made-up root
at `/sysroot/` and the real rootfs under `/sysroot/sysroot` as systemd
will be responsible for moving `/sysroot` to `/`.

We need to do this in 3 moves to avoid trying to move `/sysroot` under
itself:

1. `/sysroot/ostree/deploy/...` -> `/sysroot.tmp`
2. `/sysroot` -> `/sysroot.tmp/sysroot`
3. `/sysroot.tmp` -> `/sysroot`

This is a refactoring to group all these operations together so I can
implement an alternative in terms of `pivot_root`.

Closes: #403
Approved by: cgwalters
2016-08-02 19:07:25 +00:00
William Manley a0a4052365 ostree-prepare-root: Cope with /proc not being mounted
When trying to read kernel command-line.

Closes: #403
Approved by: cgwalters
2016-08-02 19:07:25 +00:00
William Manley c9551dc231 ostree-prepare-root as init: exec init from deployment if run as PID1
This supports running ostree on embedded platforms without an initrd.
Specificially I'm trying to do bringup on an NVidia Tegra based Jetson TK1
dev board.

Closes: #403
Approved by: cgwalters
2016-08-02 19:07:25 +00:00
William Manley 1364e6e30d ostree-prepare-root: Refactor code to resolve deploy_path
I'll reuse this for a new ostree-init.

Closes: #403
Approved by: cgwalters
2016-08-02 19:07:25 +00:00
Colin Walters 24671f7d25 repo: Port to g_autoptr() rather than old style cleanup macros
This notably kills a few libgsystem uses here.

Closes: #423
Approved by: giuseppe
2016-08-01 21:00:12 +00:00
Colin Walters 421c902125 repo: Port sign_data() to libglnx tmpfile APIs
Part of dropping libgsystem.

Closes: #423
Approved by: giuseppe
2016-08-01 21:00:12 +00:00
Colin Walters 6f17237849 deploy: Replace a use of gs_file_enumerator with compat wrapper
More libglnx/glib porting.

Closes: #423
Approved by: giuseppe
2016-08-01 21:00:12 +00:00
Colin Walters 5334758ba7 repo: Make ostree_repo_create() nonfatal on existing repos
In general we want to support "idempotentcy" or "state
synchronization" across interruption.  If a repo is only partially
created due to a crash or whatever, it's hard for a user to know that.
Let's just make `ostree_repo_create()` idempotent. Since all we're
doing is a set of `mkdirat()` invocations, it's quite simple.

This also involved porting to fd-relative, which IMO makes the
code a lot clearer.

Closes: #422
Approved by: 14rcole
2016-08-01 15:12:14 +00:00
Dan Nicholson 512090785e deltas: Allow processing of empty delta parts
If a static delta is generated between 2 commits with the same content,
then the delta will contain 1 part with no checksums. While useless,
this is a valid delta that shouldn't raise an assertion. If the delta
part has no checksums, then there are no objects to recreate and the
processing can be skipped.

Closes: #420
Approved by: cgwalters
2016-07-31 00:01:52 +00:00
Giuseppe Scrivano edecae06ab libostree, ostree: fix usage of ostree_repo_checkout_tree_at
it was deprecated, use ostree_repo_checkout_at.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #417
Approved by: cgwalters
2016-07-30 11:24:52 +00:00
Giuseppe Scrivano 0bac88e132 libostree: skip introspection for two functions
These two functions are not safe for gobject introspection, so annotate
them to be skipped:

1) ostree_repo_import_archive_to_mtree
2) ostree_repo_export_tree_to_archive

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #417
Approved by: cgwalters
2016-07-30 11:24:52 +00:00
Giuseppe Scrivano 8867693240 libostree: mark ostree_repo_checkout_tree_at as deprecated
and move its definition to a separate file.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #417
Approved by: cgwalters
2016-07-30 11:24:52 +00:00
Giuseppe Scrivano 30963766c7 libostree: new function ostree_repo_checkout_at
Provide a gobject introspection safe version for
`ostree_repo_checkout_tree_at'.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #417
Approved by: cgwalters
2016-07-30 11:24:52 +00:00
Colin Walters 6d310db1e7 libglnx porting: Migrate to new tempfile code
In general this is even cleaner now, though it was better after I
extracted a helper function for the "write tempfile with contents"
bits that were shared between metadata and regular file codepaths.

Closes: #369
Approved by: jlebon
2016-07-29 19:02:41 +00:00
Jonathan Lebon 1db0c8dcd6 static-delta: remove unused struct
Closes: #418
Approved by: cgwalters
2016-07-29 16:38:19 +00:00
Jonathan Lebon e9f08d45f7 static-delta: fix command contexts
Closes: #418
Approved by: cgwalters
2016-07-29 16:38:19 +00:00
Colin Walters 6ffcb24d22 deltas: Handle untrusted checksums faster and more robustly
When reworking the ostree core [to use O_TMPFILE](https://github.com/ostreedev/ostree/pull/369),
I hit an issue in the way the untrusted delta codepath ends up trying
to re-open the file to checksum it.  That's not possible with
`O_TMPFILE` since the fd (which we opened `O_WRONLY`) is the only
accessible reference to the content.

Fix this by changing the delta processing code to update a checksum as
we're doing writes, which is also faster, and ends up simplifying the
code as well.

What would be an even larger simplification here is if we e.g. used a
separate thread calling `write_object()` or something like that; the
main issue I see there is somehow bridging the fact that function
wants a `GInputStream*` but the delta code is generating stream of
writes.

Closes: #392
Approved by: jlebon
2016-07-29 16:03:28 +00:00
Colin Walters fc25fa16e1 lib: Fix compiler warning from previous patch
I had this in a `fixup!` I thought.

Closes: #414
Approved by: giuseppe
2016-07-28 14:46:17 +00:00
Colin Walters a38f2f41b2 lib: Fix leak in bootconfig parser
Pretty simple.

Closes: #410
Approved by: giuseppe
2016-07-28 10:10:17 +00:00
Colin Walters 27559c58a9 deploy: Fix leaks in parsing /etc/os-release
This one is a bit subtle; we're generating a hash that contains
pointers to the strings we parsed, so we need to carefully track
ownership.

Closes: #410
Approved by: giuseppe
2016-07-28 10:10:17 +00:00
Colin Walters 707ef93097 sysroot: Fix a leak in deployment dirpath API
This one is pretty obvious in retrospect.

Closes: #410
Approved by: giuseppe
2016-07-28 10:10:17 +00:00
Colin Walters ba21023d6c fetcher: Explicitly join thread if it's not self
This fixes a valgrind leak; see [this StackOverflow thread](http://stackoverflow.com/questions/17642433/why-pthread-causes-a-memory-leak).

Closes: #410
Approved by: giuseppe
2016-07-28 10:10:17 +00:00
Colin Walters 35008ead77 pull-local: Explicitly unref variant rather than relying on floating
This shows up as a leak in valgrind; the callee isn't sinking.  In
general through the power of cleanup attributes we can do explicit
cleanup rather than relying on floating refs.

Closes: #410
Approved by: giuseppe
2016-07-28 10:10:17 +00:00
Colin Walters 7f335a8437 trivial-httpd: Fix leak of option context
Right now our valgrind runs also end up valgrinding the
`trivial-httpd` code, so while it doesn't matter, let's fix this leak
anyways.  We need to avoid calling `_exit()` since that won't run the
cleanup functions.

Closes: #410
Approved by: giuseppe
2016-07-28 10:10:17 +00:00
Colin Walters bac1fa1839 pull: Don't execute static deltas when mirroring
We don't presently support this, since the static delta code assumes
it can just `mmap()` file objects.  We could at some point implement
this, but for now just skip executing deltas when doing
`archive -> archive` mirroring.

I noticed this when trying to mirror a repo in Jenkins in
[CAHC](https://wiki.centos.org/SpecialInterestGroup/Atomic/Devel).

Closes: #408
Approved by: giuseppe
2016-07-25 06:50:51 +00:00
Colin Walters a6aeacede6 repo: Fix leak with ostree_repo_commit_traverse_iter_init_commit()
I noticed this using `OT_TEST_VALGRIND=1` on `test-basic.sh`.

Closes: #385
Approved by: jlebon
2016-07-22 14:01:07 +00:00
Dan Nicholson db974b0596 core: Add allocating b64 checksum functions
The checksum_b64_inplace variants can't be used in bindings. Provide
versions that allocate and return the output rather than working on a
passed in buffer. These can then be used in GI bindings to get the
ostree modified base64 encodings.

Closes: #398
Approved by: cgwalters
2016-07-15 02:18:27 +00:00
Dan Nicholson 2e97e72123 lib: Fix version script node ordering
The order of the VERSION nodes is such that the new node name goes first
and the one it depends on goes after the commands. See
https://sourceware.org/binutils/docs/ld/VERSION.html.

Closes: #398
Approved by: cgwalters
2016-07-15 02:18:27 +00:00
Colin Walters efa1fa6534 builtins/commit: Switch to using ostree_repo_write_dfd_to_mtree()
Where we're referencing local files.  It's what
ostree_repo_write_directory_to_mtree() is doing internally anyways,
and I consider the `GFile*` based APIs to be generally deprecated for
the most part.

Closes: #394
Approved by: giuseppe
2016-07-14 08:08:53 +00:00
Colin Walters f45eca948c repo: Ensure we set mode for bare-user files before xattrs
When trying to switch ostree to `O_TMPFILE`, I hit the fact that
by default it uses mode `000`.  It still works to write to the
open fd of course, but it *doesn't* work to set xattrs because
that code path for some reason in the kernel checks the mode bits.

This only broke for bare-user repos where we tried to set the xattr
before calling `fchmod()`, so just invert those two operations.

Closes: #391
Approved by: jlebon
2016-07-12 14:09:37 +00:00
Dan Nicholson 4ebcd57fec repo: Fix annotation for ostree_repo_add_gpg_signature_summary
GI needs to know this is a NULL terminated array of gchar or you'll
segfault using it from a binding.

Closes: #387
Approved by: cgwalters
2016-07-08 22:22:28 +00:00
Colin Walters c31cf75552 Release 2016.7
Closes: #386
Approved by: jlebon
2016-07-08 19:40:55 +00:00
Colin Walters 972ed3e54e fetcher: Remove unused GTask structure member
Spotted by mbarnes.

Closes: #383
Approved by: mbarnes
2016-07-08 18:38:11 +00:00
Colin Walters 5d21650ea5 fetcher: Clear all data for session in session thread
Conceptually the session thread owns the session, so let's clear out
everything predictably there, rather than sometimes having it happen
on the main thread.

Also, this moves up clearing the pending/outstanding queues *before*
we unreference the session, since conceptually they need to reference
it as well.

Based on a patch from: Matthew Barnes <mbarnes@redhat.com>

Closes: #383
Approved by: mbarnes
2016-07-08 18:38:11 +00:00
Colin Walters b4c15209e8 fetcher: Hold a ref to main context for lifetime of thread
I don't think this fixes the bug I was seeing, but it makes me more
comfortable to know we have a strong ref to the main context across
the thread lifetime, and we only unset the default right before
we go away.

If something in `thread_closure_unref()` used
`g_main_context_get_thread_default()` for example it'd be wrong
before.

Closes: #383
Approved by: mbarnes
2016-07-08 18:38:11 +00:00
Colin Walters d7629d33a4 tests: Add some test coverage of repeated pulls w/HTTP 500s
Systems like pulp may want to keep retrying in a loop if the server
throws a (hopefully transient) 500, and we need test coverage of
handling these errors versus our existing 404 and 206 coverage.

Closes: #383
Approved by: mbarnes
2016-07-08 18:38:11 +00:00
Mathnerd314 b0bfb92831 pull: Free fetch_data by default
This should fix the memory leaks in #352

This is a subset of the changes, the other part is in my pull code rewrite

Closes: #382
Approved by: cgwalters
2016-07-06 20:57:40 +00:00
Jonathan Lebon d371aec217 static-delta-core.c: squash unused var warning
Closes: #379
Approved by: cgwalters
2016-07-05 00:34:33 +00:00
Bastien Nocera 9df846559a libostree: Fix build failure with glib 2.42
G_DEFINE_AUTOPTR_CLEANUP_FUNC is a new function in GLib 2.44, but
libglnx contains a backported version of it. A few source files were
however using G_DEFINE_AUTOPTR_CLEANUP_FUNC either without including
libglnx.h, or without including it early enough.

This fix is similar to the one in commit d368624.

Closes #376

Closes: #377
Approved by: smcv
2016-07-04 15:25:20 +00:00
Colin Walters 0d07c7ecde delta: Add --if-not-exists option
I often want to have "idempotent" systems that iterate to a known
state.  If after generating a commit, the system is interrupted, I'd
like the next run to still generate a delta.  But we don't want to
regenerate if one exists, hence this option.

Closes: #375
Approved by: jlebon
2016-07-04 13:27:06 +00:00
Jonathan Lebon f4e92a1e06 ostree admin switch: fix short summary
Closes: #371
Approved by: cgwalters
2016-06-27 18:06:25 +00:00
Colin Walters 439069b2bb checkout: Add an option to require hardlinks
I've seen a few people hit this and wonder why checkouts are slow/take
space.  Really, ensuring this happens is the *point* of OSTree.
Physical copies should be a last resort fallback for very unusual
situations (one of those is rpm-ostree checking out the db since
librpm doesn't know how to read from libostree).

Even I hit the fact that `/var` is a mountpoint disallowing hardlinks
with `/ostree` once and was confused.  =)

Add this to the rofiles-fuse test case because it creates a mount
point.

Closes: #368
Approved by: jlebon
2016-06-27 13:08:46 +00:00
Colin Walters da989b473d rofiles-fuse: Do allow fchmod/fchown on directories
The program is called ro*files* and ostree creates physical
copies of directories, so changing them is fine.

I hit this when trying to do a copy checkout onto an rofiles-fuse
mount.

Closes: #368
Approved by: jlebon
2016-06-27 13:08:46 +00:00
Colin Walters 073c34ca08 pull: Write commitpartial files for local imports too
Just like HTTP fetches, these can be interrupted, so we need to write
the commitpartial files.

Closes: #324
Approved by: yuqi-zhang
2016-06-24 15:21:38 +00:00
Yu Qi Zhang 02a2b689dd refs: resolve conflict between local/remote repos
Add the functionality to use the same name for refs in local and remote
repos. This helps users keep track of local refs of remote origin, much
like local and remote git branches.

Previously, when a local ref is specified, resolve_refspec would fall
back to searching through remote repos if the ref is not found locally.
This function now takes an extra flag to specify whether it should
search through remote repos. Additionally, ostree_repo_resove_rev_ext
was added to call resolve_refspec with fallback_remote being false, so
refs --create would no longer complain when trying to create a local
ref of the same name as a remote one.

Fix remote repo parsing not being handled correctly on refs --create.

Closes: #363
Approved by: jlebon
2016-06-23 19:52:26 +00:00
Alexander Larsson fc4a7ec35e pull: Correctly handle repo->parent_repo when applying static deltas
In flatpak i was using a parent repo, and it failed to update
with ENOENT when dispatching an set-read-source opcode, because the
object it referenced was in the parent repo.

This fixes that by making _ostree_repo_read_bare_fd look
at parent_repo.

Closes: #362
Approved by: cgwalters
2016-06-23 11:36:33 +00:00
Mathnerd314 9a779563bb refs: Fix a logic error
I encountered the Opening remotes/ dir error with some broken pull code, and this fixes it.

Closes: #358
Approved by: cgwalters
2016-06-22 20:15:42 +00:00
Mathnerd314 23049bbd01 core: Add OSTREE_OBJECT_TYPE_COMMIT_META
This is cleaner than the loose_path_with_suffix approach

Closes: #359
Approved by: cgwalters
2016-06-22 16:10:01 +00:00
Mathnerd314 4cb77c51db core: Use OSTREE_SHA256_STRING_LEN instead of 64
Closes: #359
Approved by: cgwalters
2016-06-22 16:10:01 +00:00
Krzesimir Nowak 91ccaff197 core: Fix wrong return value docs
ostree_commit_get_parent() returns a string form of a checksum, not a
binary form.

Closes: #360
Approved by: cgwalters
2016-06-22 12:45:12 +00:00
Yu Qi Zhang 744543110e refs: allow overwrite of empty folders
We noticed that once a ref folder is created, there is no existing
command that can remove it. For example, once "foo/bar" is created,
even if the user deletes foo or all the refs under foo, the folder
will persist.

Now when the user attempts to create a ref "foo" either through commit
or refs --create, if a folder "foo" exists but is empty of refs, the
folder is removed and the new ref "foo" is created.

New unit tests in tests-ref.sh verify this functionality.

Closes: #354
Approved by: cgwalters
2016-06-21 20:20:15 +00:00
Colin Walters f6ce04e480 libglnx porting: Drop uses of gs_file_openat_noatime
We're not really doing the "noatime" thing anymore.

Closes: #341
Approved by: jlebon
2016-06-21 18:24:17 +00:00
Colin Walters 90b9a06277 lib: Use g_file_enumerator_iterate() if available, with fallback
Import `gs_file_enumerator_iterate()` for the next six months or
so...after RHEL 7.3 is released I'm strongly considering hard
requiring 2.46 or so.

Likely at some point we should figure out how to share more "glib
backport" code with NetworkManager at least.

Closes: #341
Approved by: jlebon
2016-06-21 18:24:17 +00:00
Colin Walters 9e2763106b lib: Use sd_journal directly (optionally)
This was the last caller of libgsystem that isn't
`gs_file_get_path_cached()`.  I think the use case ostree has where
the same code can be called via command line and via a shared library
*and* via a daemon is rather unusual, so let's just copy the code for
logging from libgsystem into here.

For example rpm-ostree hard depends on a daemon mode, so it'll just
use `sd_journal` directly.

Closes: #341
Approved by: jlebon
2016-06-21 18:24:17 +00:00
Colin Walters 4819b44189 libglnx porting: Use of GSDirFdIterator
This one was pretty simple.  One of the uses in `repo.c` was just a
leftover variable.

Closes: #341
Approved by: jlebon
2016-06-21 18:24:17 +00:00
Colin Walters 0134c62157 libostree.sym: Fix test-symbols
The test isn't smart enough to ignore comments, so change the prefix.

Closes: #356
Approved by: jlebon
2016-06-20 22:59:27 +00:00
Colin Walters 6c7e191147 Release 2016.6 2016-06-20 11:51:32 -04:00
Colin Walters 535033a4f0 pull: Ensure we always process queue only from main thread
I was easily reproducing a hang on pulls with thousands of requests on
current git master.  The initial symptom seemed to be that there are
multiple code paths where we don't invoke
`session_thread_process_pending_queue()`.  We really need to do
that any time we remove something from the outstanding queue,
to ensure it gets filled again.

A further issue is that we were tying the lifecycle of the pending
object to the `GTask`, but the task could be unref'd from the main
thread (via a `GSource` on the main thread), and that introduced
threadsafety issues, because the hash table and other data suddenly
could be concurrently modified.

Both of these need to be fixed together.  First, we introduce
`Arc<Pending>`, and ensure that both the main and worker threads hold
references.

Second, we ensure that we re-process the queue *immediately* whenever
a task is done, inside the worker thread, rather than doing it
incidentally via an unref.  This architecture is quite similar to what
the outside pull code is doing.

Closes: #350
Approved by: jlebon
2016-06-17 18:19:23 +00:00
Colin Walters 651f4bc3b9 repo: Avoid a possible divide by zero in progress
The previous code was subject to a divide by zero if less than a
second had passed.  Rework it so we only do the divide if more than a
second has passed.

Closes: #349
Approved by: Mathnerd314
2016-06-17 02:30:13 +00:00
Colin Walters ab47a8a030 Add "archive" as an alias for "archive-z2"
I find the "-z2" is really a long ago relic of the past when I changed
the format.  We no longer have anything to do with the original
`archive`, so let's start allowing people to type `--mode=archive`
which just looks saner.

At some point later I'll update the docs too, but it'll be an annoying
transition period as we'll have to say "On older OSTree, use -z2" etc.

Closes: #346
Approved by: giuseppe
2016-06-16 14:34:23 +00:00
Yu Qi Zhang f8fcdba0a5 refs: add "ostree refs --create" and unit tests
Added the ability to create a ref (much like a git tag) for an
existing commit through "ostree refs EXISTING --create=NEWREF".
Previously the only way to create a new ref was by creating a new commit,
but refs --create allows multiple refs to point to the same commit.

The command will fail if:
 - None/more than one existing ref is specified
 - The specified EXISTING tag does not exist, or was not specified
 - The specified NEWREF already exists, or is the name of a folder

Add unit tests in tests-ref.sh to verify above functionality

Closes: #340
Approved by: jlebon
2016-06-15 20:42:30 +00:00
Colin Walters 7847bc7394 lib: Port some manual close() cleanups to be glnx_fd_close
Just noticed this while reading some code, we didn't have many manual
`out: close()` bits left, this pushes us over the edge to autocleanup
almost everywhere.

Closes: #332
Approved by: jlebon
2016-06-13 14:58:55 +00:00
Alexander Larsson f6b70a32e6 pull: Fix leak of refs_to_fetch
Closes: #333
Approved by: giuseppe
2016-06-10 11:12:59 +00:00
Alexander Larsson c9c4ab851e pull: Fix leaked uri in request_static_delta_superblock_sync
Closes: #333
Approved by: giuseppe
2016-06-10 11:12:59 +00:00
Alexander Larsson 785f894de1 pull: Fix leak of FetchObjectData in some cases
Closes: #333
Approved by: giuseppe
2016-06-10 11:12:59 +00:00
Alexander Larsson bd4e250e93 pull: Fix leak of debug temporary strings
Closes: #333
Approved by: giuseppe
2016-06-10 11:12:59 +00:00
Alexander Larsson 8e3d558f23 libotutil: Fix leak of VariantMapData
Closes: #333
Approved by: giuseppe
2016-06-10 11:12:59 +00:00
Colin Walters 70af1d26b1 tests: Modernize valgrind infrastructure
The recent memleak fixes motivated me to look at the bitrotted code to
run invocations of `ostree` in the test suite underneath valgrind.

There are a few things here.  First, update suppressions file from
libhif, since I recently worked on it.

When running *uninstalled* as we now support, we need
`libtool --mode=execute` in the mix so it expands out to
the uninstalled binary and we don't valgrind the intermediate shell.

However, it's harder than that because we chdir into a tmpdir,
which defeats the libtool logic.  AFAICS, the only fix for this
is to determine the realbin path before we chdir, and then unfortunately
we need to change every use of `ostree` to `${OSTREE}` =(

Then this immediately breaks for me on RHEL7 because my ancient
copy of `valgrind-3.10.0-16.el7.x86_64` is unaware of syscall 306, i.e.
`syncfs`.

But let's do this first before I dive into that.

Closes: #292
Approved by: krnowak
2016-06-09 21:10:35 +00:00
Colin Walters c015fe13fb lib: Add OSTREE_SUPPRESS_SYNCFS environment variable
Just to work around valgrind not understanding the `syncfs()` syscall
in EL7 right now.

Closes: #292
Approved by: krnowak
2016-06-09 21:10:35 +00:00
Colin Walters 0f7bf7be95 lib: Fix a leak in remote parsing
As the docs say, `g_regex_match()` still allocates a match even if it
returns `FALSE`.  Using `g_autoptr` is just plain better.

Closes: #292
Approved by: krnowak
2016-06-09 21:10:35 +00:00
Mathnerd314 1b88dc7f90 docs: Get API docs working again
This changes around a few things that didn't work for me:
* Section names seem to be ostree-* instead of libostree-*
* Also XML files are ostree-* (they didn't show up at all)
- gtk-doc doesn't seem to parse const _OSTREE_PUBLIC correctly
* pull documentation is now on the actual functions rather than stubs
* Update gitignore with some more files

And there some changes to make gtk-doc give fewer warnings (not finished)

Closes: #327
Approved by: cgwalters
2016-06-09 18:15:49 +00:00
Mathnerd314 693b4ec4be pull: Move pull and pull_onedir back into ostree-repo.c
They call pull_with_options, which will fail anyway.

Closes: #327
Approved by: cgwalters
2016-06-09 18:15:49 +00:00
Mathnerd314 da5cb099a6 pull: Move libsoup-related code from ostree-repo.c to ostree-repo-pull.c
This centralizes the ifdef's in one file, which will make it
easier to write new pull backends.

ostree-repo-pull.c is now built unconditionally

Closes: #327
Approved by: cgwalters
2016-06-09 18:15:49 +00:00
Mathnerd314 0e9a875393 repo: use OSTREE_TIMESTAMP (=1) for checked-out files
1 is a better choice than 0 because some programs use 0
as a special value; for example, GNU Tar warns of an
"implausibly old timestamp" with 0.

Closes: #330
Approved by: cgwalters
2016-06-09 18:04:55 +00:00
Colin Walters f94b191ae5 repo: (minor) Drop a GFile usage in signature creation
Just one user of hundreds but, the rest of the function was ported
now.

Closes: #319
Approved by: jlebon
2016-06-09 14:39:09 +00:00
Colin Walters 70e5489258 lib: Add a helper for mmap->bytes with openat(), use it in repo
This kills another GSystem consumer...I think down the line I'd like
to do something like "detect whether file is > 1k if so, mmap,
otherwise just readall()" so we can use this helper in more places.

Closes: #319
Approved by: jlebon
2016-06-09 14:39:09 +00:00
Colin Walters 3a03a35071 lib: Add `_ALLOW_NOENT` flag to internal variant mapping API
We have a lot of "allow_noent" type wrapper functions since
a common pattern is to allow files to not exist, but still
throw cleanly on other issues.

This is another instance of that, and cleans up duplicated error
handling code.

Part of this is prep for moving away from `GFile` consumers.

Closes: #319
Approved by: jlebon
2016-06-09 14:39:09 +00:00
Colin Walters 5a996c04de glnx porting: Drop use of gs_file_openat_noatime
As noted previously the "noatime" thing is mostly obsoleted by
relatime.

Closes: #319
Approved by: jlebon
2016-06-09 14:39:09 +00:00
Colin Walters 882561b01c libglnx porting: Drop last use of gs_transfer_out_value()
Closes: #319
Approved by: jlebon
2016-06-09 14:39:09 +00:00
Colin Walters a79c47415a glnx porting: Drop last uses of gs_file_get_basename_cached()
I apparently missed a few uses in the previous porting.

Closes: #319
Approved by: jlebon
2016-06-09 14:39:09 +00:00
Krzesimir Nowak b5da2f524c repo: Fix build on 32-bit systems
On 32-bit systems the modifier for printing 64bit values should be
%llu instead of %lu. Just use appriopriate macros that do the right
thing.

Closes: #329
Approved by: giuseppe
2016-06-09 11:25:29 +00:00
Jonathan Lebon 2240d1108e ostree_repo_write_commit: add missing docstring arg
Closes: #325
Approved by: cgwalters
2016-06-07 19:47:58 +00:00
Krzesimir Nowak d78e12fc39 summary: Fix a typo
The --gpg-sign parameter will be used for signing the summary, not the
commit. This probably was copy-pasted from the ostree commit command.

Closes: #320
Approved by: cgwalters
2016-06-03 19:39:40 +00:00
Colin Walters eaea07fe43 glnx porting: Port away from gs_file_get_basename_cached()
In some cases we use glnx_basename(), in others we already had a
`GFileInfo` around with the name.

Closes: #316
Approved by: jlebon
2016-06-02 14:52:40 +00:00
Colin Walters 900c085f21 libglnx porting: Port away from gs_file_map_noatime()
The "no atime" thing was mostly useful only before "relative atime"
updates landed.  Users who care about performance will turn it off
entirely anyways.

Closes: #316
Approved by: jlebon
2016-06-02 14:52:40 +00:00
Colin Walters c148631a98 lib: Drop GFile variant mapping API for fd-relative
In addition to generic fd relative porting,
this is a necessary preparatory step for libglnx porting, because
when I tried to use `g_mapped_file_new` I hit an issue with
it using a different error domain from GIO.

Thankfully libglnx consistently uses the GIO error domain, and here
we're now using it for the `open()` call.

Closes: #317
Approved by: jlebon
2016-06-01 15:02:41 +00:00
Colin Walters f725d39f11 lib: Change ot_util_variant_map helpers to consistently sink refs
This is similar to changes Krzesimir has been doing recently - we
really don't need the ergonomics of floating refs since we have
autocleanups.

We should continue to change most of our code to sink refs.

Specifically here it was pretty broken that the `_map()` API was
sinking but the other two weren't, and this broke some refactoring I
was trying to do later.

Closes: #317
Approved by: jlebon
2016-06-01 15:02:41 +00:00
Sam Spilsbury a189b19fd0 repo: Display estimated time remaining when pulling
Bug 765429 said that not having a time estimate can be annoying
when working with large pulls.

There isn't any complex time estimation logic here - we just take
the number of bytes remaining and do a linear projection of
the bytes per second rate at the current point in time.

Closes: #318
Approved by: cgwalters
2016-06-01 14:09:41 +00:00
Colin Walters 24cb0ffc6a core: Port to new libglnx tempname API
Drops another libgsystem use, and as bonus we malloc less too.

Closes: #311
Approved by: jlebon
2016-05-31 18:08:46 +00:00
Colin Walters 7748c361ef sysroot: Correct error handling path in previous libglnx port
I happened to have the github page open with my commit after it was
merged, and then noticed a bug.

We still need to throw if we hit a non-`ENOENT` error.

Closes: #315
Approved by: giuseppe
2016-05-30 15:40:47 +00:00
Colin Walters 6e57987c7c libglnx porting: Port away from gs_file_ensure_directory()
The init-fs code in particular gets (IMO) a lot cleaner being fd
relative.

Closes: #312
Approved by: giuseppe
2016-05-30 11:33:28 +00:00
Colin Walters e5eb6f3a22 libglnx porting: Port callers of gs_file_unlink to just unlink()
In the second case it's actually less code too.

Closes: #312
Approved by: giuseppe
2016-05-30 11:33:28 +00:00
Colin Walters 9d39d3af85 repo: Port uncompressed cache GC to libglnx
- Kills a user of `gs_file_unlink`
 - Is fd-relative
 - Is way less malloc-y.

Closes: #312
Approved by: giuseppe
2016-05-30 11:33:28 +00:00
Colin Walters 33047d5d4f libglnx porting: Port "load utf8 file" contents API callers
Closes: #312
Approved by: giuseppe
2016-05-30 11:33:28 +00:00
Krzesimir Nowak 4929ab4033 repo: Add functions for verifying any data in repository
This can be useful for validating the 3rd party data that is put in
the extensions directory and is signed with the same keys as commits
or the summary file.

Closes: #310
Approved by: cgwalters
2016-05-27 11:20:00 +00:00
Krzesimir Nowak 27f0c6980a repo: Factor out setting up a GPG verifier
Moved out setting up a GPG verifier to a separate function, as I would
like to use it for the any data verification function in the following
commit.

Closes: #310
Approved by: cgwalters
2016-05-27 11:20:00 +00:00
Krzesimir Nowak 582169f83e repo: Add a missing Returns paragraph
Closes: #310
Approved by: cgwalters
2016-05-27 11:20:00 +00:00
Krzesimir Nowak 89bfb1d503 repo: Factor out the check of gpg result to a separate function
I plan to add a function for verifying any data which may return the
error about lack of trusted signatures, so let's avoid the redundancy
and put the check in the separate function.

Closes: #310
Approved by: cgwalters
2016-05-27 11:20:00 +00:00
Krzesimir Nowak 569e43c280 core: Add a function creating an archive-z2 content stream
It is quite similar to the already existing
ostree_raw_file_to_content_stream function, so I factored the common
part to a separate function. The difference is that we cannot report
the size of the resulting stream.

Can be useful for serving a "bare" repository as a faked "archive-z2"
repository.

Closes: #308
Approved by: cgwalters
2016-05-26 16:53:08 +00:00