aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-core/swupd-server/swupd-server-2.53/0001-Add-option-S-to-take-the-state-data-dir-as-an-argume.patch
blob: 6ae3c522b474efbd84bfad7ef4893a0f004bc07c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
From 4a3c91466e0782885fe980b659a6f6ac4835fe8a Mon Sep 17 00:00:00 2001
From: Joshua Lock <joshua.g.lock@intel.com>
Date: Thu, 28 Jan 2016 10:24:56 +0000
Subject: [PATCH] Add option -S to take the state data dir as an argument

The optional -S option expects a full path to a directory
swupd-server should use instead of the default /var/lib/update.

Signed-off-by: Joshua Lock <joshua.g.lock@intel.com>

Upstream-Status: Accepted (v3.0+)

---
 include/swupd.h      | 11 ++++++---
 src/analyze_fs.c     |  4 ++--
 src/chroot.c         | 13 ++++++-----
 src/globals.c        | 53 +++++++++++++++++++++++++++++++++++++++++
 src/main.c           | 50 ++++++++++++++++++++++++++++++---------
 src/make_fullfiles.c | 63 +++++++++++++++++++++++++++++++++++++++++++++----
 src/make_packs.c     | 66 ++++++++++++++++++++++++++++++++++++++++++++--------
 src/pack.c           | 65 +++++++++++++++++++++++++++------------------------
 src/rename.c         |  6 ++---
 src/versions.c       |  6 ++---
 10 files changed, 264 insertions(+), 73 deletions(-)

diff --git a/include/swupd.h b/include/swupd.h
index 00b88d4..522ac2e 100644
--- a/include/swupd.h
+++ b/include/swupd.h
@@ -16,9 +16,6 @@
 #define SWUPD_DEFAULT_FORMAT	3
 
 #define SWUPD_SERVER_STATE_DIR "/var/lib/update"
-#define PACKSTAGE_DIR SWUPD_SERVER_STATE_DIR "/packstage"
-#define IMAGE_DIR SWUPD_SERVER_STATE_DIR "/image"
-#define STAGING_DIR SWUPD_SERVER_STATE_DIR "/www"
 
 #if SWUPD_WITH_SELINUX
 #define TAR_PERM_ATTR_ARGS "--preserve-permissions --xattrs --xattrs-include='*' --selinux"
@@ -123,9 +120,17 @@ extern int newversion;
 extern int minversion;
 extern char *format_string;
 
+extern char *state_dir;
+extern char *packstage_dir;
+extern char *image_dir;
+extern char *staging_dir;
+
 extern bool init_globals(void);
 extern void free_globals(void);
 extern bool set_format_string(char *);
+extern bool set_state_dir(char *);
+extern bool init_state_globals(void);
+extern void free_state_globals(void);
 
 extern int file_sort_hash(gconstpointer a, gconstpointer b);
 extern int file_sort_filename(gconstpointer a, gconstpointer b);
diff --git a/src/analyze_fs.c b/src/analyze_fs.c
index 4d01ccf..f6cfa13 100644
--- a/src/analyze_fs.c
+++ b/src/analyze_fs.c
@@ -389,7 +389,7 @@ struct manifest *full_manifest_from_directory(int version)
 
 	manifest = alloc_manifest(version, "full");
 
-	string_or_die(&dir, "%s/%i/full", IMAGE_DIR, version);
+	string_or_die(&dir, "%s/%i/full", image_dir, version);
 
 	threadpool = g_thread_pool_new(get_hash, dir, 12, FALSE, NULL);
 
@@ -413,7 +413,7 @@ struct manifest *sub_manifest_from_directory(char *component, int version)
 
 	manifest = alloc_manifest(version, component);
 
-	string_or_die(&dir, "%s/%i/%s", IMAGE_DIR, version, component);
+	string_or_die(&dir, "%s/%i/%s", image_dir, version, component);
 
 	iterate_directory(manifest, dir, "", false);
 
diff --git a/src/chroot.c b/src/chroot.c
index d85b5f7..cb6a04a 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -41,14 +41,15 @@ void chroot_create_full(int newversion)
 	struct stat buf;
 	char *full_dir;
 
