Compare commits

...
62 Commits
Author SHA1 Message Date
Tudor Marcu 379d5189fc Release v3.2.6
This release introduces a change to the hashing scheme regarding delta names,
and directory hashes, as well as minor fixes to support the new hashing.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-08-22 03:23:22 -07:00
Tudor Marcu 6eca4601b0 Update argument passed to system_argv
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-08-22 03:22:14 -07:00
Tudor Marcu 4940d0cf83 Fix functional test for server changes
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-08-22 02:47:16 -07:00
Tudor Marcu 04d2af2f64 Change delta's name from FROM-TO-HASH2 to FROM-TO-HASH1-HASH2 format.
There is an issue when two different files in a newer release have same hash:
This is, when swupd updates a file by applying a delta, it takes the HASH2 to
know the file where delta must be applyed. If files are different in current
release (before updating), there must be 2 deltas, one for each file but as
the two files have same hash in new release delta's name are the same:
FROM-TO-HASH2 and it is when issue arises due to just the last delta file is
kept when swupd server creates files and packs. So when swupd client tries to
apply the delta to one of the file that does not corresponds it will fail and
generates an error. At the first look it will seem like delta file is corrupted
however the issue is that delta file was created for another file.
To solve this issue we include the hash for the original file in the delta's
name so that swupd client can take the correct delta and apply it:
FROM-TO-HASH1-HASH2.

Signed-off-by: Jose R Guzman <jose.r.guzman.mosqueda@intel.com>
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-08-19 17:17:20 -07:00
Tudor Marcu 1f98322737 Make directory hashes independent on filename
Calculate the hash for directories is desiderable to be independent
on the dirname due to the subsequent calculation on the staged/HASH
file. Here is used const "DIRECTORY" string for input name for
all folders.

Signed-off-by: Jose R Guzman <jose.r.guzman.mosqueda@intel.com>
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-08-19 17:15:56 -07:00
Tudor Marcu ddca171dad Release v3.2.5
This release includes a fix to replace system calls by local system_argv
functions, cleanup patches for error output and code style, adding delta
manifests to delta packs, consistency changes for tar and string allocation,
and removes creation of delta manifests out of create_update.
This is a re-roll of release 3.2.4 to fix a time skew issue that caused some
build failures.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-07-19 16:32:20 -07:00
Tudor Marcu 62c31f0088 Release v3.2.4
This release includes a fix to replace system calls by local system_argv
functions, cleanup patches for error output and code style, adding delta
manifests to delta packs, consistency changes for tar and string allocation,
and removes creation of delta manifests out of create_update.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-07-19 23:21:18 -07:00
Tudor Marcu 54874bd4e1 Add null check before calling rmdir in manifest.c
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-07-19 19:15:33 -07:00
Tudor Marcu 9fe3ad2241 Remove delta manifest creation from create_update
Delta manifests are handled by the pack creation step, and should not be
part of the plain manifest/update content creation step. This reduces the time
swupd_create_update takes to run significantly.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-07-19 02:05:07 -07:00
Tudor Marcu be83996e48 Revert "Parallelize manifest creation code"
This reverts commit 7f3b760430 and commit
74f4afa655. The code introduced parallel manifest
creation, and removed delta manifests from being created, but needs some more
rigorous testing and refactoring to ensure all test suites pass.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-07-14 20:32:51 -07:00
Patrick McCarty 7f3b760430 Import latest version of previous patch
I had neglected to rebase to the latest revision of #21, so this commit
incorporates the additional changes.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-06-03 16:35:56 -07:00
Tudor Marcu 74f4afa655 Parallelize manifest creation and remove deltas
The code previously created all the bundle manifests and delta manifests
synchronously in 1 thread. While this worked, it was not optimal considering
the manifests can be created at the same time since they are unique. This
patch creates a threadpool that processes each bundle manifest in its own
thread. Delta manifest creation was removed from create_update because it
can already be handled by our delta pack creation process, and it is a huge
time-sink for create_update as it also runs single threaded.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-05-20 14:49:08 -07:00
Patrick McCarty ea02b67a93 Provide more information for pack hardlink errors
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-17 16:21:34 -07:00
Patrick McCarty 8af939c817 Update functional test to check for delta manifests in packs
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-17 15:59:14 -07:00
Patrick McCarty 4128fbbb9b Add delta manifests to delta packs
The delta manifests were being staged correctly but were not being added
to the delta packs.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-17 15:49:33 -07:00
Patrick McCarty 0d08824801 Permit allocating empty strings in string_or_die()
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-17 14:21:50 -07:00
Patrick McCarty 8f98e0f570 Update code comment to mention the os-core pack, instead of "base"
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-17 14:19:17 -07:00
Patrick McCarty 76e5af734b Use tar's -C option everywhere instead of --directory
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-17 14:14:51 -07:00
Patrick McCarty b7192ee686 Convert the recently added system() call
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-17 14:14:17 -07:00
Patrick McCarty b0e0b7f77d Fix some clang-format nitpicks
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-17 13:57:48 -07:00
Jose R Guzman 746b9a56a8 Replace system calls by local system_argv functions.
There are new functions that replace system() calls: system_argv(), system_argv_fd and system_argv_pipe().
They are based on execvp() function and they can manage any argument including filenames with characters
that could be interpreted as meta-characters in a regular system() function.
So no escape for the arguments needed and is less prone to errors.

Signed-off-by: Jose R Guzman <jose.r.guzman.mosqueda@intel.com>
2016-05-17 13:56:10 -07:00
Patrick McCarty adfc1067ff Remove pack_maker.sh
Since delta pack creation is very much tied to a DevOps workflow, it
makes more sense for the pack_maker.sh to live outside of swupd-server.

This script will move to the clearlinux/mixer-tools repo, since the
Clear mixer is a DevOps-oriented tool.

Also, update the code comment in versions.c to describe another action
to be taken that is DevOps-specific, namely that the value of
WEBDIR/version/formatN/latest file should be set at release time.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-16 14:20:41 -07:00
Patrick McCarty 122f674e74 Make elapsed time progress messages more flexible
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-11 15:40:50 -07:00
Patrick McCarty 9d4df7e035 Release v3.2.3
This release fixes a bug with adding invalid bundle manifest hashes to
the Manifest.MoM and optimizes swupd_create_update to remove the
unnecessary rsync from the full chroot back to bundle chroots.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-11 11:20:13 -07:00
Tudor Marcu 4df4bf14c3 Remove rsync from full->bundle chroots
This is no longer needed with the current setup, and is just wasting time during
update creation.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-05-10 14:43:06 -07:00
Tudor Marcu 6affbd1ecb Free allocated variable
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-05-05 12:23:59 -07:00
Patrick McCarty 77a0bcd9f9 Account for deleted manifests in the MoM population
Just in case we encounter a bundle manifest that does not exist anymore,
or the last_change is 0, which is an invalid version to create, make
sure we add the deleted entry in the MoM and do not attempt to untar
that manifest.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-05-05 12:17:49 -07:00
Tudor Marcu bf19e48917 Fix bundle manifest hashes from MoM
The bundle manifest hashes were calculated from the STATE_DIR Manifest.bundle
files, which caused a problem when they the permissions/owner were changed. The
hashes should be calculated by untarring the Manifest.BUNDLE.tar files
referenced in the Manifest.MoM.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-05-05 17:57:59 +00:00
Patrick McCarty d45304c8b7 Add functional test for blacklisted file names
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-29 16:39:11 -07:00
Patrick McCarty 2b4e9eb3c9 test: quote echo strings to protect against shell interpretation
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-29 16:39:08 -07:00
Patrick McCarty b6bd8bf73b Release v3.2.2
This release includes a trivial improvement for reporting paths that
contain blacklisted characters.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-29 15:23:44 -07:00
Patrick McCarty 94240130be Report full paths for files containing blacklisted characters
To better track which files are excluded from manifests because they
contain blacklisted characters, the full path is more useful to log
rather than the file basename.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-29 15:04:16 -07:00
Patrick McCarty ae299e2126 Rename main.c to create_update.c
Since the source files for entry points to the other two binaries are
named after the binaries, do the same for swupd_create_update.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-14 11:14:36 -07:00
Patrick McCarty 64e65bca92 Run functional tests in separate directories
To more easily implement tests, analyze test results, etc, store each
test in a separate directory and dump all logs and the web-dir content
there as well.

The test suite can be run with 'make check', as before, but now tests
can be run individually by directly invoking the appropriate test.bats
file (at toplevel, or within the test directory).

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-10 21:03:06 -07:00
Patrick McCarty e78ef77e06 Release v3.2.1
This release fixes a sorting issue with bundle manifests: they should be
version sorted, not filename sorted.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-05 23:51:22 -07:00
Patrick McCarty a329cc93a9 Fix sorting issue with bundle manifests
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-05 23:50:42 -07:00
Patrick McCarty bd002877c1 Release v3.2.0
This release adds support for a bundle includes feature, which allows
bundles that "include" other bundles to depend on each other. This
change reduces duplication of files in manifests and improves build
times for larger bundle sets that contain many includes.

The two other functional changes are:

- The --format option to swupd_create_update is now mandatory.
- The value passed to --format must now be a positive integer.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-05 21:44:00 -07:00
Patrick McCarty cb2706fb72 Move removal of old deleted files to a new function
Since removing of all of the matching deleted files between a build with
an older manifest format and current needs to happen *after*
match_manifests() finishes accounting for new and deleted entries in the
manifests, simply move the logic into a separate function to be called
after match_manifests().

Because one or more file deletions should trigger a fresh bundle manifest
creation, account for the return value of this new function in addition
to the result of manifest pruning and whether any bundle includes were
changed. Since "os-core" is treated specially, and it's expected to
contain changed files for every build, only the non-"os-core" bundle
manifests need the trigger.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-05 21:03:23 -07:00
Patrick McCarty 383ab112db Properly initialize format for new manifests
For the new full manifest and new bundle manifests, the format member
was not being initialized.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-05 16:29:29 -07:00
Patrick McCarty af7767a768 Add required -F option to basic_creator.sh
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-04 19:01:54 -07:00
Patrick McCarty b954d924f4 Update functional test suite for recent changes
For swupd_create_update, the required -F option needed to be added for
several tests, and the option parsing order changed.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-04 18:57:22 -07:00
Patrick McCarty e0049de3dc Fix remaining issues with handling the format number
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-04 18:48:42 -07:00
Patrick McCarty 2a9af990d6 Fix error in the previous rebase
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-04 14:23:05 -07:00
Patrick McCarty 90c976fdaf Require the -F option for swupd_create_update
To decrease chances of specifying an incorrect format number, since the
default is a hardcoded value "3", always require the user to pass the -F
option to swupd_create_update.

In the future, it would be nice to read the default value from a config
file, with the -F option overriding the value.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-04-04 14:18:15 -07:00
Tim Pepper 3b43313c9e Compare current format versus prior format in manifest match
To better support a workflow for incrementing the format on the command
line, it's useful to have the format be an integer instead of a string.
When reading a manifest (ie: old manifest) we can read that into struct
manifest.  Then when building a new manifest we can compare against the
prior manifest's format.  If the format incremented, we can prune files
previously marked as deleted in the old manifest so they no longer
appear in the new manifest.

This is beneficial because a file that has a version number in its name
will repeatedly be deleted and replaced by a new similar file.  Over
time this leads to manifests getting bigger and bigger because they
retain the entire history of all file names which ever existed, even if
a huge number of them are and have been for a long time marked as
deleted.

Signed-off-by: Tim Pepper <timothy.c.pepper@linux.intel.com>
2016-04-04 14:18:10 -07:00
William Douglas 3d8b81fbcd Fix missing closing comment 2016-03-31 18:50:42 +00:00
William Douglas 9b05b06a9b Fix manifests not detecting include changes
When deciding if a new manifest should be generated for a new version,
the included manifests were not being used to detect a manifest
change. This caused manifests that had new includes: lines in the new
version to not be generated resulting in files from the included
manifest to be missed when adding/updating that bundle.

The fix was to compare includes: lines from the current and previous
manifest versions for differences and generate new manifests when that
was the case. In order to compare manifests duplicate includes: lines
are not allowed and previously os-core could be added multiple times to
a manifest because it was always added. This change also added detection
for os-core before automatically adding it to a bundle.
2016-03-31 18:45:33 +00:00
Patrick McCarty 1cd3cdb96f Update gitignore 2016-03-30 13:08:48 -07:00
William Douglas 9c920d65e8 Don't bump versions for deleted files
In Manifest.full, previously a file being deleted from a bundle caused
the version of the file in Manifest.full to increase incorrectly.
2016-03-29 20:06:57 +00:00
William Douglas 825dc6c75f Add functional tests to validate includes work
Check that os-core is subtracked correctly and that $bundle-includes
files are correctly subtracked as well. Also include testing for new
bundles being subtracked.
2016-03-24 21:17:56 +00:00
William Douglas 4fb32c570f Replace explicit os-core subtraction
Now that much of the includes plumbing present on the output/subtract
side, make sure all non os-core manifests explicitly include os-core,
and then use the new extra semantics of subtract_manifests() to subtract
all included bundles, not just os-core.
2016-03-24 21:17:56 +00:00
William Douglas 79e8a12b75 Populate the manifest->includes list
Using the $bundle-includes files for building submanifests from
directories and previous manifest files includes: sections, create the
manifest->includes list as the names of submanifests included in the
submanifest being instantiated.

This needs to then be processed into a list of pointers to the other
submanifests themselves once all other manifests have been
instantiated before use with functions that operate on the includes list
(subtract_manifest and write_manifest for now)..
2016-03-24 21:17:56 +00:00
William Douglas 9b8b1d5359 Make the subtract_manifests function include-aware
When subtracting a manifest from another, all the included manifests
also will need to be subtracted from the original. To do this build up a
unique list of all manifests included (directly or indirectly) from the
manifest being subtracted from.

With that in place, this gives an opportunity to provide the
functionality of subtracting all included manifests from the main
manifest by calling subtract_manifests(A, A);
2016-03-24 21:17:56 +00:00
William Douglas df7b2adc9d Print included bundles in the manifest header
If a bundle includes one or more other bundles, print out one or more
includes: lines as part of the header of the manifest file.

