Debug messages need to be treated a little differently from other
messages, since they include more information, like the time, file and
line of code. So certain things like having carriage returns and
messages with only a line break should not be allowed since they would
mess up the debug output.
This commit fixes that issue
Closes#1009
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Add a data parameter to config parser to make the config_parse function easier to
be reused for other cases. And adapting config_loader to use that new function.
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
The function do_staging is regularly used within a loop to stage all the
files for a given bundle-add or update, repair, etc. However when the
loop contains a progress report (with a percentage), if there are errors
in the do_staging function, they get printed in the same line as the
percentage, messing up the output. Like this:
...22%Warning: Update target directory does not exist: some_file...
This commit fixes that output by adding a carriage return at the
beginning of each message do_staging could print so it would overlap
with the percentage value effectively deleting it.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
The logger functions (warn, error, debug) do not support adding line
breaks or carriage returns at the beginning of the message, because
the line break would be inserted between the label and the message,
or the carriage return would cause the message to overlap the label.
For example, for a code line like this:
warn("\nmy message\n")
The output would look like this:
Warning:
my message
This commit adds support to the logger functions to use "\n" and "\r"
at the beginning of the message so it provides more control over the
output.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Adding carriage return to outpu
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
swupd has many flags that can be used for fine tunning its
functionality. In some cases users may want to include a flag with every
swupd command they run.
This commit gives the ability to provide swupd flags via options in a
configuration file that swupd will read before running the command.
The configuration file is an INI style file tha can include sections
so users can specify options that should only apply to a specific
command. The biggest advantage of this is to be able to fine tune the
flags that should apply for each command.
For example a user could set a global flag that would apply to every
swupd command, and then turn that flag off for a specific command by
unsetting it in the command's section.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Replace stdin with /dev/null for children. This addresses the issue with
hangs when running update hooks which for whatever reason may expect
interactive input.
When using "diagnose --picky --picky-tree /fake/path" swupd was exiting
with error code 34 (SWUPD_OUT_OF_MEMORY_ERROR) which was incorrect.
This commit fixes the issue by returning the correct code 29
(SWUPD_COULDNT_LIST_DIR) in those situations.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When reporting download progress, we should never have a percentage
bigger than 100%, but if for some reason we do (due to a bug), we don't
want that percentage slipping all the way to the end user.
This commit limits the percentage we display to 100 maximum.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Currently when running diagnose, and a problem is found (a missing
file, a corrupt file, or an extraneous file), swupd shows the output
like this:
Verifying files
...12%
Hash mismatch for file: /usr/bin/somefile
...100%
Inspected 632545 files
So it splits the percentage that shows the progress of the action in two
lines. This commit fixes the output so it looks like this instead:
Checking for missing files
...100%
Checking for corrupt files
-> Hash mismatch for file: /usr/bin/mixer
-> Hash mismatch for file: /usr/bin/mixin
-> Hash mismatch for file: /usr/bin/swupd-extract
-> Hash mismatch for file: /usr/bin/swupd-inspector
-> Hash mismatch for file: /usr/share/zsh/site-functions/_mixer
...100%
Checking for extraneous files
...100%
Inspected 632545 files
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit adds a line break at the end of the progress report (when we
reach 100%) so we don't have to manually include it every time we report
progress.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Dirname() is a very tricky function to use. Create a wrapper to make it a
lot easier. The only downside is an extra strdup, but it's worth it.
sys_path_join() is a function to make it easier to concatenate 2 paths using
correct separator and avoid duplicated '/'
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Documentation coverage on src/lib is now 100% and the goal is to eventually
reach that for everything on src/.
Also improve some documention on headers.
When swupd reports progress of content it needs, it does so by counting
how many files it needs to download (fullfiles or packs) and how many it
has already downloaded. This gives a rough estimate of what is the
progress of the overall download, but it can also be very misleading
since some files may be very different in size compared to others. This
is specially true when talking about packs, one pack could be a couple
of megabytes big while another one could be a few hundred megabytes.
This commit adds a curl callback that can be used to report download
progress periodically based on how many bytes have been downloaded vs
how many bytes have to be downloaded in total, giving the ability to report
progress accurately.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
At first I assumed that all tarballs would have a trailing '/' for directories
and this isn't true. But we can't assume that we won't have a trailing '/'. So
archives_check_single_file_tarball() is now ignoring trailing '/' when comparing
files. That is the same behavior of the function that
archives_check_single_file_tarball() replaced.
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
The --json-output flag can be enabled for every swupd command.
This commit converts it to be a global flag, and enables it in every
swupd command.
Closes#869
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Reimplement search file to print output in search time instead of saving
everything to be printed later. This makes search a lot faster and reduce
the memory footprint of this function.
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
swupd prints some messages to stdout and others to stderr, this makes
the code somewhat confusing and also it creates a mess regarding which
messages go where. Messages are usually printed using fprintf() and
printf().
This commit replaces all calls to printf and fprintf with one of the
functions that are part of the logger. This will bring many advantages
to the code:
- readability, it is straightforward to identify where a message needs
to go based on the name of the logger functions.
- consistency, the output will go to either stderr or stdout depending
on the type of message being printed.
- the format of the messages will also be consistent, so for example,
if the message is an error the message will automatically include the
"Error: " label in the beginning of the message, this way we avoid
having things like "ERROR:", "error - ", etc...
Closes#864Closes#294Closes#489Closes#433
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
Since the reporting of a process progress could be printed in different
formats in the future, not just JSON, this patch moves those functions
to their own file (progress.c) so it is decoupled from the json
formatter.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When swupd is run and the stdout is not a tty (for example when
redirecting the output to a file) the progress of a step is being
reported as a sequence of dots, which is not very useful to really
identify how far in the process we are.
This commit changes that behavior so percentages are used to report
progress when not using a tty instead of dots.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit add a few functions to report partial progress on a given
step, either in JSON format or standard so a user or another app can
tell what is the current progress status of a swupd operation at all
times.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit adds a function that can be used to report the status at the
end of an operation into the JSON stream.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
There is the need to print info about swupd operations in a parsable
JSON format.
This function provides a wrapper function to format the messages to
comply with the JSON format if the --json-output flag is used.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
If we have any errors on pipe2 syscall or in pthread creation run tasks
in main thread. Also set the max downloads in parallel to 1 to avoid timeouts
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Use a binary launcher to load swupd-inspector and execute that
when swupd inspector is run.
Closes#826
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When a function returns a boolean state, explicitly return true or
false instead of returning 0 or 1, it is more readable.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>