-	string_or_die(&full_dir, "%s/%i/full/", IMAGE_DIR, newversion);
+	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 " IMAGE_DIR "/%i/os-core/ %s", newversion, full_dir);
+	string_or_die(&command, "rsync -aAX %s/%i/os-core/ %s",
+	              image_dir, newversion, full_dir);
 	ret = system(command);
 	assert(ret==0);
 	free(command);
@@ -61,8 +62,8 @@ void chroot_create_full(int newversion)
 		}
 
 		LOG(NULL, "Overlaying bundle chroot onto full", "%s", group);
-		string_or_die(&command, "rsync -aAX --ignore-existing " IMAGE_DIR "/%i/%s/ %s",
-		             newversion, group, full_dir);
+		string_or_die(&command, "rsync -aAX --ignore-existing %s/%i/%s/ %s",
+		             image_dir, newversion, group, full_dir);
 		ret = system(command);
 		assert(ret==0);
 		free(command);
@@ -81,8 +82,8 @@ void chroot_create_full(int newversion)
 		}
 
 		LOG(NULL, "Recopy bundle chroot out of full", "%s", group);
-		string_or_die(&command, "rsync -aAX --existing %s " IMAGE_DIR "/%i/%s",
-		             full_dir, newversion, group);
+		string_or_die(&command, "rsync -aAX --existing %s %s/%i/%s",
+		             full_dir, image_dir, newversion, group);
 		ret = system(command);
 		assert(ret==0);
 		free(command);
diff --git a/src/globals.c b/src/globals.c
index 32dc793..ff6a3fa 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -34,6 +34,11 @@ int newversion = -1;
 int minversion = 0;
 char *format_string = NULL;
 
+char *state_dir = NULL;
+char *packstage_dir = NULL;
+char *image_dir = NULL;
+char *staging_dir = NULL;
+
 bool set_format_string(char *userinput)
 {
 	int version;
@@ -52,12 +57,36 @@ bool set_format_string(char *userinput)
 	return true;
 }
 
