Commit Graph

59 Commits

Author SHA1 Message Date
Colin Walters 83b97ec569 lib/deltas: Squash some GCC maybe-uninitialized warnings
These show up in the RPM build, I didn't yet try to figure out why we're not
reproducing them outside of that.

Closes: #1510
Approved by: jlebon
2018-03-22 19:30:16 +00:00
Marcus Folkesson 6bf4b3e1d8 Add SPDX-License-Identifier to source files
SPDX License List is a list of (common) open source
licenses that can be referred to by a “short identifier”.
It has several advantages compared to the common "license header texts"
usually found in source files.

Some of the advantages:
* It is precise; there is no ambiguity due to variations in license header
  text
* It is language neutral
* It is easy to machine process
* It is concise
* It is simple and can be used without much cost in interpreted
  environments like java Script, etc.
* An SPDX license identifier is immutable.
* It provides simple guidance for developers who want to make sure the
  license for their code is respected

See http://spdx.org for further reading.

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

Closes: #1439
Approved by: cgwalters
2018-01-30 20:03:42 +00:00
Colin Walters 1825f03fe7 tree-wide: Update to new libglnx fd APIs
This ends up a lot better IMO.  This commit is *mostly* just
`s/glnx_close_fd/glnx_autofd`, but there's also a number of hunks like:

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

Update submodule: libglnx

Closes: #1259
Approved by: jlebon
2017-10-11 19:26:10 +00:00
Colin Walters 5c7d2dd8be Deduplicate and fix up our use of mmap()
Buried in this large patch is a logical fix:

```
-  if (!map)
-    return glnx_throw_errno_prefix (error, "mmap");
+  if (map == (void*)-1)
+    return glnx_null_throw_errno_prefix (error, "mmap");
```

Which would have helped me debug another patch I was working
on.  But it turns out that actually correctly checking for
errors from `mmap()` triggers lots of other bugs - basically
because we sometimes handle zero-length variants (in detached
metadata).  When we start actually returning errors due to
this, things break.  (It wasn't a problem in practice before
because most things looked at the zero size, not the data).

Anyways there's a bigger picture issue here - a while ago
we made a fix to only use `mmap()` for reading metadata from disk
only if it was large enough (i.e. `>16k`).  But that didn't
help various other paths in the pull code and others that were
directly doing the `mmap()`.

Fix this by having a proper low level fs helper that does "read all data from
fd+offset into GBytes", which handles the size check. Then the `GVariant` bits
are just a clean layer on top of this. (At the small cost of an additional
allocation)

Side note: I had to remind myself, but the reason we can't just use
`GMappedFile` here is it doesn't support passing an offset into `mmap()`.

Closes: #1251
Approved by: jlebon
2017-10-04 20:42:39 +00:00
Colin Walters 6e4146a354 tree-wide: Remove Emacs modelines
We added a `.dir-locals.el` in commit: 9a77017d87
There's no need to have it per-file, with that people might think
to add other editors, which is the wrong direction.

Closes: #1206
Approved by: jlebon
2017-09-21 21:38:34 +00:00
Colin Walters 8eec337fee lib/deltas: Squash Coverity warning for div-by-zero in delta show
If a delta happens to have zero objects, we could end up doing
a divide-by-zero when inferring endianness.  In practice,
a zero-object delta isn't possible to generate I think, but
let's make sure the code is defensive all the same.

Spotted by Coverity.

Coverity CID: 1452208

Closes: #1041
Approved by: pwithnall
2017-08-07 16:10:08 +00:00
Colin Walters 064d7bffef 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
2017-06-29 14:46:18 +00:00
Colin Walters 6f2ea23e8a 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
2017-06-29 14:46:18 +00:00
Colin Walters c2b6afe5b9 lib/deltas: Some style porting
Just a few functions to keep up momentum.

Closes: #964
Approved by: jlebon
2017-06-27 17:19:21 +00:00
Colin Walters 88a1fc92a9 tree-wide: Add+run spatch to use glnx_throw()
I had to run a sed job to add whitespace after, but otherwise this was easy.