There will be as many includes: lines as included bundles (including
being omitted if a bundle does not include other bundles).
2016-03-24 21:17:56 +00:00
William Douglas 0dcad76694 Add field for expressing included bundles 2016-03-24 21:17:56 +00:00
William Douglas 24ef47f40c Fixups for clang-format v3.8.0 2016-03-24 21:17:56 +00:00
Patrick McCarty 0a41a7e2d5 basic creator: remove unneeded pushd/popd
Since full paths are used everywhere in this script, the pushd/popd
sequence is not needed.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-24 09:38:40 -07:00
Patrick McCarty 51c0bf2007 Release v3.1.2
This release enables logs for the three installed binaries and optimizes
swupd_make_pack performance by preferring to hardlink files to the pack
staging area whenever possible.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-22 17:21:48 -07:00
Patrick McCarty f27d0cf03a Capture logs for every binary
To capture all information that is logged, change init_log() to make
every log file name unique, and add a call to swupd_make_fullfiles to
enable logging.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-22 17:04:17 -07:00
Arjan van de Ven 08fb540678 Speed up pack creation
A big chunk of time during pack creation is spent in untar'ing of
fullfiles tar files.  However, we also (most likely) have this exact
same content already in the image/ directory.

This patch makes the pack creator skip the untar if its possible to link
the file directly, and falls back to the existing behavior if the link
fails

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-22 13:04:45 -07:00
Patrick McCarty 2355295023 Release v3.1.1
This release fixes a bug in manifest subtraction logic that may result
in "partial" subtraction of one manifest from another. The fix now
ensures that a manifest can be fully subtracted.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-18 11:33:21 -07:00
Patrick McCarty 1aed8c3d4d Fix manifest subtraction logic
In subtract_manifests(), if the two files under consideration have the
same filename but should not be subtracted, a file is skipped in the m2
manifest because there is no "continue" statement at the end of the
first "if" block.

This results in potentially many files not getting subtracted when they
ought to be.

