Commit Graph

1000 Commits (5d796b567819ce91740fcdea7cbafecbda65d8f3)

Author SHA1 Message Date
Timo Teräs b45415b109 add: fix virtual package id generation
Fixes 37fbafcd by adding more input to the hash than just second
grained time stamp - collisions would happen when running apk
scripted.

For virtual package the hash works only as unique identifier, so
try to add elements that should make it unique in most cases.

Fixes #10648
2019-07-02 15:27:57 +03:00
Timo Teräs 366d0ee371 print usage and exit with error on invalid arguments
Add also some testing to make sure help, long help and handling
of invalid arguments works as expected.

Based on pull request #19 originally by Laurent Arnoud (@spk).
2019-06-05 09:56:13 +03:00
Timo Teräs c3a93a4aa5 fix all applets to return -ENOTSUP if it's unrecognized
The return -1 seems to have been left over from earlier code, and
could have been treated as -EPERM. This helps to fix the other command
line handling that potentially require changing.
2019-06-05 09:32:29 +03:00
Timo Teräs b0be9f610c solver: fix common dependency merging to inherit pinning and flags
Notably this fixes occasional issues when doing upgrade with multiple
versions of same packages. Without this the upgrade flag is not always
propagated properly down the dependency chain.
2019-06-05 08:51:00 +03:00
Timo Teräs 1c47f37443 use fixed system time in test mode to have fixed test output
fixes test suite regression from previous commit
2019-06-03 16:19:17 +03:00
Timo Teräs 37fbafcd92 add: make virtual packages upgradeable (ref #9957)
Originally the virtual packages could have dependencies added to it.
However, commit b06e3b99 broke this behaviour to fix error reporting.
The root cause however was that the virtual depedency package was not
properly versioned.

This fixes to use current date/time as the package version, and
constructs the "faked" package hash from it. This effectively makes
"add -t virtpkg deps.." replace the dependencies which should be the
desired behaviour for "abuild deps".

'world' dependency to the generated virtual package is also now
versioned to make sure it get's upgraded.
2019-06-03 09:33:43 +03:00
Ian Douglas Scott d901444ec9 Fix compile with glibc 2019-05-28 13:07:50 +03:00
A. Wilcox 84941a5967 list: Detect orphaned packages correctly
BIT(1) corresponds with decimal 2, which is the first available repository.

Before this fix, `apk list -O` would list every package installed from the
first available repository, which is the 'system' repository on most Adélie
Linux computers.

After this fix, `apk list -O` correctly lists only the packages which are
no longer available.
2019-05-01 18:56:43 +03:00
Timo Teräs 44daf80873 fix strncpy bounds errors
error: 'strncpy' specified bound 4096 equals destination size [-Werror=stringop-truncation]

Based on patch by Elan Ruusamäe <glen@delfi.ee>
2019-02-13 16:05:27 +02:00
Elan Ruusamäe 86922d1a34 include sys/sysmacros.h for makedev definition 2019-02-13 15:32:22 +02:00
Natanael Copa 947baeea18 fetch: fix error message for --recursive
Give error message for `apk fetch --recursive missing`
2019-01-10 09:29:35 +01:00
Timo Teräs bd8967bcb7 Revert "move --simulate to global options"
This reverts commit 358f703b76.

The short option -s conflicts info --size and fetch --stdout.
Revert this for now.
2018-11-15 12:03:51 +02:00
Timo Teräs 0565e9bb05 fix orphan package handling for certain provides cases 2018-11-12 15:00:14 +02:00
Timo Teräs 47570f80e9 prefer selecting packages by their primary name 2018-11-12 14:16:36 +02:00
Timo Teräs a86c8ed082 fix package preference based on it's conflicts in --latest mode
remove also redundant pkg_selectable check in repair mode.
2018-11-12 13:20:14 +02:00
Timo Teräs c3fe426da0 fix short option string to be nil terminated 2018-11-02 17:42:46 +02:00
Timo Teräs b06e3b991d fix error reporting for virtual package addition
Move addition of virtual package after the dependencies have been parsed
as then the reverse dependency structers can be populated correctly.
2018-11-02 17:41:34 +02:00
Timo Teräs 31338affc2 don't report virtual packages as masked 2018-11-02 17:12:20 +02:00
Timo Teräs 22abda2af4 inhibit printing same 'required by' dependency multiple times
this would happen if same package matched multiple times due to
multiple provided names.
2018-11-02 15:40:53 +02:00
Timo Teräs 59271f8c13 print: don't print spurious newlines 2018-11-02 15:40:45 +02:00
Timo Teräs f38d1f74af fix xattr hash to be sha1
The hash type was accidentally changed in previous commit. Currently
csum->data cannot hold longer hash, so fix the hash.
2018-10-30 18:26:10 +02:00
Timo Teräs beab8545eb add support for openssl 1.1 2018-10-26 08:22:08 +03:00
Timo Teräs 40ffdfe623 apk: fix all_options array size off-by-one
merge_options() will write one more entry to the options table
which is the end-of-table indicator. Allocate memory for it too.
valgrind did not pick it up due to being in stack; changing alloca
to malloc would make valgrind notice the issue too.

Reported-by: Mobile Stream <info@mobile-stream.com>
2018-10-05 09:45:02 +03:00
Timo Teräs 0e3be0fd4a cache: support --latest and --upgrade to affect download policy 2018-09-25 13:07:42 +03:00
Timo Teräs 358f703b76 move --simulate to global options
there are several applets that support simulation but are not
committing changes to database
2018-09-25 13:06:40 +03:00
Timo Teräs 4c6fc81474 add: add --latest flag to help analyze why upgrade fails 2018-09-11 10:34:14 +03:00
Timo Teräs 6484ed9849 rework unpacking of packages and harden package file format requirements
A crafted .apk file could to trick apk writing unverified data to
an unexpected file during temporary file creation due to bugs in handling
long link target name and the way a regular file is extracted.

Several hardening steps are implemented to avoid this:
 - the temporary file is now always first unlinked (apk thus reserved
   all filenames .apk.* to be it's working files)
 - the temporary file is after that created with O_EXCL to avoid races
 - the temporary file is no longer directly the archive entry name
   and thus directly controlled by potentially untrusted data
 - long file names and link target names are now rejected
 - hard link targets are now more rigorously checked
 - various additional checks added for the extraction process to
   error out early in case of malformed (or old legacy) file

Reported-by: Max Justicz <max@justi.cz>
2018-09-10 10:59:39 +03:00
Timo Teräs 7b654e1254 apk: sanitize return value
Most applets return whatever apk_solver_commit() returns. It is the
number of errors found (or negative for hard error). Sanitize the
error value to not give false success exit code in the unlikely case
of errors % 256 == 0.

Reported-by: Max Justicz <max@justi.cz>
2018-09-05 10:21:22 +03:00
Natanael Copa 13c534db77 prevent automatic repository index update with --no-network
We should not update repository index when --no-network is specified.

ref #9126
2018-08-21 12:25:37 +00:00
Jesse Young 1d55b9488f archive: enable FIFO extraction 2018-08-14 23:27:08 +03:00
Timo Teräs e1a05c74cb prevent automatic repository index update for 'apk del'
ref #9063
2018-07-18 13:29:13 +03:00
Jussi Kukkonen d609ef3c6c Invalidate id cache after script execution
It's common for a pre-install script to do something like
    addgroup -S group 2>/dev/null
When apk installs files after this, it sets the owner/group based on id cache
but currently the id cache is stale and doesn't contain the new group at that
point: instead the file will be installed with gid that the build host
happened to have for that group -- on target this might mean a non-existing
group or a completely different group.

We can't know if the script really did modify id cache contents so make sure
to reset the id cache on every script execution.
2018-07-02 10:06:53 -05:00
Sören Tempel 5c4b90dfd4 list: fix segmentation fault with virtual packages
Virtual packages have the origin pointer set to NULL. Trying to print it
using the BLOB_PRINTF macros causes a segmentation fault.

Inspired by the `print_origin_name` function from `src/search.c` this
commit attempts to fix it by checking whether `pkg->origin` is NULL
before attempting to print it. If it is NULL the pkg name is printed
instead.

Since printing the pkg name requires a different format string this
commit splits the printf call for printing the package line into
multiple ones. The output format shouldn't have changed at all though.
2018-07-02 08:52:22 -05:00
Timo Teräs 7561a501b4 fetch: ignore conflicts when solving --recursive fetches 2018-06-14 20:40:05 +03:00
Natanael Copa 611172b7a9 fetch: include install_if dependencies with --recursive
Run apk_solver_solve once with all args as dependencies instead of
running apk_solver_solve for each arg. This is neccesary so the
install_if calculation is done correctly.
2018-06-14 18:55:06 +03:00
Edan Bedrik dafbb1c4f4 url: return relevant error value from apk_istream_fetch 2018-05-08 22:44:23 +03:00
Timo Teräs 258519b1cd db: fix refreshing index if time is zero
During netboot on systems without RTC, time() will be near zero,
and the index fill not exist. Thus the plain test of st.st_mtime
against system time failed. Verify that fstatat() succeeds.
2018-04-05 09:57:17 +03:00
William Pitcock 0dcbd933c8 solver: allow names with only one provider to be autoselected regardless of priority 2018-02-21 15:35:53 +00:00
William Pitcock a5d9e2eb0a add: child dependencies can never take a pinning, give a useful error 2018-02-20 22:22:02 +00:00
William Pitcock dc7298122e apk: in test mode, always exit 0 (so the test harness doesn't stop running tests) 2018-02-20 22:21:27 +00:00
William Pitcock d52285c9aa list: use `apk list --providers` to search virtual providers instead of enabling virtuals by default 2018-01-29 03:17:07 +00:00
William Pitcock d379edd5bf search: remove from APK_COMMAND_GROUP_QUERY
list does everything search does and more
2018-01-29 03:03:15 +00:00
William Pitcock 3334624cd1 list: add option to match against real names only instead of providers 2018-01-29 02:59:39 +00:00
William Pitcock 368b8b6725 list: add --depends option for searching based on rdepends 2018-01-29 02:55:29 +00:00
William Pitcock 8fcb57bf0f list: refactor package dumping vs package filtering 2018-01-29 02:39:39 +00:00
William Pitcock fff8bfa588 list: new applet
The list applet provides a convenient way of inspecting both the available
and installed package databases by listing their contents.  In some ways,
it is similar to `apk search` but is considered to be a superset of
`apk search` functionality.

A few `apk list` criterion are not yet ready though, such as `apk list --depends`
which searches by runtime dependency (replacing `apk info --rdepends`).
2018-01-28 23:55:29 +00:00
William Pitcock 5da4dec2a2 apk: make --help --verbose actually work. 2018-01-09 17:07:22 +00:00
William Pitcock 182bfa0a9f apk: properly error out if an unknown command is requested 2018-01-09 17:07:22 +00:00
William Pitcock 1777040cc5 apk: commit options help text: fix typo concerning diskless boot 2018-01-09 17:07:22 +00:00
William Pitcock abf7c2838b apk: usage: cleanup help text when no applet is selected 2018-01-09 17:07:13 +00:00
Timo Teräs 118f29c895 fix --update-cache help to reflect reality
Internally the value is in seconds, but on command line it's in
minutes.
2018-01-09 10:32:03 +02:00
Timo Teräs 5f7dcadc69 auto-update index only when database is opened for writing 2018-01-08 11:56:48 +02:00
Timo Teräs d0a25d670a increase libfetch connection pool limits slightly 2018-01-04 11:08:30 +02:00
Timo Teräs 8a28c6d0d4 enable automatic update of indexes controlled by --cache-max-age
This modifies apk cache for indexes to be automatically refreshed
periodically without explicit 'update' or '--update-cache' usage.

The default is to do if-modified-since request if the local copy
is older than 4 hours. This age can be changed with --cache-max-age.
Using --update-cache will change this age to 60 seconds to make
sure the cached copy is relatively new. The small age is in order
to try to avoid downloading indexes second time when apk-tools is
upgraded and apk re-execs after self-upgrade.

Accordingly using explicitly 'apk update' will now enforce
--force-refresh and request the very latest index by requesting
any potential http proxy to do refresh too.
2018-01-04 10:56:09 +02:00
Timo Teräs 2da67940d5 url: add "Cache-Control: no-cache" header with --force-refresh
fixes #8161
2018-01-03 16:00:38 +02:00
Timo Teräs 039ff3bd46 split --force to several --force-[type] options
This unloads --force as several of the things are really not wanted
together. E.g. --force-refresh is a lot different from --force-broken-world
and doing --force to get the other might introduce unwanted behaviour.

--force is still kept for backwards compatibility and it enables
most things --force was used for.
2018-01-03 16:00:38 +02:00
Henrik Riomar e0eff8742f add new umbrella flag --initramfs-diskless-boot
This flag enables a group of options used during initramfs tmpfs
initial install.
2018-01-03 14:21:40 +02:00
Henrik Riomar 23cb104775 add new flag --no-commit-hooks
This flag skips running hook scripts

This flag *must* be used during initramfs tmpfs initial install.
The reason that this new flag is needed is that the hooks will currently
always fail as musl and /bin/sh is missing at this stage on diskless.
2018-01-03 14:20:58 +02:00
Timo Teräs b0fcc56f22 db: fix triggers to report deleted directories
This change just changes to keep deleted directory items in
the hash with ref count zero and modified flag set. Those entries
are reused when needed. The side effect is that fire_triggers()
will now see those removed direcotries and reports them. Other
enumerators of the directories hash are protected to skip removed
directories when appropriate.
2018-01-03 09:31:10 +02:00
Timo Teräs 8ee79c72b2 apk, del: fix few memory leaks
This fixes couple of valgrind reported leaks - though they are
non-important since the leak happens on "exit" only and kernel
frees it anyway.
2018-01-03 09:30:12 +02:00
Timo Teräs 667cb6bca7 commit: properly analyze packages with provides="$pkgname" 2018-01-02 15:45:21 +02:00
Nils Andreas Svee ac1681247f fix typo in MIPS byte-order apk_defines.h 2017-12-15 10:08:36 +02:00
Timo Teräs 8e7fd3e06f solver: fix potential install_if processing failure, fixes #8237
In discovery phase, there was logic to not process packages
multiple times. However, that logic failed to account the package's
depth and install_if state for the name being processed. This
caused install_if processing failure in certain topologies of the
dependency graph. Adds also a test case that should catch this
issue reliably.
2017-12-12 15:16:52 +02:00
Nils Andreas Svee 0700e8318f add detection of mips archs 2017-12-11 09:02:50 +02:00
Timo Teräs 97d8aab0c2 fetch: print additional error diagnostics in verbose mode 2017-11-28 14:25:38 +00:00
William Pitcock 20ae27c1da solver: prefer highest requirer count above installed status
This ensures a swap is emitted when replacing a virtual with
apk add.
2017-11-02 17:15:00 +00:00
William Pitcock 6aabb96c20 solver: fix dbg_printf() call in select_package() 2017-11-02 17:14:18 +00:00
William Pitcock 0a17a648db solver: only select a default if there is at least one provider with a declared provider_priority 2017-11-02 16:31:50 +00:00
William Pitcock 9165aa3894 solver: instead of tracking selected packages, score by requirer count for tiebreaking 2017-11-02 16:24:09 +00:00
William Pitcock f18c708183 solver: implement support for choosing default virtuals
By introducing a new package metadata field, `provider_priority`
(index letter `k`), we can specify default packages to satisfy a
virtual.

If a user wishes to select an alternative provider for the virtual,
a changeset swapping the default provider for the selected provider
will be generated by the dependency resolver.
2017-11-02 03:08:24 +00:00
Timo Teräs e03716ff3b solver: consider virtual provides to exclude non-provides transitively
this fixes package selection when a 'real' package exists, but would
need to be provided by another package with 'virtual provides'.

In current package database this can happen with postgresql which is
also provided by postgresql-bdr. Normally postgresql would be satisfied
by postgresql, but if any package depends on postgresql-bdr and there's
no versioned dependency on postgresql this will help apk figure out
that postgresql-bdr should be used.
2017-10-27 15:20:03 +03:00
Timo Teräs 2f3c842049 io: fix skip and splice to detect unexpected end-of-file 2017-10-12 13:35:46 +03:00
Timo Teräs 97e4d0531f db: handle default root correctly for /proc
dbopts->root may be null; use db->root instead

fixes #7162
2017-10-10 11:39:38 +03:00
Timo Teräs 86436fce2f build and use bundled libfetch natively 2017-10-05 16:59:14 +03:00
Timo Teräs 8f0938a056 package: remove package script after use (fixes #7974)
this is a regression introduced in commit 349c61c9
("add support for pre and post commit hooks")
2017-10-04 16:56:07 +03:00
Damiano Albani 806a476190 info: fix typo in help 2017-09-27 18:01:07 +03:00
Timo Teräs e6e90a6463 commit: proper singular/plural for 'error(s)' in commit message
based on github pull request #5
2017-08-23 09:03:35 +03:00
Dmitry Golovin 16336ba265 fix comparison of unsigned expression < 0 is always false
found by clang
2017-08-23 08:56:44 +03:00
Dmitry Golovin c099018e01 use labs istead of abs with long argument 2017-08-23 08:54:00 +03:00
A. Wilcox 8221be3569 index: Only rewrite arch if no error is encountered 2017-07-29 01:57:55 +00:00
A. Wilcox 13747fab83 database: include POSIX header for ST_* defines 2017-07-29 01:57:34 +00:00
Timo Teräs 677d3240a8 tar: use standard header prefix
APKs have been created with GNU tar so far, which uses the
GNU extensions for long names. In order to increase portability
support the standard header's 'prefix' portion in case
the GNU extensions are not present.
2017-06-26 14:29:29 +03:00
Timo Teräs 51ec463e9d db: fix current directory instance caching in tar extraction
Depending how the directory entries are ordered, the cached dir
instance might not have been updated correctly. This has not been
a problem as the entries have been ordered, but is now triggered
on ppc.
2017-06-26 10:59:37 +03:00
A. Wilcox 17dd532e42 database: mark error on renameat failure 2017-06-26 10:32:38 +03:00
Timo Teräs 4d9c0c39b0 io: make io vtables const struct, and add accessors for them
This reduces function pointers in heap, and unifies how the
io functions are called.
2017-06-23 10:07:44 +03:00
Timo Teräs ca9d476ba3 archive: validate reading of pax and gnu long filename extensions
Detect properly if the file stream gets an error during these
read operations.

Reported-by: Ariel Zelivansky from Twistlock
2017-06-23 10:07:44 +03:00
Timo Teräs 6b9a07d1ad archive: fix incorrect bounds checking for memory allocation
The value from tar header is unsigned int; keep it casted to
unsigned int and size_t instead of (signed) int, otherwise
the comparisons fail to do their job properly. Additionally check
entry.size against SSIZE_MAX so the rounding up later on is
guaranteed to not overflow.

Fixes CVE-2017-9669 and CVE-2017-9671.
Reported-by: Ariel Zelivansky from Twistlock
2017-06-23 10:07:44 +03:00
William Pitcock 5d439c4739 Revert "version: consider pkg-rX and pkg to be the same version"
This reverts commit ee5ce7284a.
2017-06-23 06:59:13 +00:00
William Pitcock 17f8c2edec print: oh dear, i have reworked the progress bar again
- rework the progress bar a little bit, basically removing the [ and ] to give a more
  modern aesthetic.

- if utf-8 locale is enabled, use unicode codepoint 0x2588 instead of # to give the
  progress bar a nicer look.

- if APK_PROGRESS_CHAR environment variable is defined, use the character defined there
  for the progress bar.
2017-06-01 05:25:56 +00:00
William Pitcock 40aee5f1d0 apk_defines: implement mulmod() 2017-06-01 04:24:15 +00:00
William Pitcock 9325eb721d index: fix unsatisfied dependencies warning (maybe vs may be) 2017-05-28 05:41:36 +00:00
William Pitcock 3eb0a0aaa4 manifest: fix up help entry 2017-05-28 01:09:42 +00:00
William Pitcock 693b4bcdb0 version: add support for fuzzy version matching
This is useful for requirements such as: python3=~3.6, which would match python3-3.6.[0-9].
This implementation should in theory be backwards compatible with the implementation in Adelie.
2017-05-27 21:49:53 +00:00
A. Wilcox ee5ce7284a version: consider pkg-rX and pkg to be the same version 2017-05-27 21:34:05 +00:00
William Pitcock 18f7aa9e44 manifest: add file support as well as apkdb support 2017-05-27 21:19:41 +00:00
William Pitcock 46c2693468 manifest: dump checksum type too 2017-05-27 20:55:31 +00:00
Timo Teräs ede5165833 db: fix regression preventing remounting apk cache r/w
Introduced in commit c0f2d88f34.
fstatfs is needed to inspect the mount flags.
2017-05-25 18:06:27 +03:00
William Pitcock b4b95e9ae7 manifest: new applet which dumps checksums in sha1sum format for a package 2017-05-20 06:19:00 +00:00
Kaarle Ritvanen c072c18d6e close database on SIGINT
cleans up procfs mount
2017-04-28 16:19:01 +03:00
Kaarle Ritvanen 5c349335c7 db: separate init from open 2017-04-28 13:28:32 +03:00