Compare commits

...
30 Commits
Author SHA1 Message Date
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
Patrick McCarty fa124fb19e Release v3.1.0
This release adds support for bsdtar (compile-time option), enables
parallel building of delta packs with pack_maker.sh, adds an initial
functional test suite, and addresses a few bugs:

- Makes parallel pack generation more robust when building packs for
  multiple versions simultaneously.

- Fixes basic_creator.sh to work properly on first run.

- Removes an unneeded -a option passed to tar, and fixes tar argument
  ordering (files always after options).

- Makes hash calculation always account for xattrs, since swupd-client
  unconditionally accounts for them.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-17 12:48:56 -07:00
Patrick McCarty 3d4e172c22 Update the gitignore
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-17 12:33:25 -07:00
Patrick McCarty 115a7f444e Add missing free() for a memory allocation
Even though swupd_make_pack will exit immediately in the event this
error occurs, calling free() here will be needed if the error handling
ever changes (e.g. returning from the function instead of exiting).

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-17 12:24:44 -07:00
Patrick McCarty 5ba47aa150 test: add basic checks to ensure packs have been created
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-17 12:22:33 -07:00
Patrick McCarty 4e6fb28d0a Improve parallel pack generation
Because pack generation is a time-consuming task, running this task in
parallel is preferable.

However, if we are generating two or more packs with the same "from"
version at the same time, the multiple jobs will use the same pack
staging directory, leading to corruption.

My solution for now is to use a staging dir with a name derived from
both "from" and "to" versions so that there are no collisions.

A long-term fix will be to implement some kind of locking mechanism to
prevent *identical* packs from being generated simultaneously, but for
now, using more unique staging directories will improve the situation.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-17 11:58:49 -07:00
Dmitry Rozhkov d6153973fe Add compatibility with libarchive's bsdtar command
Since GNU tar fails to extract files with xattrs preserved when
Integrity Measurement Architecture (IMA) is enabled some vendors
may choose to install libarchive-based tar (bsdtar) on their embedded
devices, so the swupd server needs to be able to create archives
in its format.