Closes: #890
Approved by: jlebon
2017-05-26 19:27:11 +00:00
Colin Walters 9380dbb14d lib: Add "open dfd iter handling noent" helper, port tree-wide
Follow up to a previous patch that addressed a double-close; I
realized we already had a helper for doing "open dfd iter, do nothing
if we get ENOENT".  Raise it to libotuil, and port all consumers.

Closes: #863
Approved by: jlebon
2017-05-16 18:39:19 +00:00
Colin Walters b5c5003ff6 pull: Fold together deltapart+fallback count for display
It's just simpler, and I'm not sure people are going to care
much about the difference by default.

We already folded in the fallback sizes into the download totals, so folding in
the count makes things consistent; previously you could see e.g.
`3/3 parts, 100MB/150MB` and be confused.

Closes: #678
Approved by: giuseppe
2017-02-17 14:58:25 +00:00
Colin Walters 0142e5ff39 delta-show: Don't dump whole superblock, do show fallback checksums
Doing `g_variant_print (superblock)` is unreadable and not very useful,
since we show the checksums as byte arrays.

However, do show the checksums for fallback objects. This makes it easier to see
which objects are fallbacks (and inspect why).

Closes: #678
Approved by: giuseppe
2017-02-17 14:58:25 +00:00
Colin Walters 2f86a5284c lib: Squash last use of GFile deltas_dir
I was having this thought today about making more of the OS readonly,
and ultimately if we got to the point where all ostree operations are
through the repo and sysroot dfds, we could have rpm-ostree be the
only process holding those fds open, and have a read-only bind mount
on top.

Anyways, we're not there, likely won't be soon, but this gets us
closer to being fully fd relative.

Closes: #628
Approved by: jlebon
2016-12-12 15:50:11 +00:00
Colin Walters 4c8fc92aa0 lib: Always checksum content in deltas
This is a follow up to conversation on list - in practice, if we're
backing away from summary signing, then it makes sense to remove the
special casing for checksums in deltas around summary signatures.

This is also related to the recent change to enable GPG checking for
commits in deltas - now we have a more coherent story between the
previous pull path and deltas.

I didn't do any performance checking, and while it's slightly annoying
that we're now doing sha256 on the delta content twice (once for the
part and once per object)...sha256 is pretty fast, I think most users
are I/O bound anyways, and it'd drop even farther if we started using
openssl.

Closes: #612
Approved by: jlebon
2016-12-06 15:59:35 +00:00
Colin Walters 49b8a72622 [ASAN] lib: Squash various leaks in library and commandline
The pull one is the most likely to affect users.  Otherwise mostly
just cleaning up `-fsanitize=address`.

Closes: #587
Approved by: jlebon
2016-11-21 16:34:06 +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 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
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
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
Jonathan Lebon d371aec217 static-delta-core.c: squash unused var warning
Closes: #379
Approved by: cgwalters
2016-07-05 00:34:33 +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
Mathnerd314 4cb77c51db core: Use OSTREE_SHA256_STRING_LEN instead of 64
Closes: #359
Approved by: cgwalters
2016-06-22 16:10:01 +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 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 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 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 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
Alexander Larsson ddda8e5b8b Add support for ostree static-delta delete
Closes: #245
Approved by: giuseppe
2016-04-08 13:42:43 +00:00
Colin Walters 5345573470 deltas: Add a compression size heuristic for endianness detection
I see when analyzing a delta here that due to byteswapping a negative
compression ratio of 540%, 66%, and 28%.  Let's arbitrarily pick 20%
as a threshold for detecting byetswapping.
2016-02-26 08:19:01 -05:00
Colin Walters 7fdf072710 deltas: Heuristically detect endianness for older deltas
If the average object size is greater than 4GiB, let's assume we're
dealing with opposite endianness.  I'm fairly confident no one is
going to be shipping peta- or exa- byte size ostree deltas, period.
Past the gigabyte scale you really want bittorrent or something.
2016-02-26 08:19:01 -05:00
Colin Walters 04d77da005 deltas: Use endianness marker when parsing
Extend the `static-delta show` and `pull` commands to use the
endianness information (if available).
2016-02-26 08:19:01 -05:00
Colin Walters 277220aaa6 deltas: Include an endianness marker
We screwed up and had delta integers use host endianness.  Start
digging out by at least annotating the endianness.