+bool set_state_dir(char *dir)
+{
+	if (dir == NULL || dir[0] == '\0') {
+		return false;
+	}
+
+	/* TODO: more validation of input? */
+	if (dir[0] != '/') {
+		printf("statedir must be a full path starting with '/', not '%c'\n", dir[0]);
+		return false;
+	}
+
+	if (state_dir) {
+		free(state_dir);
+	}
+	string_or_die(&state_dir, "%s", dir);
+
+	return true;
+}
+
 bool init_globals(void)
 {
 	if (format_string == NULL) {
 		string_or_die(&format_string, "%d", SWUPD_DEFAULT_FORMAT);
 	}
 
+	if (!init_state_globals()) {
+		return false;
+	}
+
 	if (newversion == -1) {
 		printf("Missing version parameter: No new version number specified\n");
 		return false;
@@ -71,4 +100,28 @@ bool init_globals(void)
 void free_globals(void)
 {
 	free(format_string);
+	free(state_dir);
+	free(packstage_dir);
+	free(image_dir);
+	free(staging_dir);
+}
+
+bool init_state_globals(void)
+{
+	if (state_dir == NULL) {
+		string_or_die(&state_dir, "%s", SWUPD_SERVER_STATE_DIR);
+	}
+	string_or_die(&packstage_dir, "%s/%s", state_dir, "packstage");
+	string_or_die(&image_dir, "%s/%s", state_dir, "image");
+	string_or_die(&staging_dir, "%s/%s", state_dir, "www");
+
+	return true;
+}
+
+void free_state_globals(void)
+{
+	free(state_dir);
+	free(packstage_dir);
+	free(image_dir);
+	free(staging_dir);
 }
diff --git a/src/main.c b/src/main.c
index ccfedfd..9366cd9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -55,6 +55,7 @@ static const struct option prog_opts[] = {
 	{"minversion", required_argument, 0, 'm'},
 	{"format", required_argument, 0, 'F'},
 	{"getformat", no_argument, 0, 'g'},
+	{"statedir", required_argument, 0, 'S'},
 	{0, 0, 0, 0}
 };
 
@@ -70,6 +71,7 @@ static void print_help(const char *name) {
 	printf("   -m, --minversion        Optional minimum file version to write into manifests per file\n");
 	printf("   -F, --format            Optional format string [ default:=%d ]\n", SWUPD_DEFAULT_FORMAT);
 	printf("   -g, --getformat         Print current format string and exit\n");
+	printf("   -S, --statedir          Optional directory to use for state [ default:=%s ]\n", SWUPD_SERVER_STATE_DIR);
 	printf("\n");
 }
 
@@ -77,7 +79,7 @@ static bool parse_options(int argc, char **argv)
 {
 	int opt;
 
-	while ((opt = getopt_long(argc, argv, "hvo:m:F:g", prog_opts, NULL)) != -1) {
+	while ((opt = getopt_long(argc, argv, "hvo:m:F:g:S:", prog_opts, NULL)) != -1) {
 		switch (opt) {
 		case '?':
 		case 'h':
@@ -107,6 +109,12 @@ static bool parse_options(int argc, char **argv)
 				return false;
 			}
 			break;
+		case 'S':
+			if (!optarg || !set_state_dir(optarg)) {
+				printf("Invalid --statedir argument ''%s'\n\n", optarg);
+				return false;
+			}
+			break;
 		case 'g':
 			if (format_string == NULL) {
 				printf("%d\n", SWUPD_DEFAULT_FORMAT);
@@ -138,9 +146,14 @@ static void check_root(void)
 static void populate_dirs(int version)
 {
 	char *newversiondir;
-	string_or_die(&newversiondir, "%s/%d", IMAGE_DIR, version);
+
+	string_or_die(&newversiondir, "%s/%d", image_dir, version);
 
 	if ((access(newversiondir, F_OK | R_OK) != 0) && (version == 0)) {
+		char *latestpath = NULL;
+
+		string_or_die(&latestpath, "%s/latest.version", image_dir);
+
 		printf("** %s does not exist... creating and populating\n", newversiondir);
 		if (mkdir(newversiondir, 0755) != 0) {
 			printf("Failed to create directory\n");
@@ -151,14 +164,17 @@ static void populate_dirs(int version)
 		}
 
 		FILE *latestver;
-		latestver = fopen_exclusive(IMAGE_DIR "/latest.version");
+		latestver = fopen_exclusive(latestpath);
 		if (latestver == NULL) {
-			printf("Failed to create %s/latest.version\n", IMAGE_DIR);
+			printf("Failed to create %s\n", latestpath);
+			free(latestpath);
 			return;
 		}
 		if (fwrite("0\n", 2, 1, latestver) != 1) {
 			LOG(NULL, "Failed to write latestver", "errno: %d", errno);
 		}
+
+		free(latestpath);
 		fclose(latestver);
 	}
 	/* groups don't exist in version 0 */
@@ -170,7 +186,7 @@ static void populate_dirs(int version)
 				break;
 			}
 
-			string_or_die(&newversiondir, "%s/%d/%s", IMAGE_DIR, version, group);
+			string_or_die(&newversiondir, "%s/%d/%s", image_dir, version, group);
 
 			/* Create the bundle directory(s) as needed */
 			if (access(newversiondir, F_OK | R_OK) != 0) {
@@ -186,13 +202,18 @@ static void populate_dirs(int version)
 
 static int check_build_env(void)
 {
-	if (access(SWUPD_SERVER_STATE_DIR "/temp", F_OK | R_OK) != 0) {
-		LOG(NULL, "/var/lib/update/temp does not exist...creating directory", "");
-		if (mkdir(SWUPD_SERVER_STATE_DIR "/temp", 0755) != 0) {
+	char *temp_dir = NULL;
+	string_or_die(&temp_dir, "%s/%s", state_dir, "/temp");
+
+	if (access(temp_dir, F_OK | R_OK) != 0) {
+		LOG(NULL, "%s", "does not exist...creating directory", temp_dir);
+		if (mkdir(temp_dir, 0755) != 0) {
 			printf("Failed to create build directory, EXITING\n");
+			free(temp_dir);
 			return -errno;
 		}
 	}
+	free(temp_dir);
 
 	return 0;
 }
@@ -217,6 +238,8 @@ int main(int argc, char **argv)
 	int exit_status = EXIT_FAILURE;
 	int ret;
 
+	char *file_path = NULL;
+
 	/* keep valgrind working well */
 	setenv("G_SLICE", "always-malloc", 0);
 
@@ -240,12 +263,17 @@ int main(int argc, char **argv)
 	}
 
 
-	if (!read_configuration_file(SWUPD_SERVER_STATE_DIR "/server.ini")) {
-		printf("Failed to read " SWUPD_SERVER_STATE_DIR "/server.ini configuration file!\n");
+	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);
+		free(file_path);
 		goto exit;
 	}
+	free(file_path);
 
-	read_group_file(SWUPD_SERVER_STATE_DIR "/groups.ini");
+	string_or_die(&file_path, "%s/groups.ini", state_dir);
+	read_group_file(file_path);
+	free(file_path);
 
 	read_current_version("latest.version");
 	printf("Last processed version is %i\n", current_version);
diff --git a/src/make_fullfiles.c b/src/make_fullfiles.c
index e755a33..bf97a1c 100644
--- a/src/make_fullfiles.c
+++ b/src/make_fullfiles.c
@@ -27,8 +27,52 @@
 #include <string.h>
 #include <assert.h>
 
+#include <getopt.h>
+
 #include <swupd.h>
 
+static const struct option prog_opts[] = {
+	{"help", no_argument, 0, 'h'},
+	{"statedir", required_argument, 0, 'S'},
+	{0, 0, 0, 0}
+};
+
+static void usage(const char *name)
+{
+	printf("usage:\n");
+	printf("   %s <version>\n\n", name);
+	printf("Help options:\n");
+	printf("   -h, --help              Show help options\n");
+	printf("   -S, --statedir          Optional directory to use for state [ default:=%s ]\n", SWUPD_SERVER_STATE_DIR);
+	printf("\n");
+}
+
+static bool parse_options(int argc, char **argv)
+{
+	int opt;
+
+	while ((opt = getopt_long(argc, argv, "hS:", prog_opts, NULL)) != -1) {
+		switch (opt) {
+			case '?':
+			case 'h':
+				usage(argv[0]);
+				return false;
+			case 'S':
+				if (!optarg || !set_state_dir(optarg)) {
+					printf("Invalid --statedir argument '%s'\n\n", optarg);
+					return false;
+				}
+				break;
+		}
+	}
+
+	if (!init_state_globals()) {
+		return false;
+	}
+
+	return true;
+}
+
 static void banner(void)
 {
 	printf(PACKAGE_NAME " update creator -- fullfiles -- version " PACKAGE_VERSION "\n");
@@ -51,20 +95,29 @@ int main(int argc, char **argv)
 {
 	struct manifest *manifest;
 	int version;
+	char *file_path = NULL;
 
 	/* keep valgrind working well */
 	setenv("G_SLICE", "always-malloc", 0);
 
+	if (!parse_options(argc, argv)) {
+		free_state_globals();
+		return EXIT_FAILURE;
+	}
 	banner();
 	check_root();
 
-	read_configuration_file(SWUPD_SERVER_STATE_DIR "/server.ini");
+	string_or_die(&file_path, "%s/server.ini", state_dir);
+	read_configuration_file(file_path);
+	free(file_path);
 
-	if (argc < 1) {
-		printf("Usage:\n\tswupd_make_fullfiles <version>\n\n");
+	if (argc - optind < 1) {
+		usage(argv[0]);
+		free_state_globals();
 		exit(EXIT_FAILURE);
 	}
-	version = strtoull(argv[1], NULL, 10);
+
+	version = strtoull(argv[optind++], NULL, 10);
 	if (version < 0) {
 		printf("Usage:\n\tswupd_make_fullfiles <version>\n\n");
 		exit(EXIT_FAILURE);
@@ -73,5 +126,7 @@ int main(int argc, char **argv)
 	manifest = manifest_from_file(version, "full");
 	create_fullfiles(manifest);
 
+	free_state_globals();
+
 	return EXIT_SUCCESS;
 }
diff --git a/src/make_packs.c b/src/make_packs.c
index 20fbd67..2b62b8a 100644
--- a/src/make_packs.c
+++ b/src/make_packs.c
@@ -33,6 +33,8 @@
 
 #include <glib.h>
 
+#include <getopt.h>
+
 #include <swupd.h>
 
 static void banner(void)
@@ -43,12 +45,47 @@ static void banner(void)
 	printf("\n");
 }
 
-static void usage(void)
+static const struct option prog_opts[] = {
+	{"help", no_argument, 0, 'h'},
+	{"statedir", required_argument, 0, 'S'},
+	{0, 0, 0, 0}
+};
+
+static void usage(const char *name)
 {
 	printf("usage:\n");
-	printf("   swupd_make_pack <start version> <latest version> <bundle>\n");
+	printf("   %s <start version> <latest version> <bundle>\n\n", name);
+	printf("Help options:\n");
+	printf("   -h, --help              Show help options\n");
+	printf("   -S, --statedir          Optional directory to use for state [ default:=%s ]\n", SWUPD_SERVER_STATE_DIR);
 	printf("\n");
-	exit(EXIT_FAILURE);
+}
+
+static bool parse_options(int argc, char **argv)
+{
+	int opt;
+
+	while ((opt = getopt_long(argc, argv, "hS:", prog_opts, NULL)) != -1) {
+		switch (opt) {
+		case '?':
+		case 'h':
+			usage(argv[0]);
+			return false;
+		case 'S':
+			if (!optarg || !set_state_dir(optarg)) {
+				printf("Invalid --statedir argument ''%s'\n\n", optarg);
+				return false;
+			}
+			break;
+		}
+	}
+
+	/* FIXME: *_state_globals() are ugly hacks */
+	if (!init_state_globals()) {
+		return false;
+	}
+
+	return true;
 }
 
 int main(int argc, char **argv)
@@ -59,11 +96,17 @@ int main(int argc, char **argv)
 	char *module;
 	struct packdata *pack;
 	int exit_status = EXIT_FAILURE;
+	char *file_path = NULL;
 
+	if (!parse_options(argc, argv)) {
+		free_state_globals();
+		return EXIT_FAILURE;
+	}
 	banner();
 
-	if (argc != 4) {
-		usage();
+	if (argc - optind != 3) {
+		usage(argv[0]);
+		exit(EXIT_FAILURE);
 	}
 
 	/* FIXME: should use "end_version" not "0" and a unique filename
@@ -76,12 +119,13 @@ int main(int argc, char **argv)
 		return exit_status;
 	}
 
-	read_configuration_file(SWUPD_SERVER_STATE_DIR "/server.ini");
-
+	string_or_die(&file_path, "%s/server.ini", state_dir);
+	read_configuration_file(file_path);
+	free(file_path);
 
-	start_version = strtoull(argv[1], NULL, 10);
-	end_version = strtoull(argv[2], NULL, 10);
-	module = argv[3];
+	start_version = strtoull(argv[optind++], NULL, 10);
+	end_version = strtoull(argv[optind++], NULL, 10);
+	module = argv[optind++];
 
 	if ((start_version < 0) ||
 	    (end_version == 0) ||
@@ -108,5 +152,7 @@ int main(int argc, char **argv)
 	printf("Pack creation %s (pack-%s %i to %li)\n",
 		exit_status == EXIT_SUCCESS ? "complete" : "failed",
 		module, start_version, end_version);
+
+	free_state_globals();
 	return exit_status;
 }
diff --git a/src/pack.c b/src/pack.c
index f021af9..5bb99b8 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -46,21 +46,21 @@ static void empty_pack_stage(int full, int version, char *module)
 	int ret;
 
 	// clean any stale data (eg: re-run after a failure)
-	string_or_die(&cmd, "rm -rf " PACKSTAGE_DIR "/%s/%i/", module, version);
+	string_or_die(&cmd, "rm -rf %s/%s/%i/", packstage_dir, module, version);
 	ret = system(cmd);
 	if (ret) {
-		fprintf(stderr, "Failed to clean " PACKSTAGE_DIR "/%s/%i\n",
-			module, version);
+		fprintf(stderr, "Failed to clean %s/%s/%i\n",
+			packstage_dir, module, version);
 		exit(EXIT_FAILURE);
 	}
 	free(cmd);
 
 	if (!full) {
 		// (re)create module/version/{delta,staged}
-		string_or_die(&path, PACKSTAGE_DIR "/%s/%i/delta", module, version);
+		string_or_die(&path, "%s/%s/%i/delta", packstage_dir, module, version);
 		g_mkdir_with_parents(path, S_IRWXU | S_IRWXG);
 		free(path);
-		string_or_die(&path, PACKSTAGE_DIR "/%s/%i/staged", module, version);
+		string_or_die(&path, "%s/%s/%i/staged", packstage_dir, module, version);
 		g_mkdir_with_parents(path, S_IRWXU | S_IRWXG);
 		free(path);
 	}
@@ -76,7 +76,7 @@ static void explode_pack_stage(int version, char *module)
 	struct stat buf;
 	char *path;
 
-	string_or_die(&path, PACKSTAGE_DIR "/%s/%i/staged", module, version);
+	string_or_die(&path, "%s/%s/%i/staged", packstage_dir, module, version);
 	g_mkdir_with_parents(path, S_IRWXU | S_IRWXG);
 	dir = opendir(path);
 	if (!dir) {
@@ -99,7 +99,8 @@ static void explode_pack_stage(int version, char *module)
 			continue;
 		}
 
-		string_or_die(&path, PACKSTAGE_DIR "/%s/%i/staged/%s", module, version, entry->d_name);
+		string_or_die(&path, "%s/%s/%i/staged/%s",
+		              packstage_dir, module, version, entry->d_name);
 		ret = stat(path, &buf);
 		if (ret) {
 			free(path);
@@ -112,8 +113,8 @@ 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=" PACKSTAGE_DIR "/%s/%i/staged --warning=no-timestamp "
-				TAR_PERM_ATTR_ARGS " -axf %s", module, version, path);
+		string_or_die(&tar, "tar --directory=%s/%s/%i/staged --warning=no-timestamp "
+				TAR_PERM_ATTR_ARGS " -axf %s", packstage_dir, module, version, path);
 		ret = system(tar);
 		if (!ret) {
 			unlink(path);
@@ -162,8 +163,8 @@ static void make_pack_full_files(struct packdata *pack)
 		if ((!file->peer || file->peer->is_deleted) && !file->is_deleted && !file->rename_peer) {
 			char *from, *to;
 			/* hardlink each file that is in <end> but not in <X> */
-			string_or_die(&from, STAGING_DIR "/%i/files/%s.tar", file->last_change, file->hash);
-			string_or_die(&to, PACKSTAGE_DIR "/%s/%i/staged/%s.tar", pack->module, pack->from, 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) {
@@ -228,8 +229,8 @@ static GList *consolidate_packs_delta_files(GList *files, struct packdata *pack)
 			continue;
 		}
 
-		string_or_die(&from, STAGING_DIR "/%i/delta/%i-%i-%s", file->last_change,
-				file->peer->last_change, file->last_change, file->hash);
+		string_or_die(&from, "%s/%i/delta/%i-%i-%s", staging_dir, file->last_change,
+		              file->peer->last_change, file->last_change, file->hash);
 
 		ret = stat(from, &stat_delta);
 		if (ret && !find_file_in_list(files, file)) {
@@ -284,8 +285,8 @@ static int write_pack_signature(struct packdata *pack)
 	char *filename = NULL;
 	int ret = -1;
 
-	string_or_die(&filename, STAGING_DIR "/%i/pack-%s-from-%i.tar",
-			pack->to, pack->module, pack->from);
+	string_or_die(&filename, "%s/%i/pack-%s-from-%i.tar",
+			staging_dir, pack->to, pack->module, pack->from);
 	if (!signature_sign(filename)) {
 		fprintf(stderr, "Creating signature for '%s' failed\n", filename);
 		goto exit;
@@ -324,12 +325,14 @@ 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, STAGING_DIR "/%i/delta/%i-%i-%s", file->last_change,
-				file->peer->last_change, file->last_change, file->hash);
-		string_or_die(&to, PACKSTAGE_DIR "/%s/%i/delta/%i-%i-%s", pack->module, pack->from,
+		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(&tarfrom, STAGING_DIR "/%i/files/%s.tar", file->last_change, file->hash);
-		string_or_die(&tarto, PACKSTAGE_DIR "/%s/%i/staged/%s.tar", pack->module, pack->from, 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);
+		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);
 
 		ret = stat(from, &stat_delta);
 		if (ret) {
@@ -388,8 +391,8 @@ static int make_final_pack(struct packdata *pack)
 		char *from, *to;
 		struct stat st;
 
-		string_or_die(&from, STAGING_DIR "/%i/Manifest-%s-delta-from-%i",
-				pack->to, pack->module, pack->from);
+		string_or_die(&from, "%s/%i/Manifest-%s-delta-from-%i",
+				staging_dir, pack->to, pack->module, pack->from);
 
 		ret = stat(from, &st);
 		if (ret) {
@@ -398,8 +401,8 @@ static int make_final_pack(struct packdata *pack)
 		}
 
 
-		string_or_die(&to, PACKSTAGE_DIR "/%s/%i/Manifest-%s-delta-from-%i",
-				pack->module, pack->from, pack->module, pack->from);
+		string_or_die(&to, "%s/%s/%i/Manifest-%s-delta-from-%i",
+				packstage_dir, pack->module, pack->from, pack->module, pack->from);
 
 		ret = link(from, to);
 		if (ret) {
@@ -416,16 +419,16 @@ static int make_final_pack(struct packdata *pack)
 		char *from, *to;
 		struct stat st;
 
-		string_or_die(&from, STAGING_DIR "/%i/Manifest-%s-delta-from-%i",
-				pack->to, "MoM", pack->from);
+		string_or_die(&from, "%s/%i/Manifest-%s-delta-from-%i",
+				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, PACKSTAGE_DIR "/%s/%i/Manifest-%s-delta-from-%i",
-				pack->module, pack->from, "MoM", pack->from);
+		string_or_die(&to, "%s/%s/%i/Manifest-%s-delta-from-%i",
+				packstage_dir, pack->module, pack->from, "MoM", pack->from);
 
 		ret = link(from, to);
 		if (ret) {
@@ -439,9 +442,9 @@ static int make_final_pack(struct packdata *pack)
 
 	/* tar the staging directory up */
 	LOG(NULL, "starting tar for pack", "%s: %i to %i", pack->module, pack->from, pack->to);
-	string_or_die(&tar, "tar " TAR_PERM_ATTR_ARGS " --directory=" PACKSTAGE_DIR "/%s/%i/ "
-			"--numeric-owner -Jcf " STAGING_DIR "/%i/pack-%s-from-%i.tar delta staged",
-			pack->module, pack->from, pack->to, pack->module, pack->from);
+	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);
 	ret = system(tar);
 	free(tar);
 	LOG(NULL, "finished tar for pack", "%s: %i to %i", pack->module, pack->from, pack->to);
diff --git a/src/rename.c b/src/rename.c
index 70f9006..5ea979c 100644
--- a/src/rename.c
+++ b/src/rename.c
@@ -153,7 +153,7 @@ static void precompute_file_data(struct manifest *manifest, struct file *file, i
 	}
 
 	if (manifest)  {
-		string_or_die(&filename, "%s/%i/%s/%s", IMAGE_DIR, manifest->version, manifest->component, file->filename);
+		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);
 		while (item) {
@@ -161,13 +161,13 @@ static void precompute_file_data(struct manifest *manifest, struct file *file, i
 			item = g_list_next(item);
 
 			free(filename);
-			string_or_die(&filename, "%s/%i/full/%s", IMAGE_DIR, last_change, file->filename);
+			string_or_die(&filename, "%s/%i/full/%s", image_dir, last_change, file->filename);
 			if (!lstat(filename, &buf)) {
 				break;
 			}
 		}
 	} else {
-		string_or_die(&filename, "%s/%i/full/%s", IMAGE_DIR, file->last_change, file->filename);
+		string_or_die(&filename, "%s/%i/full/%s", image_dir, file->last_change, file->filename);
 	}
 
 	/* make sure file->stat.st_size is valid */
diff --git a/src/versions.c b/src/versions.c
index eb38acc..3dd1e63 100644
--- a/src/versions.c
+++ b/src/versions.c
@@ -213,10 +213,10 @@ GList *get_last_versions_list(int next_version, int max_versions)
 	int idx, build_num, build_type, jump_point;
 	int jump_point_found;
 
-	dir = opendir(STAGING_DIR);
+	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;
 	}
 
@@ -226,7 +226,7 @@ GList *get_last_versions_list(int next_version, int max_versions)
 		}
 
 		free(filename);
-		string_or_die(&filename, STAGING_DIR "/%s", entry.d_name);
+		string_or_die(&filename, "%s/%s", staging_dir, entry.d_name);
 
 		if (lstat(filename, &stat)) {
 			LOG(NULL, "lstat failed", "path= %s, strerror= %s",
-- 
2.5.0