Commit Graph

45 Commits (cute-signatures)

Author SHA1 Message Date
Timo Teräs 6df225eac3 mkpkg, adb: validate version and dependency format
Fail if the package or dependency version format is not valid.

fixes #10807
2022-02-01 14:47:27 +02:00
Timo Teräs a662047e2c print: improve indented printing api
- make sure all commit errors go to stderr
- make it a bit more api like
2021-12-27 14:34:01 +02:00
Ariadne Conill 6df9f0ed59 defines: provide APKE_REMOTE_IO as portable alternative to EREMOTEIO 2021-12-14 18:48:18 +00:00
Ariadne Conill f4f7796ccc everywhere: use stdlib.h for malloc(3) definition, not GNU-specific malloc.h
musl implements support for malloc.h, but it is only a stub.  we do not use
any of the GNU-specific malloc interfaces, so just use POSIX stdlib.h instead.

ref #10794
2021-12-14 16:23:29 +00:00
Timo Teräs a673653200 database: implement uvol support
by adding an abstraction layer to the file system
2021-11-09 21:50:11 +02:00
Timo Teräs 9c843e4ecd Refactor .apk extraction code
This moves and isolates the tar code to tar.c. And the actual
file extraction to disk is moved to extract.c.

A new API is introduced and used for v2 file extraction. This
essentially moves and isolates the apk_sign_ctx_* beast into
extract_v2.c and offers a saner interface to handling packages.

A place holder is added for v3 extraction.
2021-07-27 14:09:38 +03:00
Timo Teräs 3d203e8f5f db: allow read-only operations without cache
fixes #10748
2021-07-23 14:39:38 +03:00
Timo Teräs e6b7fa49ce adb: add a small adb blob header with versions and root object 2021-07-22 16:14:49 +03:00
Timo Teräs 7af34db6cf adb: support seamless de/compression of adb files
Add compression header of adb files. Support uncompressed and
deflate compression at this time.
2021-07-22 15:30:08 +03:00
Timo Teräs 22281fb4b5 print: handle write() errors in apk_print_progress() 2021-06-21 12:55:32 +03:00
Timo Teräs d89c219173 reduce misuse of error codes from errno.h 2021-06-19 16:10:13 +03:00
Timo Teräs 1456296b43 add adbgen applet to generate databases from it's text dump 2021-06-02 22:35:58 +03:00
Sören Tempel 1b954e4120 Fix segfault in log_internal if prefix is APK_OUT_LOG_ONLY
This commit fixes a regression which was introduced in changeset
646c834492. If apk_out_fmt() is called
while out->log is set and prefix is set to APK_OUT_LOG_ONLY, then
apk_out_fmt() would pass this prefix to log_internal() which would, in
turn, attempt to write it to standard out using fprintf().
Unfortunately, doing so wont work as intended if prefix is ((char*)-1)
(i.e. APK_OUT_LOG_ONLY) and will cause a segmentation fault instead.

This commit fixes this segmentation fault by not printing the prefix in
log_internal() if it is either NULL or APK_OUT_LOG_ONLY.
2021-04-02 12:22:25 +02:00
Drew DeVault 646c834492 Log to /var/log/apk.log
This adds a log file at /var/log/apk.log. On each run, apk's version
information and the current date & time are written to this file,
followed by any normal apk output.
2021-03-19 12:26:15 +00:00
Timo Teräs 1a4f2e94dd db: consider control characters in filename as malicious
Especially a newline can produce havoc in the database file as
the filename is written there as-is. This hardenes the extraction
to consider any control character as malicious. Additional
hardening is added to database loading to better detect corrupt
state and return proper error code about it.

Reported-by: Luca Weiss <luca@z3ntu.xyz>
2021-02-04 22:30:26 +02:00
Timo Teräs 354713d2f7 rename apk_db_options to apk_ctx, rework logging
makes apk_verbosity non-global

fixes #10682
2020-10-09 16:09:19 +03:00
Timo Teräs 7a7eca8670 make apk_flags non-global, make progress printing state non-global
ref #10682
2020-10-09 16:09:19 +03:00
Timo Teräs efe0c4afec adb: introduce apk-tools database format, and few applets
This is a flat buffers inspired format that allows fast
mmaped access to the data with low overhead, signature support
and relatively good forward support.
2020-10-09 16:09:19 +03:00
Timo Teräs 6cedfe27ac db: mask password component of printed URLs
fixes #10710
2020-10-05 12:58:46 +03:00
TBK 5d796b5678 use SPDX-License-Identifier in source files 2020-05-07 10:45:42 +03:00
Antoine Fontaine e8522411c1 lower min-width to 25 columns
Some screen size are quite small. For example, the default phosh
terminal is less than 50 character wide on Pinephone. This lowers the minimum
loading bar size to 25 characters.

For comparison, 25 character wide is just as wide as "apk add firefox
linux-lts" without the quotes.

Here's a bad picture to illustrate the result
gitlab.alpine.org/uploads/48c20f746fbf685b62b6bd73585ecbf2/pinephone-phosh.png
2020-03-21 17:41:49 +02:00
Sören Tempel a6039e38a4 Humanize size output of `apk info`
This commits adds a function for receiving the closet byte unit and the
size in that unit for a given size_t. The function doesn't return a
string since dynamic memory allocation (or a static buffer) would be
required to implement this properly.