https://bugzilla.gnome.org/show_bug.cgi?id=762515
2016-02-26 08:19:01 -05:00
Alexander Larsson 1833142b14 deltas: Fix regression in ostree_repo_static_delta_execute_offline
xdg-app passed this a filename directly, and in this case it should be
used as is. This regressed to always look for "superblock" in the same
directory as the passed in filename.

https://bugzilla.gnome.org/show_bug.cgi?id=762617
2016-02-24 15:54:09 +01:00
Colin Walters ed7266b10a deltas: Fix some more 32 bit warnings 2016-02-22 22:07:02 -05:00
Colin Walters 0481389afd lib: Expand `ostree static-delta show` to show part stats
Now we display stats on the individual parts, such as the blob size
and the number of each type of opcode.  Most interesting to me is
things like how many bsdiff opcodes there are vs new objects, etc.
2016-02-08 14:46:13 +01:00
Colin Walters 56fc249d08 lib: Create an internal static delta parsing/opening function
We had code to deal with opening/checksumming/decompressing static
deltas in a few places.  I'd like to teach `ostree static-delta show`
how to display more information, and this will allow it to just use
`_ostree_static_delta_part_open()` too.
2016-02-08 14:46:13 +01:00
Colin Walters 98d5f6e3db static-delta: Add `show` subcommand
Right now though, almost all of the details of deltas are private, so
we can't do the "honest thing" and have the command line just use the
shared library.

Eventually some of this should appear in the API, but for now add
command line which is useful for debugging.
2016-01-28 15:38:09 -05:00
Colin Walters fa9e547e09 lib: Add a #define OSTREE_SHA256_DIGEST_LEN 32
And use it internally.  This way it's a bit less magical.
2016-01-28 15:24:16 -05:00
Alexander Larsson 1c056eb282 deltas: Support including detached metadata in static deltas
This is very useful for the inline-parts case, as you can then include
detached signatures in a single file representing the commit.

It is not as important for the generic pull case, as the detached
metadata is only a single small file. Additionally the detached
metadata is not content referenced and may change after the static
delta file was created, so we need to pull the latest version anyway.
2015-11-10 08:56:16 +01:00
Alexander Larsson ec56fea821 deltas: Support passing filename to ostree_repo_static_delta_execute_offline
If you pass a diriectory it will look for the "superblock" child, otherwise
it will use the file as the superblock. I need this in xdg-app to be able
to install any filename as a bundle.
2015-11-10 08:56:15 +01:00
Alexander Larsson 78f14555c8 deltas: Verify checksums in apply-offline unless skip_validate is TRUE 2015-11-10 08:56:14 +01:00
Alexander Larsson e418acb31b delta: Ensure the from commit exists when applying static delta 2015-11-10 08:56:13 +01:00
Alexander Larsson eaa678eaa4 deltas: Make apply-offline only read the parts once
No need to read() the file for the checksum if we then directly mmap it.
Instead we just mmap it initially and checksum from that.
2015-11-10 08:56:13 +01:00
Alexander Larsson 11a79220e2 static deltas: Add support for inline-parts
In this mode the parts are stored in the metadata of the main delta
superblock file.  This can be useful if you want a single-file delta
for easy transport, or for http in the case the delta is very small.
2015-11-10 08:56:12 +01:00
John Hiesey 70c07a6338 static-delta: Fix annotation on ostree_repo_list_static_delta_names
out_deltas should be (transfer-container)
2015-10-21 21:09:23 -04:00
Alexander Larsson fd6c572c42 _ostree_static_delta_part_validate: Take a stream instead of a file as arg
This is only called in one place, and we have already opened the file there,
no need to open it twice.
2015-09-13 22:25:21 -04:00
Alexander Larsson 1ee4007a75 offline delta apply: Handle the version field
It seems the format changed and this code was not updated.
2015-09-13 22:23:56 -04:00
Matthew Barnes c2c322efa9 Use g_autoptr(GVariant) instead of gs_unref_variant 2015-05-06 22:07:10 -04:00
Matthew Barnes bb231fdf74 Use g_autoptr(GPtrArray) instead of gs_unref_ptrarray 2015-05-06 22:07:10 -04:00