To clarify the logic, avoid using "continue", since it is not needed.
Convert to using one "if" block instead.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-17 23:44:53 -07:00
38 changed files with 1275 additions and 610 deletions
+5 -4
View File
@@ -19,16 +19,17 @@ stamp-h1
DEADJOE
swupd_create_update
swupd_make_pack
swupd-update-server.log*
swupd_make_fullfiles
swupd-server-*.tar.gz
swupd-server.log.*
cscope.*
*.kdev4
coverage/
src/*.gcno
src/*.gcda
tap-driver.sh
test/functional/*.log
test/functional/*.trs
test/functional/*/*.log
test/functional/*/*.trs
test/functional/*/logs/
test/functional/*/web-dir/
swupd-*.log
test-suite.log
+12 -9
View File
@@ -15,6 +15,7 @@ swupd_create_update_SOURCES = \
src/analyze_fs.c \
src/chroot.c \
src/config.c \
src/create_update.c \
src/delta.c \
src/fullfiles.c \
src/globals.c \
@@ -22,7 +23,6 @@ swupd_create_update_SOURCES = \
src/helpers.c \
src/heuristics.c \
src/log.c \
src/main.c \
src/manifest.c \
src/pack.c \
src/rename.c \
@@ -96,24 +96,27 @@ noinst_HEADERS = \
include/swupd.h \
include/xattrs.h
TEST_EXTENSIONS = .sh
TEST_EXTENSIONS = .bats
if ENABLE_TESTS
tap_driver = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(top_srcdir)/tap-driver.sh
LOG_DRIVER = $(tap_driver)
SH_LOG_DRIVER = $(tap_driver)
BATS_LOG_DRIVER = $(tap_driver)
TESTS = $(dist_check_SCRIPTS)
dist_check_SCRIPTS = \
test/functional/basic.bats \
test/functional/update.bats \
test/functional/fullfiles.bats \
test/functional/pack.bats \
test/functional/full-run.bats \
test/functional/full-run-delta.bats
test/functional/basic/test.bats \
test/functional/delete-no-version-bump/test.bats \
test/functional/include-version-bump/test.bats \
test/functional/update/test.bats \
test/functional/fullfiles/test.bats \
test/functional/pack/test.bats \
test/functional/full-run/test.bats \
test/functional/full-run-delta/test.bats \
test/functional/file-name-blacklisted/test.bats
endif
if COVERAGE
+1 -9
View File
@@ -23,11 +23,9 @@ export LEAF_CERT="leaf.cert.pem"
export CA_CHAIN_CERT="ca-chain.cert.pem"
export PASSPHRASE="${SWUPD_CERTS_DIR}/passphrase"
${SWUPDREPO}/swupd_create_update --osversion ${VER} --statedir ${UPDATEDIR}
${SWUPDREPO}/swupd_create_update --osversion ${VER} --statedir ${UPDATEDIR} --format 3
${SWUPDREPO}/swupd_make_fullfiles --statedir ${UPDATEDIR} ${VER}
pushd ${SWUPDREPO}
# create zero packs
MOM=${UPDATEDIR}/www/${VER}/Manifest.MoM
if [ ! -e ${MOM} ]; then
@@ -47,12 +45,6 @@ for job in $(jobs -p); do
fi
done
# create delta packs for 2 versions back
NUM_PACKS=2
${SWUPDREPO}/pack_maker.sh ${VER} ${NUM_PACKS}
popd
# expose the new build to staging / testing
echo ${VER} > ${UPDATEDIR}/image/latest.version
+1 -1
View File
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.66])
AC_INIT(swupd-server, 3.1.0, timothy.c.pepper@linux.intel.com)
AC_INIT(swupd-server, 3.2.6, timothy.c.pepper@linux.intel.com)
AM_INIT_AUTOMAKE([foreign -Wall -W subdir-objects])
AM_SILENT_RULES([yes])
AC_PROG_CC
+21 -7
View File
@@ -13,26 +13,31 @@
// SWUPD_NUM_PACKS is also "PREV_CHECK" in releas tool swupd_bb.py (change both)
#define SWUPD_NUM_PACKS 4
#define SWUPD_NUM_MANIFEST_DELTAS 25
#define SWUPD_DEFAULT_FORMAT 3
#define SWUPD_SERVER_STATE_DIR "/var/lib/update"
#if SWUPD_WITH_BSDTAR
#define TAR_COMMAND "bsdtar"
#define TAR_XATTR_ARGS ""
#define TAR_XATTR_ARGS_STRLIST
#define TAR_WARN_ARGS ""
#else
#define TAR_COMMAND "tar"
#define TAR_XATTR_ARGS "--xattrs --xattrs-include='*'"
#define TAR_XATTR_ARGS_STRLIST "--xattrs", "--xattrs-include='*'",
#define TAR_WARN_ARGS "--warning=no-timestamp"
#endif
#if SWUPD_WITH_SELINUX
#define TAR_PERM_ATTR_ARGS "--preserve-permissions --selinux " TAR_XATTR_ARGS
#define TAR_PERM_ATTR_ARGS_STRLIST TAR_XATTR_ARGS_STRLIST "--preserve-permissions", "--selinux"
#else
#define TAR_PERM_ATTR_ARGS "--preserve-permissions " TAR_XATTR_ARGS
#define TAR_PERM_ATTR_ARGS_STRLIST TAR_XATTR_ARGS_STRLIST "--preserve-permissions"
#endif
#define SWUPD_HASH_DIRNAME "DIRECTORY"
#if SWUPD_WITH_STATELESS
#define OS_IS_STATELESS 1
#else
@@ -61,6 +66,7 @@
#endif
struct manifest {
unsigned long long int format;
int version;
int prevversion;
char *component;
@@ -70,6 +76,8 @@ struct manifest {
GList *manifests; /* as struct file */
GList *submanifests; /* as struct manifest */
GList *includes; /* struct manifests for all bundles included into this one */
};
struct file;
@@ -134,7 +142,7 @@ struct packdata {
extern int current_version;
extern int newversion;
extern int minversion;
extern char *format_string;
extern unsigned long long int format;
extern bool enable_signing;
extern char *state_dir;
@@ -144,7 +152,7 @@ extern char *staging_dir;
extern bool init_globals(void);
extern void free_globals(void);
extern bool set_format_string(char *);
extern bool set_format(char *);
extern void check_root(void);
extern bool set_state_dir(char *);
extern bool init_state_globals(void);
@@ -173,10 +181,13 @@ extern void free_manifest(struct manifest *manifest);
extern struct manifest *alloc_manifest(int version, char *module);
extern int match_manifests(struct manifest *m1, struct manifest *m2);
extern void sort_manifest_by_version(struct manifest *manifest);
extern bool manifest_includes(struct manifest *manifest, char *component);
extern bool changed_includes(struct manifest *old, struct manifest *new);
extern int prune_manifest(struct manifest *manifest);
extern int remove_old_deleted_files(struct manifest *m1, struct manifest *m2);
extern void create_manifest_delta(int oldversion, int newversion, char *module);
extern void create_manifest_deltas(struct manifest *manifest, GList *last_versions_list);
extern void subtract_manifests(struct manifest *m1, struct manifest *m2);
extern void subtract_manifests_frontend(struct manifest *m1, struct manifest *m2);
extern void nest_manifest(struct manifest *parent, struct manifest *sub);
extern void nest_manifest_file(struct manifest *parent, struct file *file);
extern int manifest_subversion(struct manifest *parent, char *group);
@@ -222,7 +233,7 @@ extern void populate_file_struct(struct file *file, char *filename);
extern void download_exta_base_content(void);
extern char *get_elapsed_time(struct timeval *t1, struct timeval *t2);
extern void init_log(int version);
extern void init_log(const char *prefix, const char *bundle, int start, int end);
extern void init_log_stdout(void);
extern void close_log(int version, int exit_status);
extern void __log_message(struct file *file, char *msg, char *filename, int linenr, const char *fmt, ...);
@@ -233,7 +244,7 @@ extern void type_change_detection(struct manifest *manifest);
extern void rename_detection(struct manifest *manifest, int last_change, GList *last_versions_list);
extern void link_renames(GList *newfiles, struct manifest *from_manifest);
extern void __create_delta(struct file *file, int from_version);
extern void __create_delta(struct file *file, int from_version, char *from_hash);
extern void account_delta_hit(void);
extern void account_delta_miss(void);
@@ -241,8 +252,11 @@ extern void account_delta_miss(void);
extern FILE *fopen_exclusive(const char *filename); /* no mode, opens for write only */
extern void dump_file_info(struct file *file);
extern void string_or_die(char **strp, const char *fmt, ...);
extern void print_elapsed_time(struct timeval *previous_time, struct timeval *current_time);
extern void print_elapsed_time(const char *step, struct timeval *previous_time, struct timeval *current_time);
extern int system_argv(char *const argv[]);
extern int system_argv_fd(char *const argv[], int newstdin, int newstdout, int newstderr);
extern int system_argv_pipe(char *const argvp1[], int stdinp1, int stderrp1,
char *const argvp2[], int stdoutp2, int stderrp2);
extern bool signature_initialize(void);
extern void signature_terminate(void);
-112
View File
@@ -1,112 +0,0 @@
#!/bin/bash -e
# usage:
# pack_maker.sh <to version> <back_count>
# pack_maker.sh 2820 2
# pack_maker.sh 2730 3
#
# For each bundle changed as of the Manifest.MoM at the <to version>,
# create version-pair packs going back <back_count>
# versions of that bundle. For example if bundle "editors" changed in 2650
# and the script is run as "pack_maker.sh 2650 2", it will find that
# "editors" last two change points were 2550 and 2260 and thus create a
# 2550-to-2650 and a 2260-to-2650 version pair pack for the "editors"
# bundle.
#NOTE: fullfiles must be created before calling this script
#NOTE: zero packs need similarly created
#NOTE: build numbers are sparse, search back for the next oldest existing build
#NOTE: in the future isn't simply -10, and when that change happens we must also
# consider which version-pair packs are meaningful for intermediate builds
# and revert builds.
SWUPDREPO=${SWUPDREPO:-"/usr/src/clear-projects/swupd-server"}
BUNDLEREPO=${BUNDLEREPO:-"/usr/src/clear-projects/clr-bundles"}
UPDATEDIR=${UPDATEDIR:-"/var/lib/update"}
SWUPDWEBDIR="${UPDATEDIR}/www"
SWUPD_CERTS_DIR=${SWUPD_CERTS_DIR=:-"/root/swupd-certs"}
export XZ_DEFAULTS="--threads 0"
export SWUPD_CERTS_DIR
export LEAF_KEY="leaf.key.pem"
export LEAF_CERT="leaf.cert.pem"
export CA_CHAIN_CERT="ca-chain.cert.pem"
export PASSPHRASE="${SWUPD_CERTS_DIR}/passphrase"
VER=$1
BACK_COUNT=$2
if [ "${BACK_COUNT}" == "" ]; then
echo "missing to pack count"
exit 1
fi
if [ "${VER}" == "" ]; then
echo "missing to version"
exit 1
fi
MOM=${SWUPDWEBDIR}/${VER}/Manifest.MoM
if [ ! -e ${MOM} ]; then
echo "invalid version (no ${MOM})"
exit 1
fi
#time ${SWUPDREPO}/swupd_make_fullfiles --statedir ${UPDATEDIR} ${VER}
BUNDLE_LIST=$(cat ${MOM} | awk -v V=${VER} '$1 ~ /^M\./ && $3 == V { print $4 }')
# build packs for all bundles changed in $VER
for BUNDLE in $BUNDLE_LIST; do
#${SWUPDREPO}/swupd_make_pack --statedir ${UPDATEDIR} 0 ${VER} ${BUNDLE} &
BUNDLE_VER_LIST=""
MANIFEST_VER=$(cat ${SWUPDWEBDIR}/$VER/Manifest.MoM | grep "^previous:" | cut -f 2)
BUNDLE_VER=""
COUNT=0
while [ $COUNT -lt $BACK_COUNT ] && [ $MANIFEST_VER -gt 0 ]; do
MOM=${SWUPDWEBDIR}/$MANIFEST_VER/Manifest.MoM
if [ -e ${MOM} ]; then
BUNDLE_VER=$(cat ${MOM} | grep " ${BUNDLE}$" | cut -f 3)
if [ "$BUNDLE_VER" != "" ]; then
BUNDLE_VER_LIST="$BUNDLE_VER $BUNDLE_VER_LIST"
MANIFEST_VER=$(cat ${SWUPDWEBDIR}/$BUNDLE_VER/Manifest.MoM | grep "^previous:" | cut -f 2)
let COUNT=$((COUNT+1))
else
# back in history to where bundle didn't exist yet
MANIFEST_VER=0
fi
else
# seek backwards until a manifest if found
MANIFEST_VER=$((MANIFEST_VER-10))
fi
done
for v in $BUNDLE_VER_LIST; do
if [ -e ${SWUPDWEBDIR}/${VER}/pack-${BUNDLE}-from-$v.tar ]; then
echo "${VER}/pack-${BUNDLE}-from-$v.tar already exists, skipping."
else
${SWUPDREPO}/swupd_make_pack --statedir ${UPDATEDIR} $v ${VER} ${BUNDLE} &
fi
done
done
for job in $(jobs -p)
do
wait ${job}
RET=$?
if [ "$RET" != "0" ]; then
echo "pack creation failure!"
exit $RET
fi
done
# NOTE: your devops will want to expose the completed swupd server build to
# trial usage at some point. This would be done via code like:
#
# echo ${VER} > ${SWUPDWEBDIR}/../image/latest.version
# STAGING=$(cat ${SWUPDWEBDIR}/version/formatstaging/latest)
# if [ "${STAGING}" -lt "${VER}" ]; then
# echo ${VER} > ${SWUPDWEBDIR}/version/formatstaging/latest
# fi
+75 -16
View File
@@ -23,19 +23,19 @@
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <glib.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <openssl/hmac.h>
#include <linux/limits.h>
#include <openssl/hmac.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "swupd.h"
#include "xattrs.h"
@@ -222,7 +222,7 @@ int compute_hash(struct file *file, char *filename)
hmac_sha256_for_string(file->hash,
(const unsigned char *)key,
key_len,
file->filename); //file->filename not filename
SWUPD_HASH_DIRNAME); // Make independent of dirname
return 0;
}
@@ -286,18 +286,15 @@ static bool illegal_characters(char *filename)
// these breaks the tar transform sed-like expression,
// hopefully can remove this check after moving to libtar
if (strncmp(filename, "+", 1) == 0) {
printf("WARNING: Filename %s begins with '+'! ...skipping.\n", filename);
return true;
}
if (strstr(filename, "+package+") != NULL) {
printf("WARNING: Filename %s contains \"+package+\"! ...skipping.\n", filename);
return true;
}
for (i = 0; i < BAD_CHAR_COUNT; i++) {
c = bad_chars[i];
if (strchr(filename, c) != NULL) {
printf("WARNING: Filename %s includes illegal character '%c'! ...skipping.\n", filename, c);
return true;
}
}
@@ -323,6 +320,7 @@ static void iterate_directory(struct manifest *manifest, char *pathprefix,
while (dir) {
struct file *file;
char *sub_filename;
char *fullname;
entry = readdir(dir);
@@ -331,8 +329,15 @@ static void iterate_directory(struct manifest *manifest, char *pathprefix,
}
if ((strcmp(entry->d_name, ".") == 0) ||
(strcmp(entry->d_name, "..") == 0) ||
(illegal_characters(entry->d_name))) {
(strcmp(entry->d_name, "..") == 0)) {
continue;
}
string_or_die(&sub_filename, "%s/%s", subpath, entry->d_name);
if (illegal_characters(entry->d_name)) {
printf("WARNING: Filename %s includes illegal character(s) ...skipping.\n", sub_filename);
free(sub_filename);
continue;
}
@@ -342,7 +347,7 @@ static void iterate_directory(struct manifest *manifest, char *pathprefix,
}
file->last_change = manifest->version;
string_or_die(&file->filename, "%s/%s", subpath, entry->d_name);
file->filename = sub_filename;
string_or_die(&fullname, "%s/%s", fullpath, entry->d_name);
populate_file_struct(file, fullname);
@@ -402,6 +407,58 @@ struct manifest *full_manifest_from_directory(int version)
return manifest;
}
/* Read includes from $manifest-includes file */
GList *get_sub_manifest_includes(char *component, int version)
{
FILE *infile;
GList *includes = NULL;
char *c;
char *conf;
char *filename;
char *included;
char line[8192];
conf = config_output_dir();
if (conf == NULL) {
assert(0);
}
string_or_die(&filename, "%s/%i/noship/%s-includes", conf, version, component);
free(conf);
LOG(NULL, "Reading includes", "%s", filename);
infile = fopen(filename, "rb");
if (infile == NULL) {
if (errno != ENOENT) {
LOG(NULL, "Cannot read includes", "%s (%s)\n", filename, strerror(errno));
}
free(filename);
return NULL;
}
line[0] = 0;
while (strcmp(line, "\n") != 0) {
line[0] = 0;
if (fgets(line, 8191, infile) == NULL) {
break;
}
c = strchr(line, '\n');
if (c) {
*c = 0;
}
if (strlen(line) == 0) {
break;
}
included = strdup(line);
includes = g_list_prepend(includes, included);
}
fclose(infile);
includes = g_list_sort(includes, (GCompareFunc)strcmp);
return includes;
}
struct manifest *sub_manifest_from_directory(char *component, int version)
{
struct manifest *manifest;
@@ -419,6 +476,8 @@ struct manifest *sub_manifest_from_directory(char *component, int version)
manifest->files = g_list_sort(manifest->files, file_sort_filename);
manifest->includes = get_sub_manifest_includes(component, version);
return manifest;
}
+16 -36
View File
@@ -21,23 +21,21 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <glib.h>
#include <sys/types.h>
#include <unistd.h>
#include "swupd.h"
void chroot_create_full(int newversion)
{
int ret;
char *group;
char *command;
char *param;
char *full_dir;
string_or_die(&full_dir, "%s/%i/full/", image_dir, newversion);
@@ -46,11 +44,12 @@ void chroot_create_full(int newversion)
/* start with base */
LOG(NULL, "Copying chroot os-core to full", "");
string_or_die(&command, "rsync -aAX %s/%i/os-core/ %s",
image_dir, newversion, full_dir);
ret = system(command);
assert(ret == 0);
free(command);
string_or_die(&param, "%s/%i/os-core/", image_dir, newversion);
char *const rsynccmd[] = { "rsync", "-aAX", param, full_dir, NULL };
if (system_argv(rsynccmd) != 0) {
assert(0);
}
free(param);
/* overlay any new files from each group */
while (1) {
@@ -60,31 +59,12 @@ void chroot_create_full(int newversion)
}
LOG(NULL, "Overlaying bundle chroot onto full", "%s", group);
string_or_die(&command, "rsync -aAX --ignore-existing %s/%i/%s/ %s",
image_dir, newversion, group, full_dir);
ret = system(command);
assert(ret == 0);
free(command);
}
/* and since some dumb files have things like install timestamps in
* them, we pull files from full back to bundles so each instance
* of the "same" file is truly identical across bundles. It may
* make sense at some point to add more logic here for conflict
* detection and resolution, including work to insure renames are
* consistent across groups. */
while (1) {
group = next_group();
if (!group) {
break;
string_or_die(&param, "%s/%i/%s/", image_dir, newversion, group);
char *const rsynccmd[] = { "rsync", "-aAX", "--ignore-existing", param, full_dir, NULL };
if (system_argv(rsynccmd) != 0) {
assert(0);
}
LOG(NULL, "Recopy bundle chroot out of full", "%s", group);
string_or_die(&command, "rsync -aAX --existing %s %s/%i/%s",
full_dir, image_dir, newversion, group);
ret = system(command);
assert(ret == 0);
free(command);
free(param);
}
free(full_dir);
}
+2 -2
View File
@@ -20,11 +20,11 @@
*
*/
#include <assert.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <glib.h>
#include "swupd.h"
+84 -30
View File
@@ -25,17 +25,17 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <errno.h>
#include <getopt.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <glib.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <getopt.h>
#include <sys/wait.h>
#include <unistd.h>
#include "swupd.h"
@@ -69,7 +69,7 @@ static void print_help(const char *name)
printf("Application Options:\n");
printf(" -o, --osversion The OS version for which to create an update\n");
printf(" -m, --minversion Optional minimum file version to write into manifests per file\n");
printf(" -F, --format Optional format string [ default:=%d ]\n", SWUPD_DEFAULT_FORMAT);
printf(" -F, --format Format number for the update\n");
printf(" -g, --getformat Print current format string and exit\n");
printf(" -S, --statedir Optional directory to use for state [ default:=%s ]\n", SWUPD_SERVER_STATE_DIR);
printf(" -s, --signcontent Enables cryptographic signing of update content\n");
@@ -105,7 +105,7 @@ static bool parse_options(int argc, char **argv)
}
break;
case 'F':
if (!optarg || !set_format_string(optarg)) {
if (!optarg || !set_format(optarg)) {
printf("Invalid --format argument\n\n");
return false;
}
@@ -117,10 +117,10 @@ static bool parse_options(int argc, char **argv)
}
break;
case 'g':
if (format_string == NULL) {
printf("%d\n", SWUPD_DEFAULT_FORMAT);
if (format == 0) {
printf("No format specified\n");
} else {
printf("%s\n", format_string);
printf("%llu\n", format);
free_globals();
}
exit(0);
@@ -223,8 +223,11 @@ int main(int argc, char **argv)
struct manifest *old_full = NULL;
struct manifest *new_full = NULL;
GHashTable *new_manifests = g_hash_table_new(g_str_hash, g_str_equal);
GHashTable *old_manifests = g_hash_table_new(g_str_hash, g_str_equal);
GList *manifests_last_versions_list = NULL;
int newfiles = 0;
int old_deleted = 0;
struct timeval current_time;
struct timeval previous_time;
@@ -274,7 +277,7 @@ int main(int argc, char **argv)
populate_dirs(newversion);
printf("Next version is %i \n", newversion);
init_log(newversion);
init_log("swupd-create-update", "", current_version, newversion);
gettimeofday(&previous_time, NULL);
@@ -285,7 +288,7 @@ int main(int argc, char **argv)
printf("Syncing bundle chroots with full chroot\n");
chroot_create_full(newversion);
print_elapsed_time(&previous_time, &current_time);
print_elapsed_time("full chroot creation", &previous_time, &current_time);
printf("Calculating full manifest (this is expensive/slow)\n");
old_full = manifest_from_file(current_version, "full");
@@ -293,11 +296,18 @@ int main(int argc, char **argv)
apply_heuristics(old_full);
apply_heuristics(new_full);
match_manifests(old_full, new_full);
old_deleted = remove_old_deleted_files(old_full, new_full);
if (old_deleted > 0) {
LOG(NULL, "", "Old deleted files (%d) removed from full manifest", old_deleted);
printf("Old deleted files (%d) removed from full manifest\n", old_deleted);
}
apply_heuristics(new_full);
#warning disabled rename detection for some simplicity
// rename_detection(new_full);
print_elapsed_time(&previous_time, &current_time);
print_elapsed_time("full manifest creation", &previous_time, &current_time);
printf("Entering phase 2: Doing the os-core bundle\n");
/* Phase 2 : the os-core set */
@@ -332,6 +342,7 @@ int main(int argc, char **argv)
/* Detect renamed files specifically for each pack */
// rename_detection(...);
old_deleted = remove_old_deleted_files(old_core, new_core);
sort_manifest_by_version(new_core);
newfiles = prune_manifest(new_core);
if (newfiles <= 0) {
@@ -339,20 +350,56 @@ int main(int argc, char **argv)
printf("Core component has not changed (after pruning), exiting\n");
goto exit;
}
LOG(NULL, "", "Core component has changes (%d), writing out new manifest", newfiles);
printf("Core component has changes (%d), writing out new manifest\n", newfiles);
LOG(NULL, "", "Core component has changes (%d new, %d deleted), writing out new manifest", newfiles, old_deleted);
printf("Core component has changes (%d new, %d deleted), writing out new manifest\n", newfiles, old_deleted);
if (write_manifest(new_core) != 0) {
LOG(NULL, "", "Core component manifest write failed");
printf("Core component manifest write failed\n");
goto exit;
}
create_manifest_deltas(new_core, manifests_last_versions_list);
}
nest_manifest(new_MoM, new_core);
/* Phase 3: the functional bundles */
printf("Entering phase 3: The bundles\n");
while (1) {
char *group = next_group();
if (!group) {
break;
}
(void)g_hash_table_insert(new_manifests, group, sub_manifest_from_directory(group, newversion));
(void)g_hash_table_insert(old_manifests, group, manifest_from_file(manifest_subversion(old_MoM, group), group));
}
while (1) {
GList *manifest_includes = NULL;
GList *name_includes;
char *group = next_group();
struct manifest *manifest;
if (!group) {
break;
}
manifest = g_hash_table_lookup(new_manifests, group);
name_includes = manifest->includes;
while (name_includes) {
char *name = name_includes->data;
name_includes = g_list_next(name_includes);
manifest_includes = g_list_prepend(manifest_includes, g_hash_table_lookup(new_manifests, name));
}
manifest->includes = manifest_includes;
manifest_includes = NULL;
manifest = g_hash_table_lookup(old_manifests, group);
name_includes = manifest->includes;
while (name_includes) {
char *name = name_includes->data;
name_includes = g_list_next(name_includes);
manifest_includes = g_list_prepend(manifest_includes, g_hash_table_lookup(old_manifests, name));
}
manifest->includes = manifest_includes;
}
while (1) {
char *group = next_group();
struct manifest *oldm;
@@ -369,19 +416,27 @@ int main(int argc, char **argv)
printf("Processing bundle %s\n", group);
/* Step 4: Make a manifest for this functonal group */
oldm = manifest_from_file(manifest_subversion(old_MoM, group), group);
newm = sub_manifest_from_directory(group, newversion);
oldm = g_hash_table_lookup(old_manifests, group);
newm = g_hash_table_lookup(new_manifests, group);
add_component_hashes_to_manifest(newm, new_full);
apply_heuristics(oldm);
apply_heuristics(newm);
newm->prevversion = oldm->version;
/* add os-core as an included manifest */
if (!manifest_includes(oldm, "os-core")) {
oldm->includes = g_list_prepend(oldm->includes, old_core);
}
if (!manifest_includes(newm, "os-core")) {
newm->includes = g_list_prepend(newm->includes, new_core);
}
/* Step 5: Subtract the core files from the manifest */
subtract_manifests(oldm, old_core);
subtract_manifests(newm, new_core);
subtract_manifests_frontend(oldm, oldm);
subtract_manifests_frontend(newm, newm);
/* Step 6: Compare manifest to the previous version... */
if (match_manifests(oldm, newm) == 0) {
if (match_manifests(oldm, newm) == 0 && !changed_includes(oldm, newm)) {
LOG(NULL, "", "%s components have not changed, no new manifest", group);
printf("%s components have not changed, no new manifest\n", group);
/* Step 6a: if nothing changed, stay at the old version */
@@ -390,18 +445,18 @@ int main(int argc, char **argv)
apply_heuristics(newm);
#warning missing rename_detection here
/* Step 6b: otherwise, write out the manifest */
old_deleted = remove_old_deleted_files(oldm, newm);
sort_manifest_by_version(newm);
type_change_detection(newm);
newfiles = prune_manifest(newm);
if (newfiles > 0) {
LOG(NULL, "", "%s component has changes (%d), writing out new manifest", group, newfiles);
printf("%s component has changes (%d), writing out new manifest\n", group, newfiles);
if (newfiles > 0 || old_deleted > 0 || changed_includes(oldm, newm)) {
LOG(NULL, "", "%s component has changes (%d new, %d deleted), writing out new manifest", group, newfiles, old_deleted);
printf("%s component has changes (%d new, %d deleted), writing out new manifest\n", group, newfiles, old_deleted);
if (write_manifest(newm) != 0) {
LOG(NULL, "", "%s component manifest write failed", group);
printf("%s component manifest write failed\n", group);
goto exit;
}
create_manifest_deltas(newm, manifests_last_versions_list);
} else {
LOG(NULL, "", "%s component has not changed (after pruning), no new manifest", group);
printf("%s component has not changed (after pruning), no new manifest\n", group);
@@ -412,7 +467,7 @@ int main(int argc, char **argv)
nest_manifest(new_MoM, newm);
}
print_elapsed_time(&previous_time, &current_time);
print_elapsed_time("bundle manifest creation", &previous_time, &current_time);
printf("Entering phase 4: completion manifests \n");
/* Phase 4 : manifest completion */
@@ -423,9 +478,8 @@ int main(int argc, char **argv)
printf("Failed to write new MoM\n");
goto exit;
}
create_manifest_deltas(new_MoM, manifests_last_versions_list);
print_elapsed_time(&previous_time, &current_time);
print_elapsed_time("MoM creation", &previous_time, &current_time);
printf("Entering phase 5: creating download content\n");
/* Phase 5: wrapping up */
@@ -442,7 +496,7 @@ int main(int argc, char **argv)
/* Step 8: Prepare delta directory */
prepare_delta_dir(new_full);
print_elapsed_time(&previous_time, &current_time);
print_elapsed_time("finalize update", &previous_time, &current_time);
exit_status = EXIT_SUCCESS;
exit:
+15 -19
View File
@@ -21,26 +21,23 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <bsdiff.h>
#include <errno.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <bsdiff.h>
#include <glib.h>
#include <sys/types.h>
#include <unistd.h>
#include "swupd.h"
#include "xattrs.h"
void __create_delta(struct file *file, int from_version)
void __create_delta(struct file *file, int from_version, char *from_hash)
{
char *original, *newfile, *outfile, *dotfile, *testnewfile, *sanitycheck;
char *conf;
char *original, *newfile, *outfile, *dotfile, *testnewfile, *conf;
int ret;
if (file->is_link) {
@@ -64,10 +61,9 @@ void __create_delta(struct file *file, int from_version)
conf = config_output_dir();
string_or_die(&outfile, "%s/%i/delta/%i-%i-%s", conf, file->last_change, from_version, file->last_change, file->hash);
string_or_die(&dotfile, "%s/%i/delta/.%i-%i-%s", conf, file->last_change, from_version, file->last_change, file->hash);
string_or_die(&testnewfile, "%s/%i/delta/.%i-%i-%s.testnewfile", conf, file->last_change, from_version, file->last_change, file->hash);
string_or_die(&sanitycheck, "cmp -s \"%s\" \"%s\"", newfile, testnewfile);
string_or_die(&outfile, "%s/%i/delta/%i-%i-%s-%s", conf, file->last_change, from_version, file->last_change, from_hash, file->hash);
string_or_die(&dotfile, "%s/%i/delta/.%i-%i-%s-%s", conf, file->last_change, from_version, file->last_change, from_hash, file->hash);
string_or_die(&testnewfile, "%s/%i/delta/.%i-%i-%s-%s.testnewfile", conf, file->last_change, from_version, file->last_change, from_hash, file->hash);
LOG(file, "Making delta", "%s->%s", original, newfile);
@@ -112,13 +108,14 @@ void __create_delta(struct file *file, int from_version)
goto out;
}
ret = system(sanitycheck);
if (ret == -1 || !WIFEXITED(ret) || WEXITSTATUS(ret) == 2) {
char *const sanitycheck[] = { "cmp", "-s", newfile, testnewfile, NULL };
ret = system_argv(sanitycheck);
if (ret == -1 || ret == 2) {
printf("Sanity check system command failed %i. \n", ret);
printf("%s->%s via diff %s yielded %s\n", original, newfile, dotfile, testnewfile);
assert(0);
goto out;
} else if (WEXITSTATUS(ret) == 1) {
} else if (ret == 1) {
printf("Delta application resulted in file mismatch %i. \n", ret);
printf("%s->%s via diff %s yielded %s\n", original, newfile, dotfile, testnewfile);
LOG(file, "Delta mismatch:", "%s->%s via diff %s yielded %s", original, newfile, dotfile, testnewfile);
@@ -139,7 +136,6 @@ void __create_delta(struct file *file, int from_version)
LOG(NULL, "Failed to rename", "");
}
out:
free(sanitycheck);
free(testnewfile);
free(conf);
free(newfile);
+56 -40
View File
@@ -22,18 +22,18 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <libgen.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdint.h>
#include <errno.h>
#include <libgen.h>
#include <glib.h>
#include <sys/types.h>
#include <unistd.h>
#include "swupd.h"
@@ -42,7 +42,6 @@
static void create_fullfile(struct file *file)
{
char *origin;
char *tarcommand = NULL;
char *tarname = NULL;
char *rename_source = NULL;
char *rename_target = NULL;
@@ -50,6 +49,8 @@ static void create_fullfile(struct file *file)
int ret;
struct stat sbuf;
char *empty, *indir, *outdir;
char *param1, *param2;
int stderrfd;
if (file->is_deleted) {
return; /* file got deleted -> by definition we cannot tar it up */
@@ -92,14 +93,22 @@ static void create_fullfile(struct file *file)
assert(0);
}
string_or_die(&tarcommand, TAR_COMMAND " -C %s " TAR_PERM_ATTR_ARGS " -cf - --exclude='%s/?*' './%s' 2> /dev/null | "
TAR_COMMAND " -C %s " TAR_PERM_ATTR_ARGS " -xf - 2> /dev/null",
dir, base, base, rename_tmpdir);
if (system(tarcommand) != 0) {
LOG(NULL, "Failed to run command:", "%s", tarcommand);
string_or_die(&param1, "--exclude=%s/?*", base);
string_or_die(&param2, "./%s", base);
char *const tarcfcmd[] = { TAR_COMMAND, "-C", dir, TAR_PERM_ATTR_ARGS_STRLIST, "-cf", "-", param1, param2, NULL };
char *const tarxfcmd[] = { TAR_COMMAND, "-C", rename_tmpdir, TAR_PERM_ATTR_ARGS_STRLIST, "-xf", "-", NULL };
stderrfd = open("/dev/null", O_WRONLY);
if (stderrfd == -1) {
LOG(NULL, "Failed to open /dev/null", "");
assert(0);
}
free(tarcommand);
if (system_argv_pipe(tarcfcmd, -1, stderrfd, tarxfcmd, -1, stderrfd) != 0) {
assert(0);
}
free(param1);
free(param2);
close(stderrfd);
string_or_die(&rename_source, "%s/%s", rename_tmpdir, base);
string_or_die(&rename_target, "%s/%s", rename_tmpdir, file->hash);
@@ -110,13 +119,13 @@ static void create_fullfile(struct file *file)
free(rename_source);
/* for a directory file, tar up simply with gzip */
string_or_die(&tarcommand, TAR_COMMAND " -C %s " TAR_PERM_ATTR_ARGS " -zcf %s/%i/files/%s.tar %s",
rename_tmpdir, outdir, file->last_change, file->hash, file->hash);
if (system(tarcommand) != 0) {
LOG(NULL, "Failed to run command:", "%s", tarcommand);
string_or_die(&param1, "%s/%i/files/%s.tar", outdir, file->last_change, file->hash);
char *const tarcmd[] = { TAR_COMMAND, "-C", rename_tmpdir, TAR_PERM_ATTR_ARGS_STRLIST, "-zcf", param1, file->hash, NULL };
if (system_argv(tarcmd) != 0) {
assert(0);
}
free(tarcommand);
free(param1);
if (rmdir(rename_target)) {
LOG(NULL, "rmdir failed for %s", rename_target);
@@ -125,6 +134,7 @@ static void create_fullfile(struct file *file)
if (rmdir(rename_tmpdir)) {
LOG(NULL, "rmdir failed for %s", rename_tmpdir);
}
free(rename_tmpdir);
free(tmp1);
free(tmp2);
@@ -145,29 +155,38 @@ static void create_fullfile(struct file *file)
/* step 2a: tar it with each compression type */
// lzma
string_or_die(&tarcommand, TAR_COMMAND " --directory=%s " TAR_PERM_ATTR_ARGS " -Jcf %s/%i/files/%s.tar.xz %s",
empty, outdir, file->last_change, file->hash, file->hash);
if (system(tarcommand) != 0) {
LOG(NULL, "Failed to run command:", "%s", tarcommand);
string_or_die(&param1, "--directory=%s", empty);
string_or_die(&param2, "%s/%i/files/%s.tar.xz", outdir, file->last_change, file->hash);
char *const tarlzmacmd[] = { TAR_COMMAND, param1, TAR_PERM_ATTR_ARGS_STRLIST, "-Jcf", param2, file->hash, NULL };
if (system_argv(tarlzmacmd) != 0) {
assert(0);
}
free(tarcommand);
free(param1);
free(param2);
// gzip
string_or_die(&tarcommand, TAR_COMMAND " --directory=%s " TAR_PERM_ATTR_ARGS " -zcf %s/%i/files/%s.tar.gz %s",
empty, outdir, file->last_change, file->hash, file->hash);
if (system(tarcommand) != 0) {
LOG(NULL, "Failed to run command:", "%s", tarcommand);
string_or_die(&param1, "--directory=%s", empty);
string_or_die(&param2, "%s/%i/files/%s.tar.gz", outdir, file->last_change, file->hash);
char *const targzipcmd[] = { TAR_COMMAND, param1, TAR_PERM_ATTR_ARGS_STRLIST, "-zcf", param2, file->hash, NULL };
if (system_argv(targzipcmd) != 0) {
assert(0);
}
free(tarcommand);
free(param1);
free(param2);
#ifdef SWUPD_WITH_BZIP2
string_or_die(&tarcommand, TAR_COMMAND " --directory=%s " TAR_PERM_ATTR_ARGS " -jcf %s/%i/files/%s.tar.bz2 %s",
empty, outdir, file->last_change, file->hash, file->hash);
if (system(tarcommand) != 0) {
LOG(NULL, "Failed to run command:", "%s", tarcommand);
string_or_die(&param1, "--directory=%s", empty);
string_or_die(&param2, "%s/%i/files/%s.tar.bz2", outdir, file->last_change, file->hash);
char *const tarbzip2cmd[] = { TAR_COMMAND, param1, TAR_PERM_ATTR_ARGS_STRLIST, "-jcf", param2, file->hash, NULL };
if (system_argv(tarbzip2cmd) != 0) {
assert(0);
}
free(tarcommand);
free(param1);
free(param2);
#endif
/* step 2b: pick the smallest of the three compression formats */
@@ -303,17 +322,14 @@ void create_fullfiles(struct manifest *manifest)
{
GList *deduped_file_list;
char *path;
char *cmd;
char *conf, *empty;
empty = config_empty_dir();
string_or_die(&cmd, "rm -rf %s", empty);
if (system(cmd) != 0) {
LOG(NULL, "Failed to run command:", "%s", cmd);
char *const rmcmd[] = { "rm", "-rf", empty, NULL };
if (system_argv(rmcmd) != 0) {
assert(0);
}
free(cmd);
g_mkdir_with_parents(empty, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
free(empty);
+13 -16
View File
@@ -21,19 +21,19 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include "swupd.h"
int newversion = -1;
int minversion = 0;
char *format_string = NULL;
unsigned long long int format = 0;
bool enable_signing = false;
char *state_dir = NULL;
@@ -41,20 +41,17 @@ char *packstage_dir = NULL;
char *image_dir = NULL;
char *staging_dir = NULL;
bool set_format_string(char *userinput)
bool set_format(char *userinput)
{
int version;
unsigned long long int user_format;
// expect a positive integer
// format string shall be a positive integer
errno = 0;
version = strtoull(userinput, NULL, 10);
if ((errno < 0) || (version <= 0)) {
user_format = strtoull(userinput, NULL, 10);
if ((errno < 0) || (user_format == 0)) {
return false;
}
if (format_string) {
free(format_string);
}
string_or_die(&format_string, "%d", version);
format = user_format;
return true;
}
@@ -81,8 +78,9 @@ bool set_state_dir(char *dir)
bool init_globals(void)
{
if (format_string == NULL) {
string_or_die(&format_string, "%d", SWUPD_DEFAULT_FORMAT);
if (format == 0) {
printf("Error: Missing format parameter. Please specify a format with -F.\n");
return false;
}
if (!init_state_globals()) {
@@ -101,7 +99,6 @@ bool init_globals(void)
void free_globals(void)
{
free(format_string);
free(state_dir);
free(packstage_dir);
free(image_dir);
+2 -2
View File
@@ -23,11 +23,11 @@
*
*/
#include <assert.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <glib.h>
#include "swupd.h"
+102 -14
View File
@@ -21,19 +21,18 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <errno.h>
#include <glib.h>
#include <unistd.h>
#include "swupd.h"
@@ -102,22 +101,27 @@ void string_or_die(char **strp, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
if (vasprintf(strp, fmt, ap) <= 0) {
if (vasprintf(strp, fmt, ap) < 0) {
assert(0);
}
va_end(ap);
}
void print_elapsed_time(struct timeval *previous_time, struct timeval *current_time)
/* "step" should be a descriptive string for the process that completed before
* this function is called */
void print_elapsed_time(const char *step, struct timeval *previous_time,
struct timeval *current_time)
{
char *elapsed;
assert(strlen(step) > 0);
gettimeofday(current_time, NULL);
elapsed = get_elapsed_time(previous_time, current_time);
if (strcmp(elapsed, " ") == 0) {
printf("\t~0.0 elapsed for Manifest.full creation\n");
printf("\t~0.0 elapsed for '%s' step\n", step);
} else {
printf("\t%s elapsed for full chroot creation\n", elapsed);
printf("\t%s elapsed for '%s' step\n", elapsed, step);
}
previous_time->tv_sec = current_time->tv_sec;
previous_time->tv_usec = current_time->tv_usec;
@@ -149,7 +153,7 @@ int system_argv(char *const argv[])
{
int child_exit_status;
pid_t pid;
int status;
int status = -1;
pid = fork();
@@ -182,9 +186,93 @@ int system_argv(char *const argv[])
LOG(NULL, "Failed to run command:", "%s", cmdline);
free(cmdline);
}
return status;
}
return status;
}
int system_argv_fd(char *const argv[], int newstdin, int newstdout, int newstderr)
{
int child_exit_status;
pid_t pid;
int status = -1;
pid = fork();
if (pid == 0) { /* child */
if (newstdin >= 0) {
if (dup2(newstdin, STDIN_FILENO) == -1) {
LOG(NULL, "Could not redirect stdin", "");
assert(0);
}
close(newstdin);
}
if (newstdout >= 0) {
if (dup2(newstdout, STDOUT_FILENO) == -1) {
LOG(NULL, "Could not redirect stdout", "");
assert(0);
}
close(newstdout);
}
if (newstderr >= 0) {
if (dup2(newstderr, STDERR_FILENO) == -1) {
LOG(NULL, "Could not redirect stderr", "");
assert(0);
}
close(newstderr);
}
execvp(*argv, argv);
LOG(NULL, "This line must not be reached", "");
assert(0);
} else if (pid < 0) {
LOG(NULL, "Failed to fork a child process", "");
assert(0);
} else {
pid_t ws = waitpid(pid, &child_exit_status, 0);
if (ws == -1) {
LOG(NULL, "Failed to wait for child process", "");
assert(0);
}
if (WIFEXITED(child_exit_status)) {
status = WEXITSTATUS(child_exit_status);
} else {
LOG(NULL, "Child process didn't exit", "");
assert(0);
}
if (status != 0) {
char *cmdline = NULL;
concat_str_array(&cmdline, argv);
LOG(NULL, "Failed to run command:", "%s", cmdline);
free(cmdline);
}
}
return status;
}
int system_argv_pipe(char *const argvp1[], int stdinp1, int stderrp1,
char *const argvp2[], int stdoutp2, int stderrp2)
{
int statusp2;
int pipefd[2];
if (pipe(pipefd)) {
LOG(NULL, "Failed to create a pipe", "");
return -1;
}
system_argv_fd(argvp1, stdinp1, pipefd[1], stderrp1);
close(pipefd[1]);
statusp2 = system_argv_fd(argvp2, pipefd[0], stdoutp2, stderrp2);
close(pipefd[0]);
/* Returns the status of the failed process if any
If both processes failed returns the status of first one */
return statusp2;
}
void check_root(void)
+3 -4
View File
@@ -21,13 +21,12 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <glib.h>
#include <unistd.h>
#include "swupd.h"
+8 -8
View File
@@ -22,15 +22,14 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <glib.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <stdarg.h>
#include <sys/time.h>
#include <glib.h>
#include <unistd.h>
#include "swupd.h"
@@ -38,11 +37,12 @@ static FILE *logfile;
static struct timeval start_time;
void init_log(int version)
void init_log(const char *prefix, const char *bundle, int start, int end)
{
char filename[4096];
sprintf(filename, "swupd-server.log.%i", version);
char *filename;
string_or_die(&filename, "%s%s-from-%i-to-%i.log", prefix, bundle, start, end);
logfile = fopen(filename, "w");
free(filename);
gettimeofday(&start_time, NULL);
}
void init_log_stdout(void)
+5 -4
View File
@@ -21,13 +21,12 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <getopt.h>
#include <unistd.h>
#include "swupd.h"
@@ -113,6 +112,8 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
init_log("swupd-make-fullfiles", "", 0, version);
manifest = manifest_from_file(version, "full");
create_fullfiles(manifest);
+10 -14
View File
@@ -21,20 +21,18 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <getopt.h>
#include <getopt.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <getopt.h>
#include <glib.h>
#include <getopt.h>
#include <sys/types.h>
#include <unistd.h>
#include "swupd.h"
@@ -116,10 +114,6 @@ int main(int argc, char **argv)
banner();
check_root();
/* FIXME: should use "end_version" not "0" and a unique filename
init_log(0);
*/
/* Initilize the crypto signature module */
if (!signature_initialize()) {
printf("Can't initialize the crypto signature module!\n");
@@ -141,6 +135,8 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
init_log("swupd-make-pack-", module, start_version, end_version);
printf("Making pack-%s %i to %li\n", module, start_version, end_version);
pack = calloc(1, sizeof(struct packdata));
+267 -48
View File
@@ -23,19 +23,17 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <bsdiff.h>
#include <errno.h>
#include <glib.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <bsdiff.h>
#include <glib.h>
#include <unistd.h>
#include "swupd.h"
#include "xattrs.h"
@@ -101,6 +99,7 @@ struct manifest *alloc_manifest(int version, char *component)
manifest->version = version;
manifest->component = strdup(component);
manifest->format = format;
return manifest;
}
@@ -108,11 +107,13 @@ struct manifest *alloc_manifest(int version, char *component)
struct manifest *manifest_from_file(int version, char *component)
{
FILE *infile;
GList *includes = NULL;
char line[8192], *c, *c2;
int count = 0;
struct manifest *manifest;
char *filename, *conf;
int previous = 0;
unsigned long long int format_number;
conf = config_output_dir();
if (conf == NULL) {
@@ -144,7 +145,9 @@ struct manifest *manifest_from_file(int version, char *component)
return NULL;
}
c = &line[9];
if (strtoull(c, NULL, 10) == 0) {
format_number = strtoull(c, NULL, 10);
if ((errno < 0) || (format_number == 0)) {
//format string shall be a positive integer
printf("Unknown file format version in MANIFEST line: %s\n", c);
fclose(infile);
return NULL;
@@ -178,10 +181,18 @@ struct manifest *manifest_from_file(int version, char *component)
if (strncmp(line, "previous:", 9) == 0) {
previous = strtoull(c, NULL, 10);
}
if (strncmp(line, "includes:", 9) == 0) {
includes = g_list_prepend(includes, strdup(c));
if (!includes->data) {
abort();
}
}
}
manifest = alloc_manifest(version, component);
manifest->format = format_number;
manifest->prevversion = previous;
manifest->includes = includes;
/* empty line */
while (!feof(infile)) {
@@ -509,29 +520,57 @@ int match_manifests(struct manifest *m1, struct manifest *m2)
return count;
}
/* removes all files from m2 from m1 */
static GList *get_unique_includes(struct manifest *manifest)
{
GHashTable *unique_includes = g_hash_table_new(g_str_hash, g_str_equal);
GHashTableIter iter;
GList *includes = NULL;
GList *l1, *l2;
gpointer k, v;
l1 = g_list_first(manifest->includes);
while (l1) {
struct manifest *m = l1->data;
l1 = g_list_next(l1);
(void)g_hash_table_replace(unique_includes, m->component, m);
l2 = get_unique_includes(m);
while (l2) {
struct manifest *m = l2->data;
l2 = g_list_next(l2);
(void)g_hash_table_replace(unique_includes, m->component, m);
}
g_list_free(l2);
}
g_hash_table_iter_init(&iter, unique_includes);
while (g_hash_table_iter_next(&iter, &k, &v)) {
includes = g_list_prepend(includes, v);
}
return includes;
}
/*
* removes all files from m2 from m1
* This will recurse over all included manifests to also
* subtract those from the m1 manifest.
*
* As a special convenient semantics,
* subtract_manifests(M, M)
* will subtract all included manifests from M,
* but will not subtract M from M itself.
*/
void subtract_manifests(struct manifest *m1, struct manifest *m2)
{
GList *list1, *list2;
struct file *file1, *file2;
if (!m1) {
printf("Subtracting manifests failed: No m1 manifest!\n");
return;
}
if (!m2) {
printf("Subtracting manifests failed: No m2 manifest!\n");
return;
}
m1->files = g_list_sort(m1->files, file_sort_filename);
m2->files = g_list_sort(m2->files, file_sort_filename);
list1 = g_list_first(m1->files);
list2 = g_list_first(m2->files);
while (list1 && list2) {
while (list1 && list2 && m1 != m2) {
int ret;
file1 = list1->data;
file2 = list2->data;
@@ -546,15 +585,37 @@ void subtract_manifests(struct manifest *m1, struct manifest *m2)
if (file1->is_deleted == file2->is_deleted && file1->is_file == file2->is_file) {
m1->files = g_list_delete_link(m1->files, todel);
m1->count--;
continue;
}
}
if (ret < 0) {
} else if (ret < 0) {
list1 = g_list_next(list1);
continue;
} else {
list2 = g_list_next(list2);
}
list2 = g_list_next(list2);
}
}
void subtract_manifests_frontend(struct manifest *m1, struct manifest *m2)
{
GList *includes;
struct manifest *m;
if (!m1) {
printf("Subtracting manifests failed: No m1 manifest!\n");
return;
}
if (!m2) {
printf("Subtracting manifests failed: No m2 manifest!\n");
return;
}
subtract_manifests(m1, m2);
includes = get_unique_includes(m2);
while (includes) {
m = includes->data;
includes = g_list_next(includes);
subtract_manifests(m1, m);
}
}
@@ -660,6 +721,7 @@ exit:
/* Returns 0 == success, -1 == failure */
static int write_manifest_plain(struct manifest *manifest)
{
GList *includes;
GList *list;
struct file *file;
FILE *out = NULL;
@@ -667,6 +729,8 @@ static int write_manifest_plain(struct manifest *manifest)
char *conf = config_output_dir();
char *filename = NULL;
char *submanifest_filename = NULL;
char *manifest_tempdir = NULL;
char *tempmanifest = NULL;
int ret = -1;
if (conf == NULL) {
@@ -690,13 +754,19 @@ static int write_manifest_plain(struct manifest *manifest)
goto exit;
}
fprintf(out, "MANIFEST\t%s\n", format_string);
fprintf(out, "MANIFEST\t%llu\n", format);
fprintf(out, "version:\t%i\n", manifest->version);
fprintf(out, "previous:\t%i\n", manifest->prevversion);
fprintf(out, "filecount:\t%i\n", manifest->count);
fprintf(out, "timestamp:\t%i\n", (int)time(NULL));
compute_content_size(manifest);
fprintf(out, "contentsize:\t%llu\n", (long long unsigned int)manifest->contentsize);
includes = manifest->includes;
while (includes) {
struct manifest *sub = includes->data;
includes = g_list_next(includes);
fprintf(out, "includes:\t%s\n", sub->component);
}
fprintf(out, "\n");
list = g_list_first(manifest->files);
@@ -708,24 +778,61 @@ static int write_manifest_plain(struct manifest *manifest)
}
list = g_list_first(manifest->manifests);
string_or_die(&manifest_tempdir, "%s/XXXXXX", state_dir);
if (!mkdtemp(manifest_tempdir)) {
LOG(NULL, "Failed to create temporary directory %s for untarring Manifests", manifest_tempdir);
assert(0);
}
while (list) {
file = list->data;
list = g_list_next(list);
string_or_die(&submanifest_filename, "%s/%i/Manifest.%s", conf, file->last_change, file->filename);
populate_file_struct(file, submanifest_filename);
ret = compute_hash(file, submanifest_filename);
if (file->is_deleted) {
goto write_entry;
}
char *param1, *param2;
/* Untar the Manifest.BUNDLE.tar and calculate the hash on that,
* otherwise we may get incorrect hashes due to owner permissions on
* the files. */
string_or_die(&param1, "%s", manifest_tempdir);
string_or_die(&param2, "%s.tar", submanifest_filename);
char *const tarcmd[] = { TAR_COMMAND, "-C", param1, TAR_PERM_ATTR_ARGS_STRLIST, "-xf", param2, NULL };
ret = system_argv(tarcmd);
free(param1);
free(param2);
if (ret != 0) {
assert(0);
}
string_or_die(&tempmanifest, "%s/Manifest.%s", manifest_tempdir, file->filename);
populate_file_struct(file, tempmanifest);
ret = compute_hash(file, tempmanifest);
if (ret != 0) {
printf("Hash computation failed\n");
assert(0);
}
unlink(tempmanifest);
free(tempmanifest);
write_entry:
fprintf(out, "%s\t%s\t%i\t%s\n", file_type_to_string(file), file->hash, file->last_change, file->filename);
free(submanifest_filename);
}
ret = 0;
exit:
if (manifest_tempdir) {
if (rmdir(manifest_tempdir) != 0) {
LOG(NULL, "rmdir failed for %s: %s", manifest_tempdir, strerror(errno));
}
free(manifest_tempdir);
}
if (out) {
fclose(out);
}
@@ -739,34 +846,37 @@ exit:
static int write_manifest_tar(struct manifest *manifest)
{
char *conf = config_output_dir();
char *tarcmd = NULL;
int ret = -1;
char *directory, *manifesttar, *manifestcomp, *manifestsigned;
int ret = 0;
if (conf == NULL) {
assert(0);
}
string_or_die(&directory, "--directory=%s/%i", conf, manifest->version);
string_or_die(&manifesttar, "%s/%i/Manifest.%s.tar", conf, manifest->version, manifest->component);
string_or_die(&manifestcomp, "Manifest.%s", manifest->component);
string_or_die(&manifestsigned, "Manifest.%s.signed", manifest->component);
/* now, tar the thing up for efficient full file download */
/* and put the signature of the plain manifest into the archive, too */
if (enable_signing) {
string_or_die(&tarcmd, TAR_COMMAND " --directory=%s/%i " TAR_PERM_ATTR_ARGS " -Jcf "
"%s/%i/Manifest.%s.tar Manifest.%s Manifest.%s.signed",
conf, manifest->version, conf, manifest->version, manifest->component,
manifest->component, manifest->component);
char *const tarcmd[] = { TAR_COMMAND, directory, TAR_PERM_ATTR_ARGS_STRLIST, "-Jcf",
manifesttar, manifestcomp, manifestsigned, NULL };
ret = system_argv(tarcmd);
} else {
string_or_die(&tarcmd, TAR_COMMAND " --directory=%s/%i " TAR_PERM_ATTR_ARGS " -Jcf "
"%s/%i/Manifest.%s.tar Manifest.%s",
conf, manifest->version, conf, manifest->version, manifest->component,
manifest->component);
char *const tarcmd[] = { TAR_COMMAND, directory, TAR_PERM_ATTR_ARGS_STRLIST, "-Jcf",
manifesttar, manifestcomp, NULL };
ret = system_argv(tarcmd);
}
if (ret) {
fprintf(stderr, "Creation of Manifest.tar failed\n");
}
if (system(tarcmd) != 0) {
fprintf(stderr, "Creation of Manifest.tar failed\n");
goto exit;
}
ret = 0;
exit:
free(tarcmd);
free(directory);
free(manifesttar);
free(manifestcomp);
free(manifestsigned);
free(conf);
return ret;
}
@@ -814,6 +924,115 @@ void sort_manifest_by_version(struct manifest *manifest)
}
}
bool manifest_includes(struct manifest *manifest, char *component)
{
GList *includes = g_list_first(manifest->includes);
while (includes) {
if (strcmp(((struct manifest *)includes->data)->component,
component) == 0) {
return true;
}
includes = g_list_next(includes);
}
return false;
}
/* This requires the manifest to have the includes sorted.
* The manifests will be sorted when constructed from
* get_sub_manifest_includes (and then replacing the manifest
* strings with actual manifest structs in the same order as
* is done in the main.c's main()).
*/
bool changed_includes(struct manifest *old, struct manifest *new)
{
GList *includes_old = g_list_first(old->includes);
GList *includes_new = g_list_first(new->includes);
if (g_list_length(includes_old) != g_list_length(includes_new)) {
return true;
}
while (includes_old && includes_new) {
char *bundle_old = ((struct manifest *)includes_old->data)->component;
char *bundle_new = ((struct manifest *)includes_new->data)->component;
if (strcmp(bundle_old, bundle_new) != 0) {
return true;
}
includes_old = g_list_next(includes_old);
includes_new = g_list_next(includes_new);
}
return false;
}
/* For a format bump, it's convenient to remove deleted files from manifests
* that last changed prior to the format bump, since they are no longer
* considered for deletion as part of an update.
*
* Note: this function should be called after match_manifests().
*/
int remove_old_deleted_files(struct manifest *m1, struct manifest *m2)
{
GList *list1, *list2;
struct file *file1, *file2;
int count = 0;
if (!m1) {
printf("No old manifest!\n");
return -1;
}
if (!m2) {
printf("No new manifest!\n");
return -1;
}
/* This is the common case, so bail early, reporting no deletions */
if (m1->format == m2->format) {
return 0;
}
/* At this point, the manifest formats mismatch, and it's assumed that
* m1 is the old manifest, and m2 is the new.
*/
m1->files = g_list_sort(m1->files, file_sort_filename);
m2->files = g_list_sort(m2->files, file_sort_filename);
list1 = g_list_first(m1->files);
list2 = g_list_first(m2->files);
while (list1 && list2) {
int ret;
file1 = list1->data;
file2 = list2->data;
ret = strcmp(file1->filename, file2->filename);
if (ret == 0) {
if (file1->is_deleted && file2->is_deleted) {
GList *to_delete = list2;
list1 = g_list_next(list1);
list2 = g_list_next(list2);
m2->files = g_list_delete_link(m2->files, to_delete);
m2->count--;
count++;
continue;
}
list1 = g_list_next(list1);
list2 = g_list_next(list2);
} else if (ret < 0) {
list1 = g_list_next(list1);
} else {
list2 = g_list_next(list2);
}
}
return count;
}
/* Conditionally remove some things from a manifest.
* Returns > 0 when the pruned manifest has new files.
* Returns 0 when the pruned manifest no longer has new files.
@@ -1004,7 +1223,7 @@ static void maximize_version_manifests(struct manifest *m1, struct manifest *m2)
ret = strcmp(file1->filename, file2->filename);
if (ret == 0) {
if (file1->last_change > file2->last_change) {
if (!file1->is_deleted && file1->last_change > file2->last_change) {
LOG(file1, "Update", "Moving %s to version %i", file1->filename, file1->last_change);
file2->last_change = file1->last_change;
}
+98 -53
View File
@@ -24,38 +24,35 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <glib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <glib.h>
#include <sys/types.h>
#include <unistd.h>
#include "swupd.h"
static void empty_pack_stage(int full, int from_version, int to_version, char *module)
{
char *cmd;
char *param;
char *path;
int ret;
// clean any stale data (eg: re-run after a failure)
string_or_die(&cmd, "rm -rf %s/%s/%i_to_%i/", packstage_dir, module,
from_version, to_version);
ret = system(cmd);
if (ret) {
string_or_die(&param, "%s/%s/%i_to_%i/", packstage_dir, module, from_version, to_version);
char *const rmcmd[] = { "rm", "-fr", param, NULL };
if (system_argv(rmcmd) != 0) {
fprintf(stderr, "Failed to clean %s/%s/%i_to_%i\n",
packstage_dir, module, from_version, to_version);
free(cmd);
free(param);
exit(EXIT_FAILURE);
}
free(cmd);
free(param);
if (!full) {
// (re)create module/version/{delta,staged}
@@ -90,7 +87,7 @@ static void explode_pack_stage(int from_version, int to_version, char *module)
}
free(path);
while (1) {
char *path, *tar;
char *path, *param;
int ret;
entry = readdir(dir);
@@ -118,14 +115,12 @@ static void explode_pack_stage(int from_version, int to_version, char *module)
* the resulting pack is slightly smaller, and in addition, we're saving CPU
* time on the client...
*/
string_or_die(&tar, TAR_COMMAND " --directory=%s/%s/%i_to_%i/staged " TAR_WARN_ARGS " "
TAR_PERM_ATTR_ARGS " -xf %s",
packstage_dir, module, from_version, to_version, path);
ret = system(tar);
if (!ret) {
string_or_die(&param, "%s/%s/%i_to_%i/staged", packstage_dir, module, from_version, to_version);
char *const tarcmd[] = { TAR_COMMAND, "-C", param, TAR_WARN_ARGS, TAR_PERM_ATTR_ARGS_STRLIST, "-xf", path, NULL };
if (system_argv(tarcmd) == 0) {
unlink(path);
}
free(tar);
free(param);
free(path);
}
closedir(dir);
@@ -168,21 +163,44 @@ static void make_pack_full_files(struct packdata *pack)
item = g_list_next(item);
if ((!file->peer || file->peer->is_deleted) && !file->is_deleted && !file->rename_peer) {
char *from, *to;
char *fullfrom, *fullto;
/* hardlink each file that is in <end> but not in <X> */
string_or_die(&fullfrom, "%s/%i/full/%s", image_dir, file->last_change, file->filename);
string_or_die(&fullto, "%s/%s/%i_to_%i/staged/%s", packstage_dir,
pack->module, pack->from, pack->to, file->hash);
string_or_die(&from, "%s/%i/files/%s.tar", staging_dir, file->last_change, file->hash);
string_or_die(&to, "%s/%s/%i_to_%i/staged/%s.tar", packstage_dir,
pack->module, pack->from, pack->to, file->hash);
ret = link(from, to);
if (ret) {
if (errno != EEXIST) {
LOG(NULL, "Failure to link", "%s to %s (%s) %i", from, to, strerror(errno), errno);
ret = -1;
errno = 0;
/* Prefer to hardlink uncompressed files (excluding
* directories) first, and fall back to the compressed
* versions if the hardlink fails.
*/
if (!file->is_dir) {
ret = link(fullfrom, fullto);
if (ret && errno != EEXIST) {
LOG(NULL, "Failure to link for fullfile pack", "%s to %s (%s) %i", fullfrom, fullto, strerror(errno), errno);
}
} else {
}
if (ret) {
ret = link(from, to);
if (ret && errno != EEXIST) {
LOG(NULL, "Failure to link for fullfile pack", "%s to %s (%s) %i", from, to, strerror(errno), errno);
}
}
if (ret == 0) {
pack->fullcount++;
}
free(from);
free(to);
free(fullfrom);
free(fullto);
}
}
@@ -236,8 +254,8 @@ static GList *consolidate_packs_delta_files(GList *files, struct packdata *pack)
continue;
}
string_or_die(&from, "%s/%i/delta/%i-%i-%s", staging_dir, file->last_change,
file->peer->last_change, file->last_change, file->hash);
string_or_die(&from, "%s/%i/delta/%i-%i-%s-%s", staging_dir, file->last_change,
file->peer->last_change, file->last_change, file->peer->hash, file->hash);
ret = stat(from, &stat_delta);
if (ret && !find_file_in_list(files, file)) {
@@ -256,7 +274,7 @@ static void create_delta(gpointer data, __unused__ gpointer user_data)
/* if the file was not found in the from version, skip delta creation */
if (file->peer) {
__create_delta(file, file->peer->last_change);
__create_delta(file, file->peer->last_change, file->peer->hash);
}
}
@@ -313,7 +331,7 @@ static int make_final_pack(struct packdata *pack)
GList *item;
struct file *file;
int ret;
char *tar;
char *param1, *param2;
double penalty;
LOG(NULL, "make_final_pack", "%s: %i to %i", pack->module, pack->from, pack->to);
@@ -321,7 +339,7 @@ static int make_final_pack(struct packdata *pack)
item = g_list_first(pack->end_manifest->files);
while (item) {
char *from, *to, *tarfrom, *tarto;
char *from, *to, *tarfrom, *tarto, *fullfrom, *fullto;
struct stat stat_delta, stat_tar;
file = item->data;
@@ -335,15 +353,18 @@ static int make_final_pack(struct packdata *pack)
/* for each file changed since <X> */
/* locate delta, check if the diff it's from is >= <X> */
string_or_die(&from, "%s/%i/delta/%i-%i-%s", staging_dir, file->last_change,
file->peer->last_change, file->last_change, file->hash);
string_or_die(&to, "%s/%s/%i_to_%i/delta/%i-%i-%s", packstage_dir,
string_or_die(&from, "%s/%i/delta/%i-%i-%s-%s", staging_dir, file->last_change,
file->peer->last_change, file->last_change, file->peer->hash, file->hash);
string_or_die(&to, "%s/%s/%i_to_%i/delta/%i-%i-%s-%s", packstage_dir,
pack->module, pack->from, pack->to, file->peer->last_change,
file->last_change, file->hash);
file->last_change, file->peer->hash, file->hash);
string_or_die(&tarfrom, "%s/%i/files/%s.tar", staging_dir,
file->last_change, file->hash);
string_or_die(&tarto, "%s/%s/%i_to_%i/staged/%s.tar", packstage_dir,
pack->module, pack->from, pack->to, file->hash);
string_or_die(&fullfrom, "%s/%i/full/%s", image_dir, file->last_change, file->filename);
string_or_die(&fullto, "%s/%s/%i_to_%i/staged/%s", packstage_dir,
pack->module, pack->from, pack->to, file->hash);
ret = stat(from, &stat_delta);
if (ret) {
@@ -375,13 +396,28 @@ static int make_final_pack(struct packdata *pack)
}
}
} else {
/* include full file in pack */
ret = link(tarfrom, tarto);
if (ret) {
if (errno != EEXIST) {
LOG(NULL, "Failure to link", "%s to %s (%s) %i\n", tarfrom, tarto, strerror(errno), errno);
ret = -1;
errno = 0;
/* Prefer to hardlink uncompressed files (excluding
* directories) first, and fall back to the compressed
* versions if the hardlink fails.
*/
if (!file->is_dir) {
ret = link(fullfrom, fullto);
if (ret && errno != EEXIST) {
LOG(NULL, "Failure to link for final pack", "%s to %s (%s) %i\n", fullfrom, fullto, strerror(errno), errno);
}
} else {
}
if (ret) {
ret = link(tarfrom, tarto);
if (ret && errno != EEXIST) {
LOG(NULL, "Failure to link for final pack", "%s to %s (%s) %i\n", tarfrom, tarto, strerror(errno), errno);
}
}
if (ret == 0) {
pack->fullcount++;
}
}
@@ -390,6 +426,8 @@ static int make_final_pack(struct packdata *pack)
free(to);
free(tarfrom);
free(tarto);
free(fullfrom);
free(fullto);
}
if (pack->fullcount > 0) {
@@ -397,6 +435,8 @@ static int make_final_pack(struct packdata *pack)
explode_pack_stage(pack->from, pack->to, pack->module);
}
char *bundle_delta = NULL;
/* now... link in the Manifest pack */
if (pack->from != 0) {
char *from, *to;
@@ -411,20 +451,23 @@ static int make_final_pack(struct packdata *pack)
create_manifest_delta(pack->from, pack->to, pack->module);
}
string_or_die(&to, "%s/%s/%i_to_%i/Manifest-%s-delta-from-%i", packstage_dir,
pack->module, pack->from, pack->to, pack->module, pack->from);
ret = link(from, to);
if (ret) {
LOG(NULL, "Failed to link", "Manifest-delta-from-%i", pack->from);
LOG(NULL, "Failed to link", "Manifest-%s-delta-from-%i (%s)", pack->module, pack->from, strerror(errno));
} else {
string_or_die(&bundle_delta, "Manifest-%s-delta-from-%i", pack->module, pack->from);
}
free(from);
free(to);
}
/* now... link in the MoM Manifest into the base pack */
char *mom_delta = NULL;
/* now... link in the MoM Manifest into the os-core pack */
if ((pack->from != 0) && (strcmp(pack->module, "os-core") == 0)) {
char *from, *to;
struct stat st;
@@ -442,7 +485,9 @@ static int make_final_pack(struct packdata *pack)
ret = link(from, to);
if (ret) {
LOG(NULL, "Failed to link", "Manifest-delta-from-%i", pack->from);
LOG(NULL, "Failed to link", "Manifest-MoM-delta-from-%i (%s)", pack->from, strerror(errno));
} else {
string_or_die(&mom_delta, "Manifest-MoM-delta-from-%i", pack->from);
}
free(from);
@@ -451,15 +496,15 @@ static int make_final_pack(struct packdata *pack)
/* tar the staging directory up */
LOG(NULL, "starting tar for pack", "%s: %i to %i", pack->module, pack->from, pack->to);
string_or_die(&tar, TAR_COMMAND " " TAR_PERM_ATTR_ARGS " --directory=%s/%s/%i_to_%i/ "
"--numeric-owner -Jcf %s/%i/pack-%s-from-%i.tar delta staged",
packstage_dir, pack->module, pack->from, pack->to, staging_dir, pack->to,
pack->module, pack->from);
ret = system(tar);
free(tar);
string_or_die(&param1, "%s/%s/%i_to_%i/", packstage_dir, pack->module, pack->from, pack->to);
string_or_die(&param2, "%s/%i/pack-%s-from-%i.tar", staging_dir, pack->to, pack->module, pack->from);
char *const tarcmd[] = { TAR_COMMAND, "-C", param1, TAR_PERM_ATTR_ARGS_STRLIST, "--numeric-owner", "-Jcf", param2, "delta", "staged", bundle_delta, mom_delta, NULL };
ret = system_argv(tarcmd);
free(param1);
free(param2);
LOG(NULL, "finished tar for pack", "%s: %i to %i", pack->module, pack->from, pack->to);
/* FIXME: this is a hack workaround, needs diagnosed and removed */
if ((ret != 0) && (ret != 256)) {
if ((ret != 0) && (ret != 1)) {
fprintf(stderr, "Unexpected return value (%d) creating tar of pack %s from %i to %i\n",
ret, pack->module, pack->from, pack->to);
} else {
+6 -6
View File
@@ -22,16 +22,16 @@
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <glib.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "swupd.h"
+14 -12
View File
@@ -21,6 +21,7 @@
*/
#define _GNU_SOURCE
#include <err.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
@@ -29,16 +30,11 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <err.h>
#include "swupd.h"
static char *make_filename(const char *, const char *, const char *);
static const char *CMD_FMT = "openssl smime -sign -in %s -binary "
"-out %s.signed -outform PEM -md sha256 -inkey %s -signer %s "
"-certfile %s -passin file:%s";
static char *leaf_key = NULL;
static char *leaf_cert = NULL;
static char *ca_chain_cert = NULL;
@@ -150,7 +146,7 @@ void signature_terminate(void)
*/
bool signature_sign(const char *filename)
{
char *cmd = NULL;
char *param1, *param2;
int status;
if (!enable_signing) {
@@ -160,12 +156,18 @@ bool signature_sign(const char *filename)
if (!initialized) {
return false;
}
string_or_die(&cmd, CMD_FMT, filename, filename, leaf_key, leaf_cert,
ca_chain_cert, passphrase);
status = system(cmd);
if (status) {
printf("Bad status %d from signing command:%s\n", status, cmd);
string_or_die(&param1, "%s.signed", filename);
string_or_die(&param2, "file:%s", passphrase);
char *const opensslcmd[] = { "openssl", "smime", "-sign", "-in", (char *)filename, "-binary",
"-out", param1, "-outform", " PEM", "-md", "sha256", "-inkey",
leaf_key, "-signer", leaf_cert, "-certfile", ca_chain_cert,
"-passin", param2, NULL };
status = system_argv(opensslcmd);
if (status != 0) {
printf("Bad status %d from signing command\n", status);
}
free(cmd);
free(param1);
free(param2);
return status == 0;
}
+3 -4
View File
@@ -22,13 +22,12 @@
*/
#define _GNU_SOURCE
#include <assert.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <glib.h>
#include <unistd.h>
#include "swupd.h"
+47 -19
View File
@@ -23,17 +23,17 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <sys/stat.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "swupd.h"
@@ -127,35 +127,63 @@ void ensure_version_image_exists(int version)
void write_cookiecrumbs_to_download_area(int version)
{
char *conf;
char *cmd;
char *filename, *strformat;
FILE *versionfd, *formatfd;
conf = config_output_dir();
if (conf == NULL) {
assert(0);
}
string_or_die(&cmd, "echo %s > %s/%i/swupd-server-src-version", VERSION, conf, version);
if (system(cmd) != 0) {
string_or_die(&filename, "%s/%i/swupd-server-src-version", conf, version);
versionfd = fopen(filename, "w");
if (versionfd == NULL) {
assert(0);
}
free(cmd);
string_or_die(&cmd, "echo %s > %s/%i/format", format_string, conf, version);
if (system(cmd) != 0) {
if (fwrite(VERSION, 1, strlen(VERSION), versionfd) != strlen(VERSION)) {
assert(0);
}
free(cmd);
fclose(versionfd);
free(filename);
/* written from pack_maker.sh */
string_or_die(&filename, "%s/%i/format", conf, version);
string_or_die(&strformat, "%llu", format);
formatfd = fopen(filename, "w");
if (formatfd == NULL) {
assert(0);
}
if (fwrite(strformat, 1, strlen(strformat), formatfd) != strlen(strformat)) {
assert(0);
}
fclose(formatfd);
free(filename);
free(strformat);
/* Updating the WEBDIR/version/formatN/latest file is an operation very closely tied to a DevOps
* workflow and not something swupd should make a decision about.
*
* The supported format values (replacing the "N" in the path above) are:
*
* - "staging": intended for testing only
* - [1-+inf] (positive integer): the number that a corresponding version of swupd-client
* understands to run software updates. For example, if a given swupd-client release understands
* format 1, then WEBDIR/version/format1/latest contains the value of most recent release that
* that swupd-client can update to.
*
* Adapt this step appropriately for your DevOps flow.
*/
#if 0
FILE *file;
char *fullfile = NULL;
char *param;
string_or_die(&cmd, "mkdir -p %s/version/formatstaging/", conf);
if (system(cmd) != 0) {
string_or_die($param, "%s/version/formatstaging/", conf);
char *const mkdircmd[] = { "mkdir", "-p", param, NULL };
if (system_argv(mkdircmd) != 0) {
assert(0);
}
free(cmd);
free(param);
string_or_die(&fullfile, "%s/version/formatstaging/latest", conf);
file = fopen(fullfile, "w");
+5 -5
View File
@@ -20,15 +20,15 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <sys/xattr.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/xattr.h>
#include "swupd.h"
#include "xattrs.h"
@@ -1,23 +1,25 @@
#!/usr/bin/env bats
load "../swupdlib"
@test "create_update help output" {
run $srcdir/swupd_create_update --help
run $CREATE_UPDATE --help
[ "$status" -eq 1 ]
run $srcdir/swupd_create_update -h
run $CREATE_UPDATE -h
[ "$status" -eq 1 ]
}
@test "make_fullfiles help output" {
run $srcdir/swupd_make_fullfiles --help
run $MAKE_FULLFILES --help
[ "$status" -eq 1 ]
run $srcdir/swupd_make_fullfiles -h
run $MAKE_FULLFILES -h
[ "$status" -eq 1 ]
}
@test "make_pack help output" {
run $srcdir/swupd_make_pack --help
run $MAKE_PACK --help
[ "$status" -eq 1 ]
run $srcdir/swupd_make_pack -h
run $MAKE_PACK -h
[ "$status" -eq 1 ]
}
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bats
# common functions
load "../swupdlib"
setup() {
clean_test_dir
init_test_dir
init_server_ini
set_latest_ver 0
init_groups_ini os-core test-bundle1 test-bundle2
set_os_release 10 os-core
set_os_release 10 test-bundle1
set_os_release 10 test-bundle2
track_bundle 10 os-core
track_bundle 10 test-bundle1
track_bundle 10 test-bundle2
set_os_release 20 os-core
set_os_release 20 test-bundle1
set_os_release 20 test-bundle2
track_bundle 20 os-core
track_bundle 20 test-bundle1
track_bundle 20 test-bundle2
gen_file_plain 10 test-bundle1 foo
gen_file_plain 10 test-bundle2 foo
gen_file_plain 20 test-bundle1 foo
}
@test "delete no version bump update creation" {
sudo $CREATE_UPDATE --osversion 10 --statedir $DIR --format 3
sudo $MAKE_FULLFILES --statedir $DIR 10
set_latest_ver 10
sudo $CREATE_UPDATE --osversion 20 --statedir $DIR --format 3
sudo $MAKE_FULLFILES --statedir $DIR 20
[ 1 -eq $(grep '10 /foo' $DIR/www/10/Manifest.full | wc -l) ]
[ 1 -eq $(grep '10 /foo' $DIR/www/20/Manifest.full | wc -l) ]
[ 0 -eq $(grep '20 /foo' $DIR/www/20/Manifest.full | wc -l) ]
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bats
# common functions
load "../swupdlib"
setup() {
clean_test_dir
init_test_dir
init_server_ini
set_latest_ver 0
init_groups_ini os-core
set_os_release 10 os-core
track_bundle 10 os-core
gen_file_plain 10 os-core "semicolon;"
}
assert_illegal_char() {
local output="$1"
local str=$(echo "Filename $2 includes illegal character(s)")
[[ "$output" =~ "$str" ]]
}
assert_valid_char() {
local output="$1"
local str=$(echo "Filename $2 includes illegal character(s)")
[[ ! "$output" =~ "$str" ]]
}
@test "file names with blacklisted characters" {
run sudo sh -c "$CREATE_UPDATE --osversion 10 --statedir $DIR --format 3"
echo "$output"
assert_illegal_char "$output" "/semicolon;"
assert_valid_char "$output" "/usr"
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
-58
View File
@@ -1,58 +0,0 @@
#!/usr/bin/env bats
# common functions
load swupdlib
setup() {
DIR=$(init_web_dir "$srcdir/web-dir")
export DIR
init_server_ini
set_latest_ver 0
init_groups_ini os-core test-bundle
set_os_release 10 os-core
track_bundle 10 os-core
track_bundle 10 test-bundle
set_os_release 20 os-core
track_bundle 20 os-core
track_bundle 20 test-bundle
gen_file_to_delta 10 4096 20 4 test-bundle
}
@test "full run update creation with delta packs" {
# build the first version
sudo $srcdir/swupd_create_update --osversion 10 --statedir $DIR
sudo $srcdir/swupd_make_fullfiles --statedir $DIR 10
sudo $srcdir/swupd_make_pack --statedir $DIR 0 10 os-core
sudo $srcdir/swupd_make_pack --statedir $DIR 0 10 test-bundle
set_latest_ver 10
# then the second version...
sudo $srcdir/swupd_create_update --osversion 20 --statedir $DIR
sudo $srcdir/swupd_make_fullfiles --statedir $DIR 20
sudo $srcdir/swupd_make_pack --statedir $DIR 0 20 os-core
sudo $srcdir/swupd_make_pack --statedir $DIR 0 20 test-bundle
# and with delta packs this time
sudo $srcdir/swupd_make_pack --statedir $DIR 10 20 os-core
sudo $srcdir/swupd_make_pack --statedir $DIR 10 20 test-bundle
# zero packs should exist (non-zero size) for both versions
[ -s $DIR/www/10/pack-os-core-from-0.tar ]
[ -s $DIR/www/10/pack-test-bundle-from-0.tar ]
[ -s $DIR/www/20/pack-os-core-from-0.tar ]
[ -s $DIR/www/20/pack-test-bundle-from-0.tar ]
# and delta packs should exist (non-zero size) for the latest version
[ -s $DIR/www/20/pack-os-core-from-10.tar ]
[ -s $DIR/www/20/pack-test-bundle-from-10.tar ]
}
teardown() {
sudo rm -rf $DIR
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env bats
# common functions
load "../swupdlib"
setup() {
clean_test_dir
init_test_dir
init_server_ini
set_latest_ver 0
init_groups_ini os-core test-bundle included included-two included-nested
set_os_release 10 os-core
track_bundle 10 os-core
track_bundle 10 test-bundle
set_os_release 20 os-core
track_bundle 20 os-core
track_bundle 20 test-bundle
track_bundle 20 included
track_bundle 20 included-two
track_bundle 20 included-nested
gen_file_to_delta 10 4096 20 4 test-bundle
gen_file_plain 10 test-bundle foo
gen_file_plain 10 test-bundle foobarbaz
gen_file_plain 20 test-bundle foo
gen_file_plain 20 included foo
gen_file_plain 20 included-two foo
gen_file_plain 20 included-two foobar
gen_file_plain 20 included-nested foobarbaz
gen_includes_file test-bundle 20 included included-two
gen_includes_file included 20 included-nested
}
@test "full run update creation with delta packs" {
# build the first version
sudo $CREATE_UPDATE --osversion 10 --statedir $DIR --format 3
sudo $MAKE_FULLFILES --statedir $DIR 10
sudo $MAKE_PACK --statedir $DIR 0 10 os-core
sudo $MAKE_PACK --statedir $DIR 0 10 test-bundle
set_latest_ver 10
# then the second version...
sudo $CREATE_UPDATE --osversion 20 --statedir $DIR --format 3
sudo $MAKE_FULLFILES --statedir $DIR 20
sudo $MAKE_PACK --statedir $DIR 0 20 os-core
sudo $MAKE_PACK --statedir $DIR 0 20 test-bundle
# and with delta packs this time
sudo $MAKE_PACK --statedir $DIR 10 20 os-core
sudo $MAKE_PACK --statedir $DIR 10 20 test-bundle
# zero packs should exist (non-zero size) for both versions
[ -s $DIR/www/10/pack-os-core-from-0.tar ]
[ -s $DIR/www/10/pack-test-bundle-from-0.tar ]
[ -s $DIR/www/20/pack-os-core-from-0.tar ]
[ -s $DIR/www/20/pack-test-bundle-from-0.tar ]
# and delta packs should exist (non-zero size) for the latest version
[ -s $DIR/www/20/pack-os-core-from-10.tar ]
[ -s $DIR/www/20/pack-test-bundle-from-10.tar ]
[[ 1 -eq $(grep '^includes: os-core$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/foo$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/foobarbaz$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 0 -eq $(grep '/foobar$' $DIR/www/20/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '^includes: os-core$' $DIR/www/20/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '^includes: included$' $DIR/www/20/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '^includes: included-two$' $DIR/www/20/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '^.d.. 0000000000000000000000000000000000000000000000000000000000000000 20 /foo$' $DIR/www/20/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '^.d.. 0000000000000000000000000000000000000000000000000000000000000000 20 /foobarbaz$' $DIR/www/20/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/foo$' $DIR/www/20/Manifest.included | wc -l) ]]
[[ 1 -eq $(grep '/foo$' $DIR/www/20/Manifest.included-two | wc -l) ]]
[[ 1 -eq $(grep '/foobar$' $DIR/www/20/Manifest.included-two | wc -l) ]]
[[ 1 -eq $(grep '/foobarbaz$' $DIR/www/20/Manifest.included-nested | wc -l) ]]
[[ 6 -eq $(tar -tf $DIR/www/10/pack-test-bundle-from-0.tar | wc -l) ]]
[[ 4 -eq $(tar -tf $DIR/www/20/pack-test-bundle-from-0.tar | wc -l) ]]
# delta packs should contain appropriate delta manifests
[[ $(tar -tf $DIR/www/20/pack-os-core-from-10.tar | grep '^Manifest-os-core-delta-from-10') ]]
[[ $(tar -tf $DIR/www/20/pack-os-core-from-10.tar | grep '^Manifest-MoM-delta-from-10') ]]
[[ $(tar -tf $DIR/www/20/pack-test-bundle-from-10.tar | grep '^Manifest-test-bundle-delta-from-10') ]]
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
-35
View File
@@ -1,35 +0,0 @@
#!/usr/bin/env bats
# common functions
load swupdlib
setup() {
DIR=$(init_web_dir "$srcdir/web-dir")
export DIR
init_server_ini
set_latest_ver 0
init_groups_ini os-core test-bundle
set_os_release 10 os-core
set_os_release 10 test-bundle
track_bundle 10 os-core
track_bundle 10 test-bundle
}
@test "full run update creation" {
sudo $srcdir/swupd_create_update --osversion 10 --statedir $DIR
sudo $srcdir/swupd_make_fullfiles --statedir $DIR 10
sudo $srcdir/swupd_make_pack --statedir $DIR 0 10 os-core
sudo $srcdir/swupd_make_pack --statedir $DIR 0 10 test-bundle
# zero packs should exist (non-zero size) for the build
[ -s $DIR/www/10/pack-os-core-from-0.tar ]
[ -s $DIR/www/10/pack-test-bundle-from-0.tar ]
}
teardown() {
sudo rm -rf $DIR
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bats
# common functions
load "../swupdlib"
setup() {
clean_test_dir
init_test_dir
init_server_ini
set_latest_ver 0
init_groups_ini os-core test-bundle
set_os_release 10 os-core
set_os_release 10 test-bundle
track_bundle 10 os-core
track_bundle 10 test-bundle
gen_file_plain 10 test-bundle foo
}
@test "full run update creation" {
sudo $CREATE_UPDATE --osversion 10 --statedir $DIR --format 3
sudo $MAKE_FULLFILES --statedir $DIR 10
sudo $MAKE_PACK --statedir $DIR 0 10 os-core
sudo $MAKE_PACK --statedir $DIR 0 10 test-bundle
# zero packs should exist (non-zero size) for the build
[ -s $DIR/www/10/pack-os-core-from-0.tar ]
[ -s $DIR/www/10/pack-test-bundle-from-0.tar ]
[[ 1 -eq $(grep '^includes: os-core$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/usr/share/clear/bundles/test-bundle$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/foo$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/usr/share/clear/bundles/os-core$' $DIR/www/10/Manifest.os-core | wc -l) ]]
[[ 1 -eq $(grep '/usr$' $DIR/www/10/Manifest.os-core | wc -l) ]]
[[ 1 -eq $(grep '/usr/lib$' $DIR/www/10/Manifest.os-core | wc -l) ]]
[[ 1 -eq $(grep '/usr/share$' $DIR/www/10/Manifest.os-core | wc -l) ]]
[[ 1 -eq $(grep '/usr/share/clear$' $DIR/www/10/Manifest.os-core | wc -l) ]]
[[ 1 -eq $(grep '/usr/share/clear/bundles$' $DIR/www/10/Manifest.os-core | wc -l) ]]
[[ 4 -eq $(tar -tf $DIR/www/10/pack-test-bundle-from-0.tar | wc -l) ]]
[[ 5 -eq $(tar -tf $DIR/www/10/pack-os-core-from-0.tar | wc -l) ]]
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -1,18 +1,20 @@
#!/usr/bin/env bats
load "../swupdlib"
@test "make_fullfiles required arg" {
run $srcdir/swupd_make_fullfiles
run $MAKE_FULLFILES
[ "$status" -eq 1 ]
}
@test "make_fullfiles too many arguments" {
# exactly one argument must be passed
run $srcdir/swupd_make_fullfiles foo bar
run $MAKE_FULLFILES foo bar
[ "$status" -eq 1 ]
}
@test "make_fullfiles root priv check" {
run $srcdir/swupd_make_fullfiles foo
run $MAKE_FULLFILES foo
[ "$status" -eq 1 ]
[[ "$output" =~ "not being run as root.. exiting" ]]
}
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env bats
# common functions
load "../swupdlib"
setup() {
clean_test_dir
init_test_dir
init_server_ini
set_latest_ver 0
init_groups_ini os-core test-bundle included included-two included-nested
set_os_release 10 os-core
track_bundle 10 os-core
track_bundle 10 test-bundle
set_os_release 20 os-core
track_bundle 20 os-core
track_bundle 20 test-bundle
track_bundle 20 included
track_bundle 20 included-two
set_os_release 30 os-core
track_bundle 30 os-core
track_bundle 30 test-bundle
track_bundle 30 included
track_bundle 30 included-two
track_bundle 30 included-nested
gen_file_plain 10 test-bundle foo
gen_file_plain 20 test-bundle foo
gen_file_plain 20 included bar
gen_file_plain 20 included-two baz
gen_file_plain 30 test-bundle foo
gen_file_plain 30 included bar
gen_file_plain 30 included-two baz
gen_file_plain 30 included-nested foobarbaz
gen_includes_file test-bundle 20 included included-two
gen_includes_file test-bundle 30 included included-two
gen_includes_file included 30 included-nested
}
@test "full run update creation with delta packs" {
# build the first version
sudo $CREATE_UPDATE --osversion 10 --statedir $DIR --format 3
sudo $MAKE_FULLFILES --statedir $DIR 10
sudo $MAKE_PACK --statedir $DIR 0 10 os-core
sudo $MAKE_PACK --statedir $DIR 0 10 test-bundle
set_latest_ver 10
# then the second version...
sudo $CREATE_UPDATE --osversion 20 --statedir $DIR --format 3
sudo $MAKE_FULLFILES --statedir $DIR 20
sudo $MAKE_PACK --statedir $DIR 0 20 os-core
sudo $MAKE_PACK --statedir $DIR 0 20 test-bundle
sudo $MAKE_PACK --statedir $DIR 0 20 included
sudo $MAKE_PACK --statedir $DIR 0 20 included-two
set_latest_ver 20
# then the third version...
sudo $CREATE_UPDATE --osversion 30 --statedir $DIR --format 3
sudo $MAKE_FULLFILES --statedir $DIR 30
sudo $MAKE_PACK --statedir $DIR 0 30 os-core
sudo $MAKE_PACK --statedir $DIR 0 30 test-bundle
sudo $MAKE_PACK --statedir $DIR 0 30 included
sudo $MAKE_PACK --statedir $DIR 0 30 included-two
sudo $MAKE_PACK --statedir $DIR 0 30 included-nested
# zero packs should exist (non-zero size) for both versions
[ -s $DIR/www/10/pack-os-core-from-0.tar ]
[ -s $DIR/www/10/pack-test-bundle-from-0.tar ]
[ -s $DIR/www/20/pack-os-core-from-0.tar ]
[ -s $DIR/www/20/pack-test-bundle-from-0.tar ]
[ -s $DIR/www/20/pack-included-from-0.tar ]
[ -s $DIR/www/20/pack-included-two-from-0.tar ]
[ -s $DIR/www/30/pack-os-core-from-0.tar ]
[ -s $DIR/www/30/pack-test-bundle-from-0.tar ]
[ -s $DIR/www/30/pack-included-from-0.tar ]
[ -s $DIR/www/30/pack-included-two-from-0.tar ]
[ -s $DIR/www/30/pack-included-nested-from-0.tar ]
[[ 1 -eq $(grep '^includes: os-core$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/foo$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '^includes: os-core$' $DIR/www/20/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '^includes: included$' $DIR/www/20/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '^includes: included-two$' $DIR/www/20/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/bar$' $DIR/www/20/Manifest.included | wc -l) ]]
[[ 1 -eq $(grep '/baz$' $DIR/www/20/Manifest.included-two | wc -l) ]]
[[ 1 -eq $(grep '^includes: included-nested$' $DIR/www/30/Manifest.included | wc -l) ]]
[[ 1 -eq $(grep '/foobarbaz$' $DIR/www/30/Manifest.included-nested | wc -l) ]]
[[ 0 -eq $(ls $DIR/www/30/Manifest.test-bundle | wc -l) ]]
[[ 0 -eq $(ls $DIR/www/30/Manifest.included-two | wc -l) ]]
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -1,24 +1,26 @@
#!/usr/bin/env bats
load "../swupdlib"
@test "make_pack required arg" {
run $srcdir/swupd_make_pack
run $MAKE_PACK
[ "$status" -eq 1 ]
}
@test "make_pack too few arguments" {
run $srcdir/swupd_make_pack foo
run $MAKE_PACK foo
[ "$status" -eq 1 ]
run $srcdir/swupd_make_pack foo bar
run $MAKE_PACK foo bar
[ "$status" -eq 1 ]
}
@test "make_pack too many arguments" {
run $srcdir/swupd_make_pack foo bar foo bar
run $MAKE_PACK foo bar foo bar
[ "$status" -eq 1 ]
}
@test "make_pack root priv check" {
run $srcdir/swupd_make_pack foo bar foo
run $MAKE_PACK foo bar foo
[ "$status" -eq 1 ]
[[ "$output" =~ "not being run as root.. exiting" ]]
}
+52 -6
View File
@@ -1,14 +1,28 @@
# NOTE: source this file from a *.bats file
init_web_dir() {
# absolute path is a hard requirement right now
local dir=$(realpath $1)
mkdir -p $dir/{image,www}
echo $dir
# The location of the swupd_* binaries
export SRCDIR="$BATS_TEST_DIRNAME/../../../"
export CREATE_UPDATE="$SRCDIR/swupd_create_update"
export MAKE_FULLFILES="$SRCDIR/swupd_make_fullfiles"
export MAKE_PACK="$SRCDIR/swupd_make_pack"
export DIR="$BATS_TEST_DIRNAME/web-dir"
init_test_dir() {
local testdir="$BATS_TEST_DIRNAME"
mkdir -p "$testdir"/logs
mkdir -p $DIR/{image,www}
# run swupd_* inside the directory to dump the logs
cd "$testdir"/logs
}
clean_test_dir() {
sudo rm -rf $DIR "$BATS_TEST_DIRNAME"/logs
}
init_server_ini() {
cp $srcdir/server.ini $DIR
cp $SRCDIR/server.ini $DIR
sed -i "s|/var/lib/update|$DIR|" $DIR/server.ini
}
@@ -39,6 +53,18 @@ track_bundle() {
touch $DIR/image/$ver/$bundle/usr/share/clear/bundles/$bundle
}
gen_includes_file() {
local bundle=$1
local ver=$2
local includes="${@:3}"
mkdir -p $DIR/www/$ver/noship
for b in $includes; do
cat >> $DIR/www/$ver/noship/"$bundle"-includes << EOF
$b
EOF
done
}
gen_file_to_delta() {
local origver=$1
local origsize=$2
@@ -58,4 +84,24 @@ gen_file_to_delta() {
rm $TMP
}
gen_file_plain() {
local ver=$1
local bundle=$2
local name="$3"
# Add plain text file into a bundle
mkdir -p $DIR/image/$ver/$bundle
echo "$name" > $DIR/image/$ver/$bundle/"$name"
}
gen_file_plain_change() {
local ver=$1
local bundle=$2
local name="$3"
# Add plain text file into a bundle
mkdir -p $DIR/image/$ver/$bundle
echo "$ver $name" > $DIR/image/$ver/$bundle/"$name"
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -1,13 +1,21 @@
#!/usr/bin/env bats
@test "create_update required arg" {
run $srcdir/swupd_create_update
load "../swupdlib"
@test "create_update required format" {
run $CREATE_UPDATE
[ "$status" -eq 1 ]
[[ "$output" =~ "Missing format parameter" ]]
}
@test "create_update required version" {
run $CREATE_UPDATE -F 3
[ "$status" -eq 1 ]
[[ "$output" =~ "Missing version parameter:" ]]
}
@test "create_update root priv check" {
run $srcdir/swupd_create_update -o 10
run $CREATE_UPDATE -F 3 -o 10
[ "$status" -eq 1 ]
[[ "$output" =~ "not being run as root.. exiting" ]]
}