summaryrefslogtreecommitdiff
path: root/src/libotutil/ot-fs-utils.h
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: Run clang-formatColin Walters2023-05-021-51/+27
| | | | | 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/+7
| | | | Prep for future patch.
* 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/+7
| | | | | | | 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
* Deduplicate and fix up our use of mmap()Colin Walters2017-10-041-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-5/+0
| | | | | | | The new API is definitely nicer. Closes: #1180 Approved by: jlebon
* tree-wide: Remove trailing semicolon from autoptr declarationsColin Walters2017-08-071-1/+1
| | | | | | | It confuses `g-ir-scanner`, and isn't necessary. Closes: #1056 Approved by: pwithnall
* libutil: Add a helper for O_TMPFILE + mmap()Colin Walters2017-06-291-0/+5
| | | | | | | | | | | | | 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-26/+0
| | | | | | | | | | | | | | | | | | | | | 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: Hoist unlinkat() cleanup API to fsutil, use in pullColin Walters2017-06-261-0/+28
| | | | | | | | | | | | | | | | The pull code also could make use of this in both the metadata and content paths. I changed it to own the tempfile malloc (just like `GLnxTmpFile`), since there's no reason to have different lifetimes for the filename and the file, and that way we only have one variable rather than two. The content path turns out to be a special case though, where at least for mirroring archives, we directly pass the file *path* down into `_ostree_repo_commit_loose_final()`. This is prep for `GLnxTmpFile` porting. Closes: #957 Approved by: jlebon
* Add stub for new libglnx tmpfile API, port simpler callers to itColin Walters2017-05-231-0/+24
| | | | | | | | | | | | | 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/+7
| | | | | | | | | 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-7/+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-13/+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/+7
| | | | | | | | And fd-relative. I also introduced some helpers here which I'll use later in more invasive patches. Closes: #742 Approved by: jlebon
* lib: Add a helper for mmap->bytes with openat(), use it in repoColin Walters2016-06-091-0/+4
| | | | | | | | | 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
* libotutil: new function ot_openat_ignore_enoentGiuseppe Scrivano2016-03-151-0/+5
| | | | | | Refactor some common code Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
* Teach fsck about partial commitsColin Walters2015-05-061-0/+4
| | | | | | | | | | | | | | | | | | | 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.
* syntax-check: Remove empty lines at the end of fileGiuseppe Scrivano2015-02-021-1/+0
| | | | Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
* Add internal ot_openat_read_stream() helperColin Walters2015-01-071-0/+7
| | | | We had two cases which were creating an input stream using openat().
* Use *at() functions for native filesystem commitsColin Walters2015-01-061-0/+6
| | | | | | | | | | | 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.
* Add ot_lgetxattrat and ot_lsetxattrat utilsAlexander Larsson2014-12-081-0/+13
| | | | | | | | | 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/+35
We were duplicating the code to do an opendirat() in a few places.