Discussion: It might be useful to add a command line flag for disabling
this behaviour in order to retain compatibility with the previous apk
info output format.
2020-01-05 23:26:50 +02:00
Timo Teräs 59271f8c13 print: don't print spurious newlines 2018-11-02 15:40:45 +02: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
Timo Teräs 027df02dc2 print: handle mixing stdout and stderr printing
Fixes regression from commit 5ba27c90 which caused stdio
buffering issues now that output is split to stderr/stdout.

See also commit 51737872 for some of the history.

Fixes #7107
2017-04-26 09:34:32 +03:00
William Pitcock a841d6b259 print: don't shadow log() 2017-04-24 23:53:26 +00:00
Shiz 5ba27c9000 print: print warnings and errors to stderr 2017-04-24 22:42:29 +00:00
Avi Halachmi (:avih) 515f31eb52 progress: shorten bar to prevent newlines on some terminals
On some (probably buggy) terminals, printing up to the rightmost column
may end up with the terminal issueing a newline (probably due to putting
the cursor at the next char -> new line).

Some other progress bars avoid it by not reaching the rightmost column.

Shorten the bar width from term-width - 7 to -8 (the 7 are "xxx% []").
2017-03-29 08:14:39 +03:00
Timo Teräs fd98e9c718 modifications for the previous commit in error message handling
forgot to --amend my changes
2015-04-24 09:32:22 +03:00
Alex Dowad 74dc8e232f print.c: provide more detailed error messages if retrieving a package fails
fetch_maperror() translates error codes returned by libfetch to our error
codes. Handle those in apk_error_str(), returning error messages which
advise the user of the most likely fix.

A custom error code, EAPKSTALEINDEX, has been added for cases where
retrieving a package fails due to a HTTP error 404 or similar.

[TimoT: add also EAPKBADURL, as well as organize a bit better where the
EAPKSTALEINDEX is generated]
2015-04-22 20:08:16 +03:00
Natanael Copa 1f8b793471 print: flush on apk_log
Makes it more useful whith pipes.
2013-12-05 10:58:23 +01:00
Timo Teräs 5173787218 print: use stdout instead of stderr for logging and progress
stdout is the proper place for it. this also fixes the progress
bar in musl, which seems to not support using line buffering for
stderr.
2013-10-11 14:52:34 +03:00
Natanael Copa adc5b0b161 print: move progress bar update logic to apk_print_progress
- let the apk_print functions deal with the forced print itself. We
  avoid that the callbacks need to deal with the force flag. We can
  also get rid of the APK_PRINT_PROGRESS_* defines.

- let the reader of --progress-fd decide how often things are updated
  rather than having a fixed granularity off 1/100 (percent)

- avoid detect screen size and percent/bar calculations in case the
  --no-progress was given

- track satistics for both the ascii bar and percent info and update bar
  only if either percent or bar changes. This makes the bar go smoother
  when width is wider than 100 chars and it makes the percent counter
  go smooth when screen width is less thann 100 chars. It also
  simplifies the callbacks as they no longer need to deal with update
  granularity.
2013-06-19 10:00:31 +00:00
Natanael Copa 0e9d67aea8 print: percent arg for process_fd is integer
With commit 0a13141889 the percent
variable became an integer instead of size_t. We fix the format
modifier accordingly.
2013-06-19 08:07:37 +02:00
Timo Teräs 0a13141889 print: move progress printing to common functions 2013-06-17 16:47:49 +03:00
Timo Teräs 9d10037807 db: refactor repository file construction
Fixes also 'fetch' applet to prefer copying/linking to files from
cache if possible.
2013-06-17 14:38:27 +03:00
Timo Teräs e51232e710 errors: rewrite the logic how errors are reported
Instead of the dependency oriented logic, switch to print them
for each package or name needed. Might give a bit more readable
errors now. There's still few corner cases that proper error is
not output, which are cought by the test cases.
2013-06-13 18:22:00 +03:00
Timo Teräs dd923ed065 print: minimum screen width of 50 2012-02-10 15:20:57 +02:00
Timo Teräs 1817b0a3c3 all: update copyright year statement 2011-09-13 11:53:01 +03:00
Timo Teräs bfd53b59d2 print: minor cleanup to indented writer 2011-09-09 20:06:10 +03:00
Timo Teräs 6b24f3c399 apk: improve indented printing
* fixup the help messages to align up properly
 * refresh screen width on SIGWINCH
2011-07-22 12:08:35 +03:00
Timo Teräs 972bec3210 various: use 'atoms' for certain package field and misc fixes
- implement a hash table for commonly shared fields such as
   license, version and architecture
 - use macroes to print blobs or pkgname-pkgver strings
 - fix some old cruft
2010-12-14 19:51:16 +02:00
Timo Teräs d92df52079 io: enhance istream/bstreams with pipe to forked child
* prunes the child pid to avoid zombies
 * handles the errors so e.g. file-not-found is reported properly
2010-12-09 10:47:09 +02:00
Natanael Copa 11925542d8 print: clean up after copy-paste 2010-06-11 07:09:25 +00:00
Natanael Copa 3ec82a5a42 First steps for libapk 2010-06-11 07:02:18 +00:00