summaryrefslogtreecommitdiff
path: root/src/libotutil/ot-fs-utils.c
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: Run clang-formatColin Walters2023-05-021-58/+38
| | | | | This is a one-time tree wide reformatting to ensure consistency going forward.
* libotutil: add utility functions for calculating directory sizeJonathan Lebon2023-04-141-0/+44
| | | | Prep for future patch.
* Use g_steal_fd() in preference to glnx_steal_fd()Simon McVittie2023-03-171-1/+1
| | | | | | | g_steal_fd() exists in GLib since 2.70, and libglnx has a backport for older GLib versions, equivalent to the libglnx-specific glnx_steal_fd(). Signed-off-by: Simon McVittie <smcv@collabora.com>
* Update FSF license notices to use URL instead of addressJoseph Marrero2021-12-071-3/+1
|
* libotutil: factor out utility to parse file by lineJonathan Lebon2018-02-021-0/+26
| | | | | | | This will be used in the checkout CLI as well. Closes: #1442 Approved by: cgwalters
* Add SPDX-License-Identifier to source filesMarcus Folkesson2018-01-301-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* tree-wide: Update to new libglnx fd APIsColin Walters2017-10-111-2/+2
| | | | | | | | | | | | | | | | | | | 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
* lib/utils: Port a bit to decl-after-stmt styleColin Walters2017-10-051-11/+7
| | | | | | | Add add some more comments. Closes: #1247 Approved by: jlebon
* Deduplicate and fix up our use of mmap()Colin Walters2017-10-041-12/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* tree-wide: Remove Emacs modelinesColin Walters2017-09-211-2/+1
| | | | | | | | | We added a `.dir-locals.el` in commit: 9a77017d87b74c5e2895cdd64ad098018929403f 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
* tree-wide: Some glnx_fstatat_allow_noent() portingColin Walters2017-09-191-21/+0
| | | | | | | The new API is definitely nicer. Closes: #1180 Approved by: jlebon
* tree-wide: Use helpers for unlinkat()Colin Walters2017-09-071-0/+1
| | | | | | | | | | | | We have `ot_ensure_unlinked_at()` for the "ignore ENOENT" case, and `glnx_unlinkat()` otherwise. Port all in-tree callers to one or the other as appropriate. Just noticed an unprefixed error in the refs case and decided to do a tree-wide check. Closes: #1142 Approved by: jlebon
* libutil: Add a helper for O_TMPFILE + mmap()Colin Walters2017-06-291-0/+27
| | | | | | | | | | | | | 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
* Port to GLnxTmpfileColin Walters2017-06-271-57/+1
| | | | | | | | | | | | | | | | | | | | | 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
* lib/util: Some style conversionColin Walters2017-05-301-47/+12
| | | | | | | | I saw a few instances of `glnx_set_error_from_errno() + return FALSE`, and fixed them and did a bit of style conversion. Closes: #895 Approved by: jlebon
* Add stub for new libglnx tmpfile API, port simpler callers to itColin Walters2017-05-231-0/+55
| | | | | | | | | | | | | It's hard right now to do a full port to the new libglnx tmpfile API since there are complex cases in the commit path which deal with symlinks as well. Let's make things more gradual by introducing the important part (struct with autocleanup) here in libotutil, port what we can. This will make a future complete port easier. Closes: #871 Approved by: jlebon
* lib: Add "open dfd iter handling noent" helper, port tree-wideColin Walters2017-05-161-0/+25
| | | | | | | | | 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
* lib/util: Delete some leftover pre-libglnx directory opening functionsColin Walters2017-04-251-26/+0
| | | | | | | These were migrated into libglnx; port the few callers to use that. Closes: #808 Approved by: jlebon
* repo: Optimize bare-user content object reads a bitColin Walters2017-04-191-66/+0
| | | | | | | | | | | | | | | | | | | `perf record ostree checkout ...` for a bare-user repo was telling me we were spending a good 13% of our time in the depchain of `ot_lgexattrat()`. The problem here is that traversing the `/proc` path turns out to be somewhat expensive - there are LSM (SELinux) checks, etc. For regular files, opening and just getting the xattr, then closing is still quite cheap. For symlinks, we'll always need to open anyways. This appears to shave about ~0.1 seconds off of a checkout of `fedora-atomic/25/x86_64/docker-host` on my workstation. Oh, and this was the last user of `ot_lgexattrat()` so we can kill it, which is nice - the xattr code should really live in libglnx. Closes: #796 Approved by: jlebon
* sysroot/deploy: Some cleanup to decl-after-stmt/return FALSE styleColin Walters2017-03-201-0/+34
| | | | | | | | And fd-relative. I also introduced some helpers here which I'll use later in more invasive patches. Closes: #742 Approved by: jlebon
* Final excision of libgsystem dependencyColin Walters2016-08-091-1/+0
| | | | | | | | | | | | | | 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
* lib: Add a helper for mmap->bytes with openat(), use it in repoColin Walters2016-06-091-0/+21
| | | | | | | | | 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
* libglnx porting: Use glnx_set_error_from_errnoColin Walters2016-03-231-6/+6
| | | | | | | | | :warning: There is a notable spiked pit trap here around `posix_fallocate()` and `errno`. This has bit other projects, see e.g. https://github.com/systemd/systemd/commit/7bb87460e691d30c1a7fd23a1a8240776957e05f Otherwise the port was straightforward.
* libotutil: new function ot_openat_ignore_enoentGiuseppe Scrivano2016-03-151-0/+25
| | | | | | Refactor some common code Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
* ot-fs-utils: remove empty line at EOFGiuseppe Scrivano2015-05-071-1/+0
| | | | Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
* Use g_autofree instead of gs_freeMatthew Barnes2015-05-061-2/+2
|
* Teach fsck about partial commitsColin Walters2015-05-061-0/+18
| | | | | | | | | | | | | | | | | | | An OSTree user noticed that `ostree fsck` would produce `missing object` errors in the case of interrupted pulls. It's possible to do e.g. `ostree pull --subpath=/usr/share/rpm ...`, which gets you just that portion of the commit. The use case for this was being able to see what changes would appear in an update before actually downloading all of it. (I think this would be better covered by static deltas, but those aren't final yet, and `--subpath` predates it) Further, `.commitpartial` is used as a successor to the `transaction` symlink for more precise knowledge in the case where a pull was interrupted that we needed to resume scanning. So it makes sense for `ostree fsck` to be aware of it.
* build: Use glibc's xattr support instead of requiring libattrDaniel Svensson2015-04-011-1/+1
| | | | | | Fixes the build on Debian, and is one library less. Closes: #78
* Add internal ot_openat_read_stream() helperColin Walters2015-01-071-0/+45
| | | | We had two cases which were creating an input stream using openat().
* Use *at() functions for native filesystem commitsColin Walters2015-01-061-0/+28
| | | | | | | | | | | This is just an efficiency optimization. We're getting fairly close to all of the hot code paths using `*at()`. Note that we end up maintaining a half-duplicate code path set here, because we still need to support commits from an arbitrary GFile *, which in a possible common case is an OSTree commit. I think it's worth it though.
* Port to libgsystem errno API, hard depend on 2014.3Colin Walters2015-01-041-4/+4
| | | | This is long overdue to make it to libgsystem. Update our dependency.
* Add ot_lgetxattrat and ot_lsetxattrat utilsAlexander Larsson2014-12-081-0/+67
| | | | | | | | | These are implementation of the missing corresponding syscalls that are done with the /proc/self/fd mechanism described at: https://mail.gnome.org/archives/ostree-list/2014-February/msg00017.html https://bugzilla.gnome.org/show_bug.cgi?id=741125
* Extract opendirat() helper function into libotutilColin Walters2014-09-161-0/+50
We were duplicating the code to do an opendirat() in a few places.