This patch adds one compile-time options --enable-bsdtar that is used
to enable/disable GNU tar specific options. Also it harmonizes
the command strings to be compatible with both GNU tar and bsdtar.
Particularly it
- changes --exclude pattern from '%s'/* to more explicit '%s/?*' because
  bsdtar's pattern matching is greedier than in tar: it uses tcsh's
  globbing where '*' can be anything including the null string and the
  original pattern would include the directory itself;
- OS file names are escaped with leading ./ to avoid collisions with
  file names starting with @ which has special meaning in bsdtar.

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
2016-03-09 13:13:02 +02:00
Patrick McCarty 5acb4c394c test: set latest.version to new value in the latest test
The latest.version file should generally be updated after the most
recent build completes, so bump it to 10 after the build completes for
version 10 in this test.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-08 22:37:56 -08:00
Patrick McCarty 6ba28bc7a9 Add a functional test that creates delta packs
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-08 22:23:59 -08:00
Patrick McCarty e653bdd50a Add initial functional test suite
The test suite uses BATS to emit TAP and the Automake TAP driver to
consume the output.

Most of the tests are basic, and full-run.bats creates a minimal update
using autogenerated chroot content.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-08 21:28:15 -08:00
Patrick McCarty 1cf0b2b316 Validate argument counts immediately after option parsing
Similar to how swupd_create_update handles argc/argv, swupd_make_pack
and swupd_make_fullfiles should validate the argument count before
checking for root privileges, etc.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-08 20:00:28 -08:00
Dmitry Rozhkov 71e2abe1af Always use xattrs when calculating file hashes
Currently swupd-client includes xattrs to hash sums of all files.
Therefore in order to avoid relaxing security and to prevent
`swupd verify` from reporting hash mismatches for updated files
it's better to include xattrs to hashes for all files.

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
2016-03-08 14:00:31 -08:00
Patrick McCarty 3044d8c51b Initial run of clang-format
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-03 08:39:11 -08:00
Patrick McCarty eef6afe2f1 Prepare for running clang-format
Some of the existing comments cause clang-format to reformat them
strangely, so modify them to something more expected by the tool.

Also, the tool may decide to "join" several lines of concatenated string
literals if a line begins with a macro string literal. That's not
wanted, so fix up that case too.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-03 08:39:11 -08:00
Patrick McCarty 71ced644d7 Add clang-format style file
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-03 08:39:11 -08:00
Patrick McCarty 1b4f0a7a3b Correctly set formatstaging/latest on first run
On first run, the formatstaging/latest does not exist, so make sure we
create it and initialize it properly.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-02 15:43:58 -08:00
Patrick McCarty d3004e6a9e Fix a shell syntax error
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-02 15:43:28 -08:00
Patrick McCarty 101c91c681 Read latest.version after creating groups.ini
The mk_groups_ini.sh script instantiates the latest.version file on
first run, so make sure we read contents after that point.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-02 15:42:12 -08:00
Patrick McCarty afa886e6a8 Fix error reporting for incorrect minversion
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-02 15:13:13 -08:00
Patrick McCarty 8911378049 Substitute correct values for installed server.ini
In case the user overrides UPDATEDIR in the environment, make sure the
installed server.ini reflects the overridden value.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-02 08:28:55 -08:00
Patrick McCarty f2330266b8 Build packs in parallel in pack_maker.sh
The necessary waits needed for the backgrounded processes is already
implemented, so simply throw swupd_make_pack processes into the
background for faster build times.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-02 08:20:09 -08:00
Patrick McCarty 27271d3d2b Use --statedir in the builder scripts
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-02 08:11:07 -08:00
Patrick McCarty 26892177e6 Align variable default values in builder scripts
Also, make some of the variables overridable in the environment.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-03-02 08:09:07 -08:00
Patrick McCarty 2bb1136607 Add code coverage support
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-02-29 13:21:28 -08:00
Dmitry Rozhkov 39ed685be2 Clean up tar commands: always put files after options
Unify tar commands to have files enumerated always at the end of
the commands. This would follow the scheme used in tar's man page
and simplify adoption of other tar implementation should the need
arise.

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
2016-02-24 12:44:12 -08:00
Dmitry Rozhkov d024492a20 Clean up tar options: drop -a for the extract mode.
The -a option is not needed for the extract mode since tar
auto-detects compression type from file format.

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
2016-02-24 12:43:41 -08:00
36 changed files with 797 additions and 377 deletions
+67
View File
@@ -0,0 +1,67 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Linux
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentCaseLabels: false
IndentWidth: 8
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Always
...
+8
View File
@@ -22,5 +22,13 @@ 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-suite.log
+32
View File
@@ -96,6 +96,38 @@ noinst_HEADERS = \
include/swupd.h \
include/xattrs.h
TEST_EXTENSIONS = .sh
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)
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
endif
if COVERAGE
AM_CFLAGS += --coverage
coverage: coverage-clean
mkdir -p coverage
lcov --compat-libtool --directory . --capture --output-file coverage/report
genhtml -o coverage/ coverage/report
coverage-clean:
rm -rf coverage
endif
distclean-local:
rm -rf aclocal.m4 autogen.sh autom4te.cache config.h.in config.h.in~ configure depcomp install-sh Makefile.in missing compile
+26 -16
View File
@@ -1,11 +1,10 @@
#!/bin/bash
VER=$1
XZ_DEFAULTS="--threads 0"
PREVREL=`cat /var/lib/update/image/latest.version`
SWUPDREPO=/usr/src/clear-projects/swupd-server
BUNDLEREPO=/usr/src/clear-projects/clr-bundles
UPDATEDIR=/var/lib/update
SWUPDREPO=${SWUPDREPO:-"/usr/src/clear-projects/swupd-server"}
BUNDLEREPO=${BUNDLEREPO:-"/usr/src/clear-projects/clr-bundles"}
UPDATEDIR=${UPDATEDIR:-"/var/lib/update"}
error() {
echo "${1:-"Unknown Error"}"
@@ -16,14 +15,16 @@ error() {
# eg: all of openstack, pnp, bat, cloud stuff, non-basic scripting language bundles
${SWUPDREPO}/mk_groups_ini.sh
export SWUPD_CERTS_DIR="/root/swupd-certs"
PREVREL=`cat ${UPDATEDIR}/image/latest.version`
export SWUPD_CERTS_DIR=${SWUPD_CERTS_DIR:-"/root/swupd-certs"}
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"
${SWUPDREPO}/swupd_create_update --osversion ${VER}
${SWUPDREPO}/swupd_make_fullfiles ${VER}
${SWUPDREPO}/swupd_create_update --osversion ${VER} --statedir ${UPDATEDIR}
${SWUPDREPO}/swupd_make_fullfiles --statedir ${UPDATEDIR} ${VER}
pushd ${SWUPDREPO}
@@ -35,7 +36,7 @@ fi
BUNDLE_LIST=$(cat ${MOM} | awk -v V=${VER} '$1 ~ /^M\./ && $3 == V { print $4 }')
for BUNDLE in $BUNDLE_LIST; do
#background them for parallelization
${SWUPDREPO}/swupd_make_pack 0 ${VER} ${BUNDLE} &
${SWUPDREPO}/swupd_make_pack --statedir ${UPDATEDIR} 0 ${VER} ${BUNDLE} &
done
#now await all completing
for job in $(jobs -p); do
@@ -50,16 +51,25 @@ done
NUM_PACKS=2
${SWUPDREPO}/pack_maker.sh ${VER} ${NUM_PACKS}
popd ${SWUPDREPO}
popd
# expose the new build to staging / testing
echo ${VER} > ${UPDATEDIR}/image/latest.version
STAGING=$(cat ${UPDATEDIR}/www//version/formatstaging/latest)
if [ "${STAGING}" -lt "${VER}" ]; then
echo ${VER} > ${UPDATEDIR}/www//version/formatstaging/latest
STAGING_FILE="${UPDATEDIR}/www/version/formatstaging/latest"
if [ ! -f "${STAGING_FILE}" ]; then
mkdir -p "${UPDATEDIR}/www/version/formatstaging"
STAGING=0
echo ${STAGING} > ${UPDATEDIR}/www/version/formatstaging/latest
else
STAGING=$(cat ${STAGING_FILE})
fi
#valgrind /usr/src/clear-projects/swupd-server/swupd_create_update ${VER}
time hardlink /var/lib/update/image/${VER}/*
time hardlink /var/lib/update/image/$PREVREL /var/lib/update/image/${VER}
time hardlink /var/lib/update/www/$PREVREL /var/lib/update/www/${VER}
if [ "${STAGING}" -lt "${VER}" ]; then
echo ${VER} > ${UPDATEDIR}/www/version/formatstaging/latest
fi
#valgrind ${SWUPDREPO}/swupd_create_update --osversion ${VER} --statedir ${UPDATEDIR}
time hardlink ${UPDATEDIR}/image/${VER}/*
time hardlink ${UPDATEDIR}/image/${PREVREL} ${UPDATEDIR}/image/${VER}
time hardlink ${UPDATEDIR}/www/${PREVREL} ${UPDATEDIR}/www/${VER}
+43 -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.0.0, timothy.c.pepper@linux.intel.com)
AC_INIT(swupd-server, 3.1.2, timothy.c.pepper@linux.intel.com)
AM_INIT_AUTOMAKE([foreign -Wall -W subdir-objects])
AM_SILENT_RULES([yes])
AC_PROG_CC
@@ -28,6 +28,47 @@ AC_ARG_ENABLE(
AC_DEFINE(SWUPD_WITH_STATELESS,1,[OS is stateless])
)
AC_ARG_ENABLE(
[bsdtar],
AS_HELP_STRING([--enable-bsdtar],[Use alternative bsdtar command (uses tar by default)]),
AS_IF([test "x$enable_bsdtar" = "xyes"],
AC_DEFINE([SWUPD_WITH_BSDTAR], 1, [Use alternative bsdtar]),
AC_DEFINE([SWUPD_WITH_BSDTAR], 0, [Use default tar command])),
AC_DEFINE([SWUPD_WITH_BSDTAR], 0, [Use default tar command])
)
AC_ARG_ENABLE(
[tests],
[AS_HELP_STRING([--disable-tests], [Do not enable functional test framework (enabled by default)])]
)
have_coverage=no
AC_ARG_ENABLE(coverage, AS_HELP_STRING([--enable-coverage], [enable test coverage]))
if test "$enable_coverage" = "yes" ; then
AC_CHECK_PROG(lcov_found, [lcov], [yes], [no])
if test "$lcov_found" = "no" ; then
AC_MSG_ERROR([*** lcov support requested but the program was not found])
else
lcov_version_major="`lcov --version | cut -d ' ' -f 4 | cut -d '.' -f 1`"
lcov_version_minor="`lcov --version | cut -d ' ' -f 4 | cut -d '.' -f 2`"
if test "$lcov_version_major" -eq 1 -a "$lcov_version_minor" -lt 10; then
AC_MSG_ERROR([*** lcov version is too old. 1.10 required])
else
have_coverage=yes
AC_DEFINE([COVERAGE], [1], [Coverage enabled])
fi
fi
fi
AM_CONDITIONAL([COVERAGE], [test "$have_coverage" = "yes"])
AS_IF([test "$enable_tests" != "no"], [
AC_PATH_PROG([have_bats], [bats])
AS_IF([test -z "${have_bats}"], [
AC_MSG_ERROR([Must have the Bash Automated Testing System (bats) installed to run functional tests])
])
])
AM_CONDITIONAL([ENABLE_TESTS], [test "$enable_tests" != "no"])
AS_IF([test "$enable_bzip2" != "no"], [
AC_CHECK_LIB([bz2], [BZ2_bzBuffToBuffCompress], [], [AC_MSG_ERROR([the libbz2 library is missing])])
AC_CHECK_PROGS(BZIP2, bzip2)
@@ -42,4 +83,5 @@ AS_IF([test "$enable_lzma" != "no"], [
AM_CONDITIONAL([ENABLE_LZMA], [test "$enable_lzma" != "no"])
AC_CONFIG_FILES([Makefile])
AC_REQUIRE_AUX_FILE([tap-driver.sh])
AC_OUTPUT
+55 -45
View File
@@ -8,19 +8,29 @@
#include "config.h"
#define __unused__ __attribute__ ((__unused__))
#define __unused__ __attribute__((__unused__))
// 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_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_SELINUX
#define TAR_PERM_ATTR_ARGS "--preserve-permissions --xattrs --xattrs-include='*' --selinux"
#if SWUPD_WITH_BSDTAR
#define TAR_COMMAND "bsdtar"
#define TAR_XATTR_ARGS ""
#define TAR_WARN_ARGS ""
#else
#define TAR_PERM_ATTR_ARGS "--preserve-permissions --xattrs --xattrs-include='*'"
#define TAR_COMMAND "tar"
#define TAR_XATTR_ARGS "--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
#else
#define TAR_PERM_ATTR_ARGS "--preserve-permissions " TAR_XATTR_ARGS
#endif
#if SWUPD_WITH_STATELESS
@@ -31,8 +41,8 @@
/* Build types */
#define REGULAR_BUILD 0
#define FIX_BUILD 1
#define DEV_BUILD 2
#define FIX_BUILD 1
#define DEV_BUILD 2
/* We don't have BZIP2 support in Android. This define translates to "ifdef 0"
* and demarcates codes which otherwise would enable BZIP2. If this define
@@ -57,7 +67,7 @@ struct manifest {
int count;
uint64_t contentsize;
GList *files;
GList *manifests; /* as struct file */
GList *manifests; /* as struct file */
GList *submanifests; /* as struct manifest */
};
@@ -66,57 +76,57 @@ struct file;
struct header;
struct update_stat {
uint64_t st_mode;
uint64_t st_uid;
uint64_t st_gid;
uint64_t st_rdev;
uint64_t st_size;
uint64_t st_mode;
uint64_t st_uid;
uint64_t st_gid;
uint64_t st_rdev;
uint64_t st_size;
};
#define DIGEST_LEN_SHA256 64
/* +1 for null termination */
#define SWUPD_HASH_LEN (DIGEST_LEN_SHA256+1)
#define SWUPD_HASH_LEN (DIGEST_LEN_SHA256 + 1)
struct file {
char *filename;
char hash[SWUPD_HASH_LEN];
bool use_xattrs;
int last_change;
int last_change;
struct update_stat stat;
/* the following are exclusive */
unsigned int is_dir : 1;
unsigned int is_file : 1;
unsigned int is_link : 1;
unsigned int is_deleted : 1;
unsigned int is_manifest : 1;
unsigned int is_dir : 1;
unsigned int is_file : 1;
unsigned int is_link : 1;
unsigned int is_deleted : 1;
unsigned int is_manifest : 1;
/* and these are modifiers */
unsigned int is_config : 1;
unsigned int is_state : 1;
unsigned int is_boot : 1;
unsigned int is_rename : 1;
unsigned int is_config : 1;
unsigned int is_state : 1;
unsigned int is_boot : 1;
unsigned int is_rename : 1;
struct file *peer; /* same file in another manifest */
/* data fields to help rename detection */
double rename_score;
struct file *rename_peer;
char *alpha_only_filename; /* filename minus all numerics/etc */
char *filetype;
char *basename;
char *dirname;
/* end of rename detection fields */
struct file *peer; /* same file in another manifest */
unsigned int multithread : 1; /* if set to 1, current file is computed in a
/* data fields to help rename detection */
double rename_score;
struct file *rename_peer;
char *alpha_only_filename; /* filename minus all numerics/etc */
char *filetype;
char *basename;
char *dirname;
/* end of rename detection fields */
unsigned int multithread : 1; /* if set to 1, current file is computed in a
multithreaded process for fullfile creation */
};
struct packdata {
char *module;
int from;
int to;
int from;
int to;
int fullcount;
struct manifest *end_manifest;
};
@@ -146,9 +156,9 @@ extern int file_sort_version(gconstpointer a, gconstpointer b);
extern bool read_configuration_file(char *filename);
extern void release_configuration_data(void);
extern char * config_image_base(void);
extern char * config_output_dir(void);
extern char * config_empty_dir(void);
extern char *config_image_base(void);
extern char *config_output_dir(void);
extern char *config_empty_dir(void);
extern int config_initial_version(void);
extern void read_current_version(char *filename);
@@ -212,7 +222,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, ...);
@@ -228,7 +238,7 @@ extern void __create_delta(struct file *file, int from_version);
extern void account_delta_hit(void);
extern void account_delta_miss(void);
extern FILE * fopen_exclusive(const char *filename); /* no mode, opens for write only */
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);
+9 -8
View File
@@ -1,24 +1,25 @@
#! /bin/bash
COMMON=${COMMON:-"/root/common"}
BUNDLEREPO=${BUNDLEREPO:-"/root/clr-bundles"}
BUNDLEREPO=${BUNDLEREPO:-"/usr/src/clear-projects/clr-bundles"}
SWUPD_SERVER_DIR=${SWUPD_SERVER_DIR:-"/var/lib/update"}
SWUPD_GROUPS_INI=${SWUPD_GROUPS_INI:-"$SWUPD_SERVER_DIR/groups.ini"}
SWUPD_SERVER_INI=${SWUPD_SERVER_INI:-"$SWUPD_SERVER_DIR/server.ini"}
UPDATEDIR=${UPDATEDIR:-"/var/lib/update"}
SWUPD_GROUPS_INI=${SWUPD_GROUPS_INI:-"$UPDATEDIR/groups.ini"}
SWUPD_SERVER_INI=${SWUPD_SERVER_INI:-"$UPDATEDIR/server.ini"}
if [ ! -d "$SWUPD_SERVER_DIR" ]; then
mkdir -p $SWUPD_SERVER_DIR/{image,www}
if [ ! -d "$UPDATEDIR" ]; then
mkdir -p $UPDATEDIR/{image,www}
fi
if [ ! -f "$SWUPD_SERVER_INI" ]; then
template=$(echo $BASH_SOURCE)
template=$(dirname $template)
cp -p $template/server.ini $SWUPD_SERVER_INI
sed -i "s|/var/lib/update|$UPDATEDIR|" $SWUPD_SERVER_INI
fi
if [ ! -f "$SWUPD_SERVER_DIR/image/latest.version" ]; then
echo "0" > $SWUPD_SERVER_DIR/image/latest.version
if [ ! -f "$UPDATEDIR/image/latest.version" ]; then
echo "0" > $UPDATEDIR/image/latest.version
fi
echo "rebuilding $SWUPD_GROUPS_INI based on $BUNDLEREPO"
+8 -7
View File
@@ -20,9 +20,10 @@
# consider which version-pair packs are meaningful for intermediate builds
# and revert builds.
SWUPDREPO=${SWUPDREPO:-"/root/swupd-server"}
BUNDLEREPO=${BUNDLEREPO:-"/root/clr-bundles"}
SWUPDWEBDIR="/var/lib/update/www"
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"
@@ -52,13 +53,13 @@ if [ ! -e ${MOM} ]; then
exit 1
fi
#time ${SWUPDREPO}/swupd_make_fullfiles ${VER}
#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 0 ${VER} ${BUNDLE} &
#${SWUPDREPO}/swupd_make_pack --statedir ${UPDATEDIR} 0 ${VER} ${BUNDLE} &
BUNDLE_VER_LIST=""
MANIFEST_VER=$(cat ${SWUPDWEBDIR}/$VER/Manifest.MoM | grep "^previous:" | cut -f 2)
@@ -83,10 +84,10 @@ for BUNDLE in $BUNDLE_LIST; do
done
for v in $BUNDLE_VER_LIST; do
if [ -e /var/lib/update/www/${VER}/pack-${BUNDLE}-from-$v.tar ]; then
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 $v ${VER} ${BUNDLE}
${SWUPDREPO}/swupd_make_pack --statedir ${UPDATEDIR} $v ${VER} ${BUNDLE} &
fi
done
done
+4 -3
View File
@@ -13,8 +13,9 @@ if [[ $# < 1 ]]; then
exit 1
fi
FORMAT=$1
UPDATEDIR=${UPDATEDIR:-"/var/lib/update"}
ver1=`cat /var/lib/update/www/version/formatstaging/latest`
ver2=`cat /var/lib/update/www/version/format$FORMAT/latest`
cp /var/lib/update/www/version/formatstaging/latest /var/lib/update/www/version/format$FORMAT/latest
ver1=`cat ${UPDATEDIR}/www/version/formatstaging/latest`
ver2=`cat ${UPDATEDIR}/www/version/format$FORMAT/latest`
cp ${UPDATEDIR}/www/version/formatstaging/latest ${UPDATEDIR}/www/version/format$FORMAT/latest
echo "Updated from $ver2 to $ver1 in format $FORMAT"
+25 -27
View File
@@ -44,13 +44,13 @@ static GThreadPool *threadpool;
void hash_assign(char *src, char *dst)
{
memcpy(dst, src, SWUPD_HASH_LEN-1);
dst[SWUPD_HASH_LEN-1] = '\0';
memcpy(dst, src, SWUPD_HASH_LEN - 1);
dst[SWUPD_HASH_LEN - 1] = '\0';
}
bool hash_compare(char *hash1, char *hash2)
{
if (bcmp(hash1, hash2, SWUPD_HASH_LEN-1) == 0) {
if (bcmp(hash1, hash2, SWUPD_HASH_LEN - 1) == 0) {
return true;
} else {
return false;
@@ -100,8 +100,8 @@ static void hmac_sha256_for_data(char *hash,
}
static void hmac_sha256_for_string(char *hash,
const unsigned char *key, size_t key_len,
const char *str)
const unsigned char *key, size_t key_len,
const char *str)
{
if (str == NULL) {
hash_set_zeros(hash);
@@ -111,7 +111,6 @@ static void hmac_sha256_for_string(char *hash,
hmac_sha256_for_data(hash, key, key_len, (const unsigned char *)str, strlen(str));
}
static void hmac_compute_key(const char *filename,
const struct update_stat *updt_stat,
char *key, size_t *key_len, bool use_xattrs)
@@ -124,14 +123,14 @@ static void hmac_compute_key(const char *filename,
}
hmac_sha256_for_data(key, (const unsigned char *)updt_stat,
sizeof(struct update_stat),
(const unsigned char *)xattrs_blob,
xattrs_blob_len);
sizeof(struct update_stat),
(const unsigned char *)xattrs_blob,
xattrs_blob_len);
if (hash_is_zeros(key)) {
*key_len = 0;
} else {
*key_len = SWUPD_HASH_LEN-1;
*key_len = SWUPD_HASH_LEN - 1;
}
if (xattrs_blob_len != 0) {
@@ -203,14 +202,14 @@ int compute_hash(struct file *file, char *filename)
char link[PATH_MAX];
memset(link, 0, PATH_MAX);
ret = readlink(filename, link, PATH_MAX-1);
ret = readlink(filename, link, PATH_MAX - 1);
if (ret >= 0) {
hmac_compute_key(filename, &file->stat, key, &key_len, file->use_xattrs);
hmac_sha256_for_string(file->hash,
(const unsigned char *)key,
key_len,
link);
(const unsigned char *)key,
key_len,
link);
return 0;
} else {
LOG(NULL, "readlink error ", "%i - %i / %s", ret, errno, strerror(errno));
@@ -221,9 +220,9 @@ int compute_hash(struct file *file, char *filename)
if (file->is_dir) {
hmac_compute_key(filename, &file->stat, key, &key_len, file->use_xattrs);
hmac_sha256_for_string(file->hash,
(const unsigned char *)key,
key_len,
file->filename); //file->filename not filename
(const unsigned char *)key,
key_len,
file->filename); //file->filename not filename
return 0;
}
@@ -238,10 +237,10 @@ int compute_hash(struct file *file, char *filename)
hmac_compute_key(filename, &file->stat, key, &key_len, file->use_xattrs);
hmac_sha256_for_data(file->hash,
(const unsigned char *)key,
key_len,
blob,
file->stat.st_size);
(const unsigned char *)key,
key_len,
blob,
file->stat.st_size);
munmap(blob, file->stat.st_size);
fclose(fl);
return 0;
@@ -281,8 +280,8 @@ static bool illegal_characters(char *filename)
char c;
int i;
#define BAD_CHAR_COUNT 11
char bad_chars[BAD_CHAR_COUNT] = {';', '&', '|', '*', '`', '/',
'<', '>', '\\', '\"', '\''};
char bad_chars[BAD_CHAR_COUNT] = { ';', '&', '|', '*', '`', '/',
'<', '>', '\\', '\"', '\'' };
// these breaks the tar transform sed-like expression,
// hopefully can remove this check after moving to libtar
@@ -295,8 +294,8 @@ static bool illegal_characters(char *filename)
return true;
}
for(i=0; i<BAD_CHAR_COUNT; i++) {
c=bad_chars[i];
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;
@@ -365,7 +364,7 @@ static void iterate_directory(struct manifest *manifest, char *pathprefix,
if (do_hash) {
/* compute the hash from a thread */
ret = g_thread_pool_push(threadpool, file, &err);
if (ret == FALSE){
if (ret == FALSE) {
printf("GThread hash computation push error\n");
printf("%s\n", err->message);
closedir(dir);
@@ -379,7 +378,6 @@ static void iterate_directory(struct manifest *manifest, char *pathprefix,
free(fullpath);
}
struct manifest *full_manifest_from_directory(int version)
{
struct manifest *manifest;
+7 -8
View File
@@ -37,20 +37,19 @@ void chroot_create_full(int newversion)
{
int ret;
char *group;
char * command;
char *command;
char *full_dir;
string_or_die(&full_dir, "%s/%i/full/", image_dir, newversion);
g_mkdir_with_parents(full_dir, S_IRWXU);
/* 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);
image_dir, newversion, full_dir);
ret = system(command);
assert(ret==0);
assert(ret == 0);
free(command);
/* overlay any new files from each group */
@@ -62,9 +61,9 @@ 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);
image_dir, newversion, group, full_dir);
ret = system(command);
assert(ret==0);
assert(ret == 0);
free(command);
}
@@ -82,9 +81,9 @@ void chroot_create_full(int newversion)
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);
full_dir, image_dir, newversion, group);
ret = system(command);
assert(ret==0);
assert(ret == 0);
free(command);
}
free(full_dir);
-2
View File
@@ -30,7 +30,6 @@
static GKeyFile *keyfile = NULL;
char *config_image_base(void)
{
assert(keyfile != NULL);
@@ -68,7 +67,6 @@ int config_initial_version(void)
return version;
}
bool read_configuration_file(char *filename)
{
GError *error = NULL;
+2 -3
View File
@@ -138,7 +138,8 @@ void __create_delta(struct file *file, int from_version)
}
LOG(NULL, "Failed to rename", "");
}
out: free(sanitycheck);
out:
free(sanitycheck);
free(testnewfile);
free(conf);
free(newfile);
@@ -156,7 +157,6 @@ void prepare_delta_dir(struct manifest *manifest)
conf = config_output_dir();
string_or_die(&path, "%s/%i", conf, manifest->version);
if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
if (errno != EEXIST) {
@@ -176,4 +176,3 @@ void prepare_delta_dir(struct manifest *manifest)
free(path);
free(conf);
}
+22 -23
View File
@@ -42,8 +42,8 @@
static void create_fullfile(struct file *file)
{
char *origin;
char *tarcommand=NULL;
char *tarname=NULL;
char *tarcommand = NULL;
char *tarname = NULL;
char *rename_source = NULL;
char *rename_target = NULL;
char *rename_tmpdir = NULL;
@@ -51,7 +51,6 @@ static void create_fullfile(struct file *file)
struct stat sbuf;
char *empty, *indir, *outdir;
if (file->is_deleted) {
return; /* file got deleted -> by definition we cannot tar it up */
}
@@ -88,14 +87,14 @@ static void create_fullfile(struct file *file)
dir = dirname(tmp2);
string_or_die(&rename_tmpdir, "%s/XXXXXX", outdir);
if(!mkdtemp(rename_tmpdir)) {
if (!mkdtemp(rename_tmpdir)) {
LOG(NULL, "Failed to create temporary directory for %s move", origin);
assert(0);
}
string_or_die(&tarcommand, "tar -C %s " TAR_PERM_ATTR_ARGS " -cf - '%s' --exclude='%s'/* 2> /dev/null | "
"tar -C %s " TAR_PERM_ATTR_ARGS " -xf - 2> /dev/null",
dir, base, base, rename_tmpdir);
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);
assert(0);
@@ -111,8 +110,8 @@ static void create_fullfile(struct file *file)
free(rename_source);
/* for a directory file, tar up simply with gzip */
string_or_die(&tarcommand, "tar -C %s %s " TAR_PERM_ATTR_ARGS " -zcf %s/%i/files/%s.tar",
rename_tmpdir, file->hash, outdir, file->last_change, file->hash);
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);
assert(0);
@@ -138,7 +137,7 @@ static void create_fullfile(struct file *file)
string_or_die(&tempfile, "%s/%s", empty, file->hash);
if (link(origin, tempfile) < 0) {
LOG(NULL, "hardlink failed", "%s due to %s (%s -> %s)", file->filename, strerror(errno), origin, tempfile);
char *const argv[] = {"cp", "-a", origin, tempfile, NULL};
char *const argv[] = { "cp", "-a", origin, tempfile, NULL };
if (system_argv(argv) != 0) {
assert(0);
}
@@ -146,24 +145,24 @@ static void create_fullfile(struct file *file)
/* step 2a: tar it with each compression type */
// lzma
string_or_die(&tarcommand, "tar --directory=%s " TAR_PERM_ATTR_ARGS " -Jcf %s/%i/files/%s.tar.xz %s",
empty, outdir, file->last_change, file->hash, file->hash);
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);
assert(0);
}
free(tarcommand);
// gzip
string_or_die(&tarcommand, "tar --directory=%s " TAR_PERM_ATTR_ARGS " -zcf %s/%i/files/%s.tar.gz %s",
empty, outdir, file->last_change, file->hash, file->hash);
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);
assert(0);
}
free(tarcommand);
#ifdef SWUPD_WITH_BZIP2
string_or_die(&tarcommand, "tar --directory=%s " TAR_PERM_ATTR_ARGS " -jcf %s/%i/files/%s.tar.bz2 %s",
empty, outdir, file->last_change, file->hash, file->hash);
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);
assert(0);
@@ -271,13 +270,13 @@ static void submit_fullfile_tasks(GList *files)
GList *item;
struct file *file;
int ret;
int count=0;
int count = 0;
GError *err = NULL;
LOG(NULL, "fullfile threadpool", "%d threads", sysconf(_SC_NPROCESSORS_ONLN) * 3);
threadpool = g_thread_pool_new(create_fullfile_task, NULL,
sysconf(_SC_NPROCESSORS_ONLN) * 3,
TRUE, NULL);
sysconf(_SC_NPROCESSORS_ONLN) * 3,
TRUE, NULL);
printf("Starting downloadable fullfiles data creation\n");
@@ -287,7 +286,7 @@ static void submit_fullfile_tasks(GList *files)
item = g_list_next(item);
ret = g_thread_pool_push(threadpool, file, &err);
if (ret == FALSE){
if (ret == FALSE) {
printf("GThread create_fullfile_task push error\n");
printf("%s\n", err->message);
assert(0);
@@ -321,10 +320,10 @@ void create_fullfiles(struct manifest *manifest)
conf = config_output_dir();
string_or_die(&path, "%s/%i", conf, manifest->version);
if(mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
if (errno != EEXIST) {
LOG(NULL, "Failed to create directory ", "%s", path);
return;
return;
}
}
free(path);
@@ -332,7 +331,7 @@ void create_fullfiles(struct manifest *manifest)
if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
if (errno != EEXIST) {
LOG(NULL, "Failed to create directory ", "%s", path);
return;
return;
}
}
free(path);
-2
View File
@@ -51,7 +51,6 @@ char *group_groups(char *group)
return g_key_file_get_value(groupfile, group, "groups", NULL);
}
void read_group_file(char *filename)
{
GError *error = NULL;
@@ -76,7 +75,6 @@ void release_group_file(void)
}
}
char *next_group(void)
{
if (groupcursor >= groupcount) {
+7 -8
View File
@@ -37,17 +37,16 @@
#include "swupd.h"
FILE * fopen_exclusive(const char *filename) /* no mode, opens for write only */
FILE *fopen_exclusive(const char *filename) /* no mode, opens for write only */
{
int fd;
int fd;
fd = open(filename,O_CREAT | O_EXCL | O_RDWR , 00644);
if (fd < 0) {
fd = open(filename, O_CREAT | O_EXCL | O_RDWR, 00644);
if (fd < 0) {
printf("exclusive open failed, filename=\"%s\",err=\"%s\"\n",
filename, strerror(errno));
filename, strerror(errno));
LOG(NULL, "exclusive open failed", "\\*filename=\"%s\",err=\"%s\"*\\",
filename, strerror(errno));
filename, strerror(errno));
return NULL;
}
return fdopen(fd, "w");
@@ -177,7 +176,7 @@ int system_argv(char *const argv[])
}
if (status != 0) {
char* cmdline = NULL;
char *cmdline = NULL;
concat_str_array(&cmdline, argv);
LOG(NULL, "Failed to run command:", "%s", cmdline);
-2
View File
@@ -31,8 +31,6 @@
#include "swupd.h"
/* TODO: this needs to come from a file that has a list of regexps */
static void config_file_heuristics(struct file *file)
+8 -8
View File
@@ -38,11 +38,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)
@@ -93,7 +94,7 @@ void __log_message(struct file *file, char *msg, char *filename, int linenr, con
char filebuf2[4096];
if (!logfile) {
return;\
return;
}
gettimeofday(&current_time, NULL);
@@ -119,13 +120,12 @@ void __log_message(struct file *file, char *msg, char *filename, int linenr, con
strcat(filebuf2, " ");
}
fprintf(logfile, "%3i.%03i %5s %s:%03i\t| %s\t| %s\t| %s\n",
(int)current_time.tv_sec, (int)current_time.tv_usec / 1000, logstring, filebuf, linenr, filebuf2, msg, buf);
fprintf(logfile, "%3i.%03i %5s %s:%03i\t| %s\t| %s\t| %s\n",
(int)current_time.tv_sec, (int)current_time.tv_usec / 1000, logstring, filebuf, linenr, filebuf2, msg, buf);
free(logstring);
free(buf);
fflush(logfile);
}
void close_log(int version, int exit_status)
@@ -133,7 +133,7 @@ void close_log(int version, int exit_status)
struct timeval current_time;
int t_sec;
int t_msec;
if (!logfile) {
return;
}
+19 -21
View File
@@ -24,7 +24,6 @@
*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
@@ -48,18 +47,19 @@ static void banner(void)
}
static const struct option prog_opts[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{"osversion", required_argument, 0, 'o'},
{"minversion", required_argument, 0, 'm'},
{"format", required_argument, 0, 'F'},
{"getformat", no_argument, 0, 'g'},
{"statedir", required_argument, 0, 'S'},
{"signcontent", no_argument, 0, 's'},
{0, 0, 0, 0}
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ "osversion", required_argument, 0, 'o' },
{ "minversion", required_argument, 0, 'm' },
{ "format", required_argument, 0, 'F' },
{ "getformat", no_argument, 0, 'g' },
{ "statedir", required_argument, 0, 'S' },
{ "signcontent", no_argument, 0, 's' },
{ 0, 0, 0, 0 }
};
static void print_help(const char *name) {
static void print_help(const char *name)
{
printf("Usage:\n");
printf(" %s [OPTION...]\n\n", name);
printf("Help Options:\n");
@@ -100,7 +100,7 @@ static bool parse_options(int argc, char **argv)
case 'm':
minversion = strtoull(optarg, NULL, 10);
if (minversion < 0) {
printf("-m | --minversion == %d, require value >= 0 \n", newversion);
printf("-m | --minversion == %d, require value >= 0 \n", minversion);
return false;
}
break;
@@ -256,7 +256,6 @@ int main(int argc, char **argv)
goto exit;
}
string_or_die(&file_path, "%s/server.ini", state_dir);
if (!read_configuration_file(file_path)) {
printf("Failed to read %s configuration file!\n", state_dir);
@@ -275,7 +274,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);
@@ -296,7 +295,7 @@ int main(int argc, char **argv)
match_manifests(old_full, new_full);
apply_heuristics(new_full);
#warning disabled rename detection for some simplicity
/* rename_detection(new_full); */
// rename_detection(new_full);
print_elapsed_time(&previous_time, &current_time);
@@ -304,8 +303,8 @@ int main(int argc, char **argv)
/* Phase 2 : the os-core set */
/* Step 2: Make a manifest for the os-core set */
old_MoM = manifest_from_file(current_version, "MoM");
new_MoM = alloc_manifest(newversion, "MoM");
old_MoM = manifest_from_file(current_version, "MoM");
new_MoM = alloc_manifest(newversion, "MoM");
old_core = manifest_from_file(manifest_subversion(old_MoM, "os-core"), "os-core");
new_core = sub_manifest_from_directory("os-core", newversion);
add_component_hashes_to_manifest(new_core, new_full);
@@ -329,9 +328,9 @@ int main(int argc, char **argv)
/* Step 3c: ... else save the manifest */
type_change_detection(new_core);
/* Detect renamed files specifically for each pack */
#warning disabled rename detection for some simplicity
/* rename_detection(...); */
/* Detect renamed files specifically for each pack */
// rename_detection(...);
sort_manifest_by_version(new_core);
newfiles = prune_manifest(new_core);
@@ -431,8 +430,7 @@ int main(int argc, char **argv)
printf("Entering phase 5: creating download content\n");
/* Phase 5: wrapping up */
//TODO: should be fixup_versions() and preceed all write_manifest() calls
//TODO: should be fixup_versions() and preceed all write_manifest() calls
maximize_to_full(new_MoM, new_full);
sort_manifest_by_version(new_full);
+12 -9
View File
@@ -32,9 +32,9 @@
#include "swupd.h"
static const struct option prog_opts[] = {
{"help", no_argument, 0, 'h'},
{"statedir", required_argument, 0, 'S'},
{0, 0, 0, 0}
{ "help", no_argument, 0, 'h' },
{ "statedir", required_argument, 0, 'S' },
{ 0, 0, 0, 0 }
};
static void usage(const char *name)
@@ -93,12 +93,6 @@ int main(int argc, char **argv)
free_state_globals();
return EXIT_FAILURE;
}
banner();
check_root();
string_or_die(&file_path, "%s/server.ini", state_dir);
read_configuration_file(file_path);
free(file_path);
if (argc - optind != 1) {
usage(argv[0]);
@@ -106,12 +100,21 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
banner();
check_root();
string_or_die(&file_path, "%s/server.ini", state_dir);
read_configuration_file(file_path);
free(file_path);
version = strtoull(argv[optind++], NULL, 10);
if (version < 0) {
printf("Usage:\n\tswupd_make_fullfiles <version>\n\n");
exit(EXIT_FAILURE);
}
init_log("swupd-make-fullfiles", "", 0, version);
manifest = manifest_from_file(version, "full");
create_fullfiles(manifest);
+10 -11
View File
@@ -46,10 +46,10 @@ static void banner(void)
}
static const struct option prog_opts[] = {
{"help", no_argument, 0, 'h'},
{"statedir", required_argument, 0, 'S'},
{"signcontent", no_argument, 0, 's'},
{0, 0, 0, 0}
{ "help", no_argument, 0, 'h' },
{ "statedir", required_argument, 0, 'S' },
{ "signcontent", no_argument, 0, 's' },
{ 0, 0, 0, 0 }
};
static void usage(const char *name)
@@ -107,17 +107,14 @@ int main(int argc, char **argv)
free_state_globals();
return EXIT_FAILURE;
}
banner();
check_root();
if (argc - optind != 3) {
usage(argv[0]);
exit(EXIT_FAILURE);
}
/* FIXME: should use "end_version" not "0" and a unique filename
init_log(0);
*/
banner();
check_root();
/* Initilize the crypto signature module */
if (!signature_initialize()) {
@@ -140,6 +137,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));
@@ -158,8 +157,8 @@ int main(int argc, char **argv)
signature_terminate();
printf("Pack creation %s (pack-%s %i to %li)\n",
exit_status == EXIT_SUCCESS ? "complete" : "failed",
module, start_version, end_version);
exit_status == EXIT_SUCCESS ? "complete" : "failed",
module, start_version, end_version);
free_state_globals();
return exit_status;
+54 -68
View File
@@ -40,24 +40,24 @@
#include "swupd.h"
#include "xattrs.h"
#define LINK_SIZE_HINT 1024
#define DIR_SIZE_HINT 1024
#define LINK_SIZE_HINT 1024
#define DIR_SIZE_HINT 1024
int file_sort_hash(gconstpointer a, gconstpointer b)
{
struct file *A, *B;
A = (struct file *) a;
B = (struct file *) b;
A = (struct file *)a;
B = (struct file *)b;
/* this MUST be a memcmp(), not bcmp() */
return memcmp(A->hash, B->hash, SWUPD_HASH_LEN-1);
return memcmp(A->hash, B->hash, SWUPD_HASH_LEN - 1);
}
int file_sort_version(gconstpointer a, gconstpointer b)
{
struct file *A, *B;
A = (struct file *) a;
B = (struct file *) b;
A = (struct file *)a;
B = (struct file *)b;
if (A->last_change < B->last_change) {
return -1;
@@ -73,8 +73,8 @@ int file_sort_filename(gconstpointer a, gconstpointer b)
{
struct file *A, *B;
int ret;
A = (struct file *) a;
B = (struct file *) b;
A = (struct file *)a;
B = (struct file *)b;
ret = strcmp(A->filename, B->filename);
if (ret) {
@@ -105,7 +105,6 @@ struct manifest *alloc_manifest(int version, char *component)
return manifest;
}
struct manifest *manifest_from_file(int version, char *component)
{
FILE *infile;
@@ -139,7 +138,7 @@ struct manifest *manifest_from_file(int version, char *component)
return NULL;
}
if (strncmp(line, "MANIFEST\t", 9)!=0) {
if (strncmp(line, "MANIFEST\t", 9) != 0) {
printf("Invalid file format: MANIFEST line\n");
fclose(infile);
return NULL;
@@ -151,7 +150,7 @@ struct manifest *manifest_from_file(int version, char *component)
return NULL;
}
line[0] = 0;
while (strcmp(line, "\n")!=0) {
while (strcmp(line, "\n") != 0) {
/* read the header */
line[0] = 0;
if (fgets(line, 8191, infile) == NULL) {
@@ -173,10 +172,10 @@ struct manifest *manifest_from_file(int version, char *component)
assert(0);
}
if (strncmp(line,"version:", 8) == 0) {
if (strncmp(line, "version:", 8) == 0) {
version = strtoull(c, NULL, 10);
}
if (strncmp(line,"previous:", 9) == 0) {
if (strncmp(line, "previous:", 9) == 0) {
previous = strtoull(c, NULL, 10);
}
}
@@ -286,7 +285,7 @@ struct manifest *manifest_from_file(int version, char *component)
manifest->files = g_list_prepend(manifest->files, file);
}
manifest->count++;
count ++;
count++;
}
manifest->files = g_list_sort(manifest->files, file_sort_filename);
@@ -296,7 +295,6 @@ struct manifest *manifest_from_file(int version, char *component)
return manifest;
}
void free_manifest(struct manifest *manifest)
{
struct file *file;
@@ -314,7 +312,6 @@ void free_manifest(struct manifest *manifest)
free(manifest);
}
/*
backfill the "last changed" of each file in a manifest
by comparing the hash against the same file in the previous manifest
@@ -355,7 +352,6 @@ int match_manifests(struct manifest *m1, struct manifest *m2)
file1->peer = NULL;
file2->peer = NULL;
ret = strcmp(file1->filename, file2->filename);
if (ret == 0) {
if (file1->is_deleted && file2->is_deleted && file1->is_rename) {
@@ -364,16 +360,16 @@ int match_manifests(struct manifest *m1, struct manifest *m2)
}
if (hash_compare(file1->hash, file2->hash) &&
file1->is_dir == file2->is_dir &&
file1->is_link == file2->is_link &&
file1->is_deleted == file2->is_deleted &&
file1->is_file == file2->is_file &&
file1->is_config == file2->is_config &&
file1->is_state == file2->is_state &&
file1->is_boot == file2->is_boot &&
file1->last_change >= minversion) {
file2->last_change = file1->last_change;
file2->is_rename = file1->is_rename;
file1->is_dir == file2->is_dir &&
file1->is_link == file2->is_link &&
file1->is_deleted == file2->is_deleted &&
file1->is_file == file2->is_file &&
file1->is_config == file2->is_config &&
file1->is_state == file2->is_state &&
file1->is_boot == file2->is_boot &&
file1->last_change >= minversion) {
file2->last_change = file1->last_change;
file2->is_rename = file1->is_rename;
} else {
account_changed_file();
if (first) {
@@ -398,11 +394,13 @@ int match_manifests(struct manifest *m1, struct manifest *m2)
}
if (ret < 0) {
struct file *file3;
/*
* if we get here, file1 got deleted... what we must do is add a file entry for it in the target list.
* However, since we're currently walking the list we HAVE to prepend the entry.. and mark for sort at
* the end.
*/
/*
* if we get here, file1 got deleted... what we must do
* is add a file entry for it in the target list.
* However, since we're currently walking the list we
* HAVE to prepend the entry.. and mark for sort at the
* end.
*/
file3 = calloc(1, sizeof(struct file));
if (file3 == NULL) {
assert(0);
@@ -427,7 +425,7 @@ int match_manifests(struct manifest *m1, struct manifest *m2)
file1->peer = file3;
list1 = g_list_next(list1);
m2->files = g_list_prepend(m2->files, file3);
m2->files = g_list_prepend(m2->files, file3);
m2->count++;
if (!file1->is_deleted) {
account_deleted_file();
@@ -447,7 +445,7 @@ int match_manifests(struct manifest *m1, struct manifest *m2)
count++;
}
/* now deal with the tail ends */
/* now deal with the tail ends */
while (list1) {
file1 = list1->data;
@@ -458,11 +456,12 @@ int match_manifests(struct manifest *m1, struct manifest *m2)
first = 0;
}
count++;
/*
* if we get here, file1 got deleted... what we must do is add a file entry for it in the target list.
* However, since we're currently walking the list we HAVE to prepend the entry.. and mark for sort at
* the end.
*/
/*
* if we get here, file1 got deleted... what we must do is add
* a file entry for it in the target list. However, since
* we're currently walking the list we HAVE to prepend the
* entry.. and mark for sort at the end.
*/
file3 = calloc(1, sizeof(struct file));
if (file3 == NULL) {
assert(0);
@@ -510,7 +509,6 @@ int match_manifests(struct manifest *m1, struct manifest *m2)
return count;
}
/* removes all files from m2 from m1 */
void subtract_manifests(struct manifest *m1, struct manifest *m2)
{
@@ -547,22 +545,16 @@ 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;
m1->count--;
}
}
if (ret < 0) {
} else if (ret < 0) {
list1 = g_list_next(list1);
continue;
} else {
list2 = g_list_next(list2);
}
list2 = g_list_next(list2);
}
}
char *file_type_to_string(struct file *file)
{
static char type[5];
@@ -650,7 +642,7 @@ static int write_manifest_signature(struct manifest *manifest, const char *suffi
assert(0);
}
string_or_die(&filename, "%s/%i/Manifest.%s%s", conf, manifest->version,
manifest->component, suffix);
manifest->component, suffix);
if (!signature_sign(filename)) {
fprintf(stderr, "Creating signature for '%s' failed\n", filename);
goto exit;
@@ -685,7 +677,7 @@ static int write_manifest_plain(struct manifest *manifest)
}
dir = dirname(base);
if (g_mkdir_with_parents(dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
if (g_mkdir_with_parents(dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
assert(0);
}
@@ -748,19 +740,19 @@ static int write_manifest_tar(struct manifest *manifest)
int ret = -1;
if (conf == NULL) {
assert(0);
assert(0);
}
/* 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 --directory=%s/%i " TAR_PERM_ATTR_ARGS " -Jcf "
"%s/%i/Manifest.%s.tar Manifest.%s Manifest.%s.signed",
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);
} else {
string_or_die(&tarcmd, "tar --directory=%s/%i " TAR_PERM_ATTR_ARGS " -Jcf "
"%s/%i/Manifest.%s.tar Manifest.%s",
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);
}
@@ -793,7 +785,8 @@ bool compute_hash_with_xattrs(const char *filename)
return true;
}
return false;
/* Currently swupd-client includes xattrs to hash sums of all files */
return true;
}
/* Returns 0 == success, -1 == failure */
@@ -946,7 +939,6 @@ void nest_manifest(struct manifest *parent, struct manifest *sub)
parent->count++;
}
/* adds a struct file for a submanifest and also adds it to the proper list */
void nest_manifest_file(struct manifest *parent, struct file *file)
{
@@ -958,11 +950,9 @@ void nest_manifest_file(struct manifest *parent, struct file *file)
parent->submanifests = g_list_prepend(parent->submanifests, sub);
parent->count++;
LOG(file, "Nest manifest file", "%s", file->filename);
}
int manifest_subversion(struct manifest *parent, char *group)
{
GList *list;
@@ -1028,7 +1018,6 @@ static void maximize_version_manifests(struct manifest *m1, struct manifest *m2)
}
}
/*
* We need this in case files move modules;
* the "full" list must be the maximum of all the versions of
@@ -1170,17 +1159,15 @@ void consolidate_submanifests(struct manifest *manifest)
/* (case 6) all others constitute errors */
LOG(NULL, "unhandled filename pair: file1", "%s %s (%d), file2 %s %s (%d)",
file1->filename, file1->hash, file1->last_change,
file1->filename, file2->hash, file2->last_change);
file1->filename, file1->hash, file1->last_change,
file1->filename, file2->hash, file2->last_change);
manifest->files = g_list_delete_link(manifest->files, list);
list = g_list_next(next);
manifest->files = g_list_delete_link(manifest->files, next);
printf("CONFLICT IN MANIFESTS\n");
}
}
int previous_version_manifest(struct manifest *mom, char *name)
{
GList *list;
@@ -1200,4 +1187,3 @@ int previous_version_manifest(struct manifest *mom, char *name)
}
return 0;
}
+103 -54
View File
@@ -39,28 +39,32 @@
#include "swupd.h"
static void empty_pack_stage(int full, int version, char *module)
static void empty_pack_stage(int full, int from_version, int to_version, char *module)
{
char *cmd;
char *path;
int ret;
// clean any stale data (eg: re-run after a failure)
string_or_die(&cmd, "rm -rf %s/%s/%i/", packstage_dir, module, version);
string_or_die(&cmd, "rm -rf %s/%s/%i_to_%i/", packstage_dir, module,
from_version, to_version);
ret = system(cmd);
if (ret) {
fprintf(stderr, "Failed to clean %s/%s/%i\n",
packstage_dir, module, version);
fprintf(stderr, "Failed to clean %s/%s/%i_to_%i\n",
packstage_dir, module, from_version, to_version);
free(cmd);
exit(EXIT_FAILURE);
}
free(cmd);
if (!full) {
// (re)create module/version/{delta,staged}
string_or_die(&path, "%s/%s/%i/delta", packstage_dir, module, version);
string_or_die(&path, "%s/%s/%i_to_%i/delta", packstage_dir, module,
from_version, to_version);
g_mkdir_with_parents(path, S_IRWXU | S_IRWXG);
free(path);
string_or_die(&path, "%s/%s/%i/staged", packstage_dir, module, version);
string_or_die(&path, "%s/%s/%i_to_%i/staged", packstage_dir, module,
from_version, to_version);
g_mkdir_with_parents(path, S_IRWXU | S_IRWXG);
free(path);
}
@@ -69,14 +73,15 @@ static void empty_pack_stage(int full, int version, char *module)
/*
* for very small files (eh.. lets make that all), we untar them for pack purposes
*/
static void explode_pack_stage(int version, char *module)
static void explode_pack_stage(int from_version, int to_version, char *module)
{
DIR *dir;
struct dirent *entry;
struct stat buf;
char *path;
string_or_die(&path, "%s/%s/%i/staged", packstage_dir, module, version);
string_or_die(&path, "%s/%s/%i_to_%i/staged", packstage_dir, module,
from_version, to_version);
g_mkdir_with_parents(path, S_IRWXU | S_IRWXG);
dir = opendir(path);
if (!dir) {
@@ -99,8 +104,8 @@ static void explode_pack_stage(int version, char *module)
continue;
}
string_or_die(&path, "%s/%s/%i/staged/%s",
packstage_dir, module, version, entry->d_name);
string_or_die(&path, "%s/%s/%i_to_%i/staged/%s", packstage_dir, module,
from_version, to_version, entry->d_name);
ret = stat(path, &buf);
if (ret) {
free(path);
@@ -113,8 +118,9 @@ static void explode_pack_stage(int 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 --directory=%s/%s/%i/staged --warning=no-timestamp "
TAR_PERM_ATTR_ARGS " -axf %s", packstage_dir, module, version, path);
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) {
unlink(path);
@@ -139,7 +145,7 @@ static void prepare_pack(struct packdata *pack)
pack->end_manifest = manifest_from_file(pack->to, pack->module);
empty_pack_stage(0, pack->from, pack->module);
empty_pack_stage(0, pack->from, pack->to, pack->module);
match_manifests(manifest, pack->end_manifest);
@@ -153,7 +159,7 @@ static void make_pack_full_files(struct packdata *pack)
int ret;
LOG(NULL, "starting pack full file creation", "%s: %d to %d",
pack->module, pack->from, pack->to);
pack->module, pack->from, pack->to);
/* full files pack: */
item = g_list_first(pack->end_manifest->files);
@@ -162,25 +168,49 @@ 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/staged/%s.tar", packstage_dir, pack->module, pack->from, 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);
string_or_die(&to, "%s/%s/%i_to_%i/staged/%s.tar", packstage_dir,
pack->module, pack->from, pack->to, file->hash);
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);
}
}
LOG(NULL, "finished pack full file creation", "%s: %d to %d",
pack->module, pack->from, pack->to);
pack->module, pack->from, pack->to);
}
static int find_file_in_list(GList *files, struct file *file)
@@ -195,8 +225,8 @@ static int find_file_in_list(GList *files, struct file *file)
item = g_list_next(item);
if (hash_compare(item_file->hash, file->hash) &&
(item_file->last_change == file->last_change) &&
(item_file->peer->last_change == file->peer->last_change)) {
(item_file->last_change == file->last_change) &&
(item_file->peer->last_change == file->peer->last_change)) {
LOG(NULL, "Found a duplicate delta", "%d %d %s %s", file->peer->last_change, file->last_change, file->hash, file->filename);
return TRUE;
}
@@ -230,7 +260,7 @@ static GList *consolidate_packs_delta_files(GList *files, struct packdata *pack)
}
string_or_die(&from, "%s/%i/delta/%i-%i-%s", staging_dir, file->last_change,
file->peer->last_change, file->last_change, file->hash);
file->peer->last_change, file->last_change, file->hash);
ret = stat(from, &stat_delta);
if (ret && !find_file_in_list(files, file)) {
@@ -263,7 +293,7 @@ static void make_pack_deltas(GList *files)
LOG(NULL, "pack deltas threadpool", "%d threads", sysconf(_SC_NPROCESSORS_ONLN));
threadpool = g_thread_pool_new(create_delta, NULL,
sysconf(_SC_NPROCESSORS_ONLN), FALSE, NULL);
sysconf(_SC_NPROCESSORS_ONLN), FALSE, NULL);
item = g_list_first(files);
while (item) {
@@ -271,7 +301,7 @@ static void make_pack_deltas(GList *files)
item = g_list_next(item);
ret = g_thread_pool_push(threadpool, file, &err);
if (ret == FALSE){
if (ret == FALSE) {
// intentionally non-fatal
fprintf(stderr, "GThread create_delta push error\n");
fprintf(stderr, "%s\n", err->message);
@@ -289,7 +319,7 @@ static int write_pack_signature(struct packdata *pack)
int ret = -1;
string_or_die(&filename, "%s/%i/pack-%s-from-%i.tar",
staging_dir, pack->to, pack->module, pack->from);
staging_dir, pack->to, pack->module, pack->from);
if (!signature_sign(filename)) {
fprintf(stderr, "Creating signature for '%s' failed\n", filename);
goto exit;
@@ -314,7 +344,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;
@@ -329,13 +359,17 @@ 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/delta/%i-%i-%s", packstage_dir, pack->module,
pack->from, file->peer->last_change, file->last_change, file->hash);
file->peer->last_change, file->last_change, file->hash);
string_or_die(&to, "%s/%s/%i_to_%i/delta/%i-%i-%s", packstage_dir,
pack->module, pack->from, pack->to, file->peer->last_change,
file->last_change, 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/staged/%s.tar", packstage_dir, pack->module,
pack->from, file->hash);
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) {
@@ -367,13 +401,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++;
}
}
@@ -382,11 +431,13 @@ static int make_final_pack(struct packdata *pack)
free(to);
free(tarfrom);
free(tarto);
free(fullfrom);
free(fullto);
}
if (pack->fullcount > 0) {
/* untar all files for smaller size and less cpu use on client */
explode_pack_stage(pack->from, pack->module);
explode_pack_stage(pack->from, pack->to, pack->module);
}
/* now... link in the Manifest pack */
@@ -395,7 +446,7 @@ static int make_final_pack(struct packdata *pack)
struct stat st;
string_or_die(&from, "%s/%i/Manifest-%s-delta-from-%i",
staging_dir, pack->to, pack->module, pack->from);
staging_dir, pack->to, pack->module, pack->from);
ret = stat(from, &st);
if (ret) {
@@ -404,8 +455,8 @@ static int make_final_pack(struct packdata *pack)
}
string_or_die(&to, "%s/%s/%i/Manifest-%s-delta-from-%i",
packstage_dir, pack->module, pack->from, pack->module, pack->from);
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) {
@@ -416,22 +467,21 @@ static int make_final_pack(struct packdata *pack)
free(to);
}
/* now... link in the MoM Manifest into the base pack */
if ((pack->from != 0) && (strcmp(pack->module, "os-core") == 0)) {
char *from, *to;
struct stat st;
string_or_die(&from, "%s/%i/Manifest-%s-delta-from-%i",
staging_dir, pack->to, "MoM", pack->from);
staging_dir, pack->to, "MoM", pack->from);
ret = stat(from, &st);
if (ret) {
LOG(NULL, "Making extra manifest delta", "MoM: %i->%i", pack->from, pack->to);
create_manifest_delta(pack->from, pack->to, "MoM");
}
string_or_die(&to, "%s/%s/%i/Manifest-%s-delta-from-%i",
packstage_dir, pack->module, pack->from, "MoM", pack->from);
string_or_die(&to, "%s/%s/%i_to_%i/Manifest-%s-delta-from-%i", packstage_dir,
pack->module, pack->from, pack->to, "MoM", pack->from);
ret = link(from, to);
if (ret) {
@@ -442,12 +492,12 @@ static int make_final_pack(struct packdata *pack)
free(to);
}
/* 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 " TAR_PERM_ATTR_ARGS " --directory=%s/%s/%i/ "
"--numeric-owner -Jcf %s/%i/pack-%s-from-%i.tar delta staged",
packstage_dir, pack->module, pack->from, staging_dir, pack->to, pack->module, pack->from);
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);
LOG(NULL, "finished tar for pack", "%s: %i to %i", pack->module, pack->from, pack->to);
@@ -466,13 +516,12 @@ static int make_final_pack(struct packdata *pack)
/* and clean up */
free_manifest(pack->end_manifest);
empty_pack_stage(1, pack->from, pack->module);
empty_pack_stage(1, pack->from, pack->to, pack->module);
LOG(NULL, "pack complete", "%s: %i to %i", pack->module, pack->from, pack->to);
return ret;
}
/* Returns 0 == success, -1 == failure */
int make_pack(struct packdata *pack)
{
+7 -14
View File
@@ -35,19 +35,16 @@
#include "swupd.h"
#include <magic.h>
static magic_t mcookie;
double rename_score(struct file *old, struct file *new)
{
double score = 0.0;
char *c;
int io, in;
/* if we have the same hash... sounds like a winner */
if (hash_compare(old->hash, new->hash)) {
score += 400;
@@ -88,14 +85,14 @@ double rename_score(struct file *old, struct file *new)
io--;
in--;
}
/* if both start with /boot/vmlinuz give it a boost; this is a local hack due to vmlinuz being very short */
if (strncmp(old->filename, "/boot/vmlinuz", 13) == 0 && strncmp(new->filename, "/boot/vmlinuz", 13) == 0) {
score += 80;
}
/* if ELF, points for sharing the same soname to the first dot */
/* negative points for not being within 25%+/-1Kb of the same file size */
if (old->stat.st_size > ((new->stat.st_size * 1.25) + 1024)) {
score -= 30;
@@ -152,7 +149,7 @@ static void precompute_file_data(struct manifest *manifest, struct file *file, i
c2++;
}
if (manifest) {
if (manifest) {
string_or_die(&filename, "%s/%i/%s/%s", image_dir, manifest->version, manifest->component, file->filename);
} else if (old_rename) {
item = g_list_first(last_versions_list);
@@ -186,7 +183,7 @@ static void precompute_file_data(struct manifest *manifest, struct file *file, i
}
}
c1 = (char *) magic_file(mcookie, filename);
c1 = (char *)magic_file(mcookie, filename);
if (c1) {
char *c2;
file->filetype = strdup(c1);
@@ -205,17 +202,15 @@ static void precompute_file_data(struct manifest *manifest, struct file *file, i
free(filename);
file->basename = strdup(basename(file->filename));
file->dirname = strdup(dirname(file->filename));
file->dirname = strdup(dirname(file->filename));
}
int file_sort_score(gconstpointer a, gconstpointer b)
{
struct file *A, *B;
A = (struct file *) a;
B = (struct file *) b;
A = (struct file *)a;
B = (struct file *)b;
if (A->rename_score > B->rename_score) {
return -1;
@@ -240,7 +235,6 @@ static void score_file(GList *deleted_files, struct file *file)
file2 = list2->data;
list2 = g_list_next(list2);
assert(file2);
assert(file2->peer);
@@ -249,7 +243,6 @@ static void score_file(GList *deleted_files, struct file *file)
file->rename_score = score;
file->rename_peer = file2;
}
}
}
+6 -6
View File
@@ -36,8 +36,8 @@
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";
"-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;
@@ -61,7 +61,7 @@ bool signature_initialize(void)
struct stat s;
if (initialized) {
return true;
return true;
}
cdir = getenv("SWUPD_CERTS_DIR");
if (cdir == NULL || cdir[0] == '\0') {
@@ -70,7 +70,7 @@ bool signature_initialize(void)
}
if (stat(cdir, &s)) {
printf("Can't stat certificates directory '%s' (%s)\n", cdir,
strerror(errno));
strerror(errno));
goto err;
}
leaf_key = make_filename(cdir, "LEAF_KEY", "leaf key");
@@ -91,7 +91,7 @@ bool signature_initialize(void)
}
if (stat(passphrase, &s)) {
printf("Can't stat '%s' (%s)\n", passphrase,
strerror(errno));
strerror(errno));
goto err;
}
initialized = true;
@@ -161,7 +161,7 @@ bool signature_sign(const char *filename)
return false;
}
string_or_die(&cmd, CMD_FMT, filename, filename, leaf_key, leaf_cert,
ca_chain_cert, passphrase);
ca_chain_cert, passphrase);
status = system(cmd);
if (status) {
printf("Bad status %d from signing command:%s\n", status, cmd);
-7
View File
@@ -32,16 +32,12 @@
#include "swupd.h"
static int new_files;
static int deleted_files;
static int changed_files;
static int delta_miss;
static int delta_hit;
void account_new_file(void)
{
new_files++;
@@ -62,7 +58,6 @@ void account_delta_hit(void)
delta_hit++;
}
void account_delta_miss(void)
{
delta_miss++;
@@ -84,8 +79,6 @@ int have_new_files(void)
return 0;
}
void print_statistics(int version1, int version2)
{
printf("\n");
+2 -2
View File
@@ -76,7 +76,7 @@ static bool type_has_changed(struct file *file)
LOG(file, "Type change", "%c to %c", type1, type2);
fprintf(stderr, "Type change from %c to %c for %s\n", type1, type2,
file->filename);
file->filename);
if (((type1 == 'F') && (type2 == 'L')) ||
((type1 == 'F') && (type2 == 'D')) ||
@@ -106,7 +106,7 @@ void type_change_detection(struct manifest *manifest)
if (n != 0) {
printf("Detected %d file type changes in component %s.. exiting\n",
n, manifest->component);
n, manifest->component);
exit(EXIT_FAILURE);
}
}
+10 -11
View File
@@ -39,7 +39,6 @@
int current_version;
void read_current_version(char *filename)
{
FILE *file;
@@ -47,8 +46,7 @@ void read_current_version(char *filename)
char *fullfile = NULL;
char *conf;
conf = config_image_base();
conf = config_image_base();
string_or_die(&fullfile, "%s/%s", conf, filename);
@@ -79,8 +77,7 @@ void write_new_version(char *filename, int version)
char *fullfile = NULL;
char *conf;
conf = config_image_base();
conf = config_image_base();
string_or_die(&fullfile, "%s/%s", conf, filename);
@@ -132,7 +129,7 @@ void write_cookiecrumbs_to_download_area(int version)
char *conf;
char *cmd;
conf = config_output_dir();
conf = config_output_dir();
if (conf == NULL) {
assert(0);
}
@@ -179,7 +176,8 @@ static int compare_versions(gconstpointer a, gconstpointer b)
return GPOINTER_TO_INT(b) - GPOINTER_TO_INT(a);
}
static int get_build_type(int build_num) {
static int get_build_type(int build_num)
{
int build_type = build_num % 10;
if (build_type == 0) {
return REGULAR_BUILD;
@@ -190,7 +188,8 @@ static int get_build_type(int build_num) {
}
}
static int get_jump_point(int build_num) {
static int get_jump_point(int build_num)
{
int jump_point = (build_num / 100) * 100;
if (jump_point == build_num) {
jump_point -= 100;
@@ -218,7 +217,7 @@ GList *get_last_versions_list(int next_version, int max_versions)
dir = opendir(staging_dir);
if (dir == NULL) {
LOG(NULL, "Cannot open directory", "dir_path= %s, strerror= %s",
staging_dir, strerror(errno));
staging_dir, strerror(errno));
return NULL;
}
@@ -232,7 +231,7 @@ GList *get_last_versions_list(int next_version, int max_versions)
if (lstat(filename, &stat)) {
LOG(NULL, "lstat failed", "path= %s, strerror= %s",
filename, strerror(errno));
filename, strerror(errno));
continue;
}
@@ -272,7 +271,7 @@ GList *get_last_versions_list(int next_version, int max_versions)
build_type = get_build_type(build_num);
next_item = g_list_next(cur_item);
if ((idx >= max_versions || build_type == DEV_BUILD) &&
build_num != jump_point && build_num != 0) {
build_num != jump_point && build_num != 0) {
list = g_list_delete_link(list, cur_item);
} else if (idx == max_versions - 1 && build_num != 0) {
list = g_list_delete_link(list, cur_item);
+12 -11
View File
@@ -49,8 +49,8 @@ static int xattr_get_value(const char *path, const char *name, char **blob,
len = lgetxattr(path, name, NULL, 0);
if (len < 0) {
LOG(NULL, "Failed to get x-attribute length",
"%s for file %s: %s",
name, path, strerror(errno));
"%s for file %s: %s",
name, path, strerror(errno));
return -1;
}
@@ -61,7 +61,7 @@ static int xattr_get_value(const char *path, const char *name, char **blob,
/* realloc needed len + 1 in case we need to add final zero
* to ensure consistent blob */
value = realloc(*blob, *blob_len + len +
(action == XATTRS_ACTION_GET_BLOB ? 1 : 0));
(action == XATTRS_ACTION_GET_BLOB ? 1 : 0));
assert(value);
*blob = value;
@@ -70,8 +70,8 @@ static int xattr_get_value(const char *path, const char *name, char **blob,
len = lgetxattr(path, name, value, len);
if (len < 0) {
LOG(NULL, "Failed to get x-attribute",
"%s for file %s: %s",
name, path, strerror(errno));
"%s for file %s: %s",
name, path, strerror(errno));
return -1;
}
@@ -107,7 +107,7 @@ static int get_xattr_name_count(const char *names_list, ssize_t len)
static int cmp_xattr_name_ptrs(const void *ptr1, const void *ptr2)
{
return strcmp(*(char * const *)ptr1, *(char * const *)ptr2);
return strcmp(*(char *const *)ptr1, *(char *const *)ptr2);
}
static const char **get_sorted_xattr_name_table(const char *names, int n)
@@ -115,7 +115,7 @@ static const char **get_sorted_xattr_name_table(const char *names, int n)
const char **table;
int i;
table = calloc(1, n * sizeof(char*));
table = calloc(1, n * sizeof(char *));
assert(table);
for (i = 0; i < n; i++) {
@@ -123,7 +123,7 @@ static const char **get_sorted_xattr_name_table(const char *names, int n)
names += strlen(names) + 1;
}
qsort(table, n, sizeof(char*), cmp_xattr_name_ptrs);
qsort(table, n, sizeof(char *), cmp_xattr_name_ptrs);
return table;
}
@@ -131,7 +131,8 @@ static const char **get_sorted_xattr_name_table(const char *names, int n)
static void xattrs_do_action(xattrs_action_type_t action,
const char *src_filename,
const char *dst_filename,
char **blob, size_t *blob_len) {
char **blob, size_t *blob_len)
{
ssize_t len;
char *list;
int ret = 0;
@@ -201,8 +202,8 @@ static void xattrs_do_action(xattrs_action_type_t action,
free(value);
if (ret < 0) {
LOG(NULL, "Failed to set x-attributes",
"%s: %s",
dst_filename, strerror(errno));
"%s: %s",
dst_filename, strerror(errno));
break;
}
value_len = 0;
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bats
@test "create_update help output" {
run $srcdir/swupd_create_update --help
[ "$status" -eq 1 ]
run $srcdir/swupd_create_update -h
[ "$status" -eq 1 ]
}
@test "make_fullfiles help output" {
run $srcdir/swupd_make_fullfiles --help
[ "$status" -eq 1 ]
run $srcdir/swupd_make_fullfiles -h
[ "$status" -eq 1 ]
}
@test "make_pack help output" {
run $srcdir/swupd_make_pack --help
[ "$status" -eq 1 ]
run $srcdir/swupd_make_pack -h
[ "$status" -eq 1 ]
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
+58
View File
@@ -0,0 +1,58 @@
#!/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
+35
View File
@@ -0,0 +1,35 @@
#!/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
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env bats
@test "make_fullfiles required arg" {
run $srcdir/swupd_make_fullfiles
[ "$status" -eq 1 ]
}
@test "make_fullfiles too many arguments" {
# exactly one argument must be passed
run $srcdir/swupd_make_fullfiles foo bar
[ "$status" -eq 1 ]
}
@test "make_fullfiles root priv check" {
run $srcdir/swupd_make_fullfiles foo
[ "$status" -eq 1 ]
[[ "$output" =~ "not being run as root.. exiting" ]]
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bats
@test "make_pack required arg" {
run $srcdir/swupd_make_pack
[ "$status" -eq 1 ]
}
@test "make_pack too few arguments" {
run $srcdir/swupd_make_pack foo
[ "$status" -eq 1 ]
run $srcdir/swupd_make_pack foo bar
[ "$status" -eq 1 ]
}
@test "make_pack too many arguments" {
run $srcdir/swupd_make_pack foo bar foo bar
[ "$status" -eq 1 ]
}
@test "make_pack root priv check" {
run $srcdir/swupd_make_pack foo bar foo
[ "$status" -eq 1 ]
[[ "$output" =~ "not being run as root.. exiting" ]]
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
+61
View File
@@ -0,0 +1,61 @@
# 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
}
init_server_ini() {
cp $srcdir/server.ini $DIR
sed -i "s|/var/lib/update|$DIR|" $DIR/server.ini
}
set_latest_ver() {
echo "$1" > $DIR/image/latest.version
}
init_groups_ini() {
for bundle in "$@"; do
cat >> $DIR/groups.ini << EOF
[$bundle]
group=$bundle
EOF
done
}
set_os_release() {
local ver=$1
local bundle=$2
mkdir -p $DIR/image/$ver/$bundle/usr/lib/
echo "VERSION_ID=$ver" > $DIR/image/$ver/$bundle/usr/lib/os-release
}
track_bundle() {
local ver=$1
local bundle=$2
mkdir -p $DIR/image/$ver/$bundle/usr/share/clear/bundles
touch $DIR/image/$ver/$bundle/usr/share/clear/bundles/$bundle
}
gen_file_to_delta() {
local origver=$1
local origsize=$2
local newver=$3
local newbytes=$4
local bundle=$5
# create some random data for the original version
mkdir -p $DIR/image/$origver/$bundle
dd if=/dev/urandom of=$DIR/image/$origver/$bundle/randomfile bs=1 count=$origsize
# append more random data to the end of the file in the new version
TMP=$(mktemp foo.XXXXXX)
mkdir -p $DIR/image/$newver/$bundle
dd if=/dev/urandom of=$TMP bs=1 count=$newbytes
cat $DIR/image/$origver/$bundle/randomfile $TMP > $DIR/image/$newver/$bundle/randomfile
rm $TMP
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bats
@test "create_update required arg" {
run $srcdir/swupd_create_update
[ "$status" -eq 1 ]
[[ "$output" =~ "Missing version parameter:" ]]
}
@test "create_update root priv check" {
run $srcdir/swupd_create_update -o 10
[ "$status" -eq 1 ]
[[ "$output" =~ "not being run as root.. exiting" ]]
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80