Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 77f16b0

Browse files
William Douglasbryteise
authored andcommitted
Add new handling for modifier field
The modifier field will be a character that translates roughly into a base64 encoded bitmask. The first 3 bytes are the optimization level and the last three are the max optimization level any files with that same filename can have. For now though skip all lines that don't match SSE_OPT (the previous values the modifier field would have: 'b', 's' and 'C' all map to the SSE_OPT bitmask). Also rework the manifest unit tests a bit more. Noticed the exported flag was wrong in the data and the X flag for the 3rd field was completely unchecked for in swupd code. Added testing for the ignored 'b', 's' and 'C' values of the modifier field and checked the non-sse is in fact skipped as a file for now. Signed-off-by: William Douglas <[email protected]>
1 parent bf3b020 commit 77f16b0

File tree

4 files changed

+58
-17
lines changed

4 files changed

+58
-17
lines changed

src/swupd.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ struct update_stat {
109109
/* +1 for null termination */
110110
#define SWUPD_HASH_LEN (DIGEST_LEN_SHA256 + 1)
111111

112+
/* Can support 7 different levels */
113+
#define SSE_OPT 0x0
114+
#define V3_OPT 0x1
115+
#define V4_OPT 0x2
116+
117+
#define MAX_OPT(opt) (opt) > 3
118+
112119
struct file {
113120
char *filename;
114121
char hash[SWUPD_HASH_LEN];
@@ -132,6 +139,8 @@ struct file {
132139
unsigned int is_exported : 1;
133140
unsigned int do_not_update : 1;
134141

142+
unsigned char opt_mask;
143+
135144
struct file *peer; /* same file in another manifest */
136145
struct header *header;
137146
char *staging;

src/swupd_lib/manifest_parser.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@
2626
#define MANIFEST_LINE_MAXLEN (PATH_MAX * 2)
2727
#define MANIFEST_HEADER "MANIFEST\t"
2828

29+
/* Below generated with the following:
30+
31+
unsigned char lt[256] = ".acdefghijklmnopqrtuvwxyzABDEFGHIJKLMNOPQRSTUVWXYZ09123456789#^*bsC";
32+
unsigned char ltr[256] = {0};
33+
for (unsigned i = 0; i < 256; i++) {
34+
ltr[lt[i]] = i;
35+
}
36+
ltr[0] = 0;
37+
ltr['b'] = ltr['s'] = ltr['C'] = 0;
38+
39+
printf("static unsigned char OPTIMIZED_BITMASKS[256] = { ");
40+
for (int i = 0; i < 256; i++) {
41+
printf("0x%X, ", ltr[i]);
42+
}
43+
printf("};\n");
44+
*/
45+
46+
/* Changes to the OPTIMIZED_BITMASKS array require a format bump and corresponding mixer change */
47+
static unsigned char OPTIMIZED_BITMASKS[256] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3D, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3F, 0x0, 0x0, 0x0, 0x0, 0x0, 0x32, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x19, 0x1A, 0x0, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x0, 0x0, 0x0, 0x3E, 0x0, 0x0, 0x1, 0x0, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x0, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
48+
2949
struct manifest *manifest_parse(const char *component, const char *filename, bool header_only)
3050
{
3151
FILE *infile;
@@ -193,6 +213,12 @@ struct manifest *manifest_parse(const char *component, const char *filename, boo
193213
file->is_experimental = 1;
194214
}
195215

216+
file->opt_mask = OPTIMIZED_BITMASKS[(unsigned char)line[2]];
217+
if (file->opt_mask != SSE_OPT) {
218+
FREE(file);
219+
continue;
220+
}
221+
196222
if (line[3] == 'r') {
197223
/* rename flag is ignored */
198224
} else if (line[3] == 'x') {

test/unit/data/mom2

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ X... 0000000000000000000000000000000000000000000000000000000000000004 30 f4
1616
.d.. 0000000000000000000000000000000000000000000000000000000000000005 30 f5
1717
.g.. 0000000000000000000000000000000000000000000000000000000000000006 30 f6
1818
.e.. 0000000000000000000000000000000000000000000000000000000000000007 30 f7
19-
..X. 0000000000000000000000000000000000000000000000000000000000000008 30 f8
20-
...r 0000000000000000000000000000000000000000000000000000000000000009 30 f9
21-
...X 0000000000000000000000000000000000000000000000000000000000000010 30 f10
19+
...r 0000000000000000000000000000000000000000000000000000000000000008 30 f8
20+
...x 0000000000000000000000000000000000000000000000000000000000000009 30 f9
21+
..C. 0000000000000000000000000000000000000000000000000000000000000010 30 f10
22+
..b. 0000000000000000000000000000000000000000000000000000000000000011 30 f11
23+
..s. 0000000000000000000000000000000000000000000000000000000000000012 30 f12
24+
..a. 0000000000000000000000000000000000000000000000000000000000000013 30 f12

test/unit/test_manifest.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "swupd.h"
2424
#include "test_helper.h"
2525

26-
static void validate_file(struct list *files, const char *filename, int version, int hash, int is_dir, int is_file, int is_link, int is_deleted, int is_ghosted, int is_manifest, int is_experimental)
26+
static void validate_file(struct list *files, const char *filename, int version, int hash, int is_dir, int is_file, int is_link, int is_deleted, int is_ghosted, int is_manifest, int is_experimental, int is_exported)
2727
{
2828
struct list *list;
2929
char hash_str[SWUPD_HASH_LEN];
@@ -40,6 +40,7 @@ static void validate_file(struct list *files, const char *filename, int version,
4040
check(file->is_ghosted == is_ghosted);
4141
check(file->is_manifest == is_manifest);
4242
check(file->is_experimental == is_experimental);
43+
check(file->is_exported == is_exported);
4344

4445
check(file->last_change == version);
4546

@@ -89,21 +90,23 @@ static void test_manifest_parse()
8990
// Check if parser can parse all different flags supported for the file list
9091
manifest = manifest_parse_test("test", dir, "data/mom2", false);
9192
check(manifest != NULL);
92-
check(list_len(manifest->files) == 10);
93+
check(list_len(manifest->files) == 12);
9394
check(list_len(manifest->manifests) == 1);
9495

95-
validate_file(manifest->manifests, "m1", 10, 1, 0, 0, 0, 0, 0, 1, 0);
96-
97-
validate_file(manifest->files, "f1", 20, 1, 0, 1, 0, 0, 0, 0, 0);
98-
validate_file(manifest->files, "f2", 30, 2, 1, 0, 0, 0, 0, 0, 0);
99-
validate_file(manifest->files, "f3", 30, 3, 0, 0, 1, 0, 0, 0, 0);
100-
validate_file(manifest->files, "f4", 30, 4, 0, 0, 0, 0, 0, 0, 0);
101-
validate_file(manifest->files, "f5", 30, 5, 0, 0, 0, 1, 0, 0, 0);
102-
validate_file(manifest->files, "f6", 30, 6, 0, 0, 0, 1, 1, 0, 0);
103-
validate_file(manifest->files, "f7", 30, 7, 0, 0, 0, 0, 0, 0, 1);
104-
validate_file(manifest->files, "f8", 30, 8, 0, 0, 0, 0, 0, 0, 0);
105-
validate_file(manifest->files, "f9", 30, 9, 0, 0, 0, 0, 0, 0, 0);
106-
validate_file(manifest->files, "f10", 30, 10, 0, 0, 0, 0, 0, 0, 0);
96+
validate_file(manifest->manifests, "m1", 10, 1, 0, 0, 0, 0, 0, 1, 0, 0);
97+
98+
validate_file(manifest->files, "f1", 20, 1, 0, 1, 0, 0, 0, 0, 0, 0);
99+
validate_file(manifest->files, "f2", 30, 2, 1, 0, 0, 0, 0, 0, 0, 0);
100+
validate_file(manifest->files, "f3", 30, 3, 0, 0, 1, 0, 0, 0, 0, 0);
101+
validate_file(manifest->files, "f4", 30, 4, 0, 0, 0, 0, 0, 0, 0, 0);
102+
validate_file(manifest->files, "f5", 30, 5, 0, 0, 0, 1, 0, 0, 0, 0);
103+
validate_file(manifest->files, "f6", 30, 6, 0, 0, 0, 1, 1, 0, 0, 0);
104+
validate_file(manifest->files, "f7", 30, 7, 0, 0, 0, 0, 0, 0, 1, 0);
105+
validate_file(manifest->files, "f8", 30, 8, 0, 0, 0, 0, 0, 0, 0, 0);
106+
validate_file(manifest->files, "f9", 30, 9, 0, 0, 0, 0, 0, 0, 0, 1);
107+
validate_file(manifest->files, "f10", 30, 10, 0, 0, 0, 0, 0, 0, 0, 0);
108+
validate_file(manifest->files, "f11", 30, 11, 0, 0, 0, 0, 0, 0, 0, 0);
109+
validate_file(manifest->files, "f12", 30, 12, 0, 0, 0, 0, 0, 0, 0, 0);
107110

108111
manifest_free(manifest);
109112

0 commit comments

Comments
 (0)