Skip to content

Commit 1bc4040

Browse files
committed
refactoring: better functions for copying and appending snapshots
1 parent 2b65a40 commit 1bc4040

File tree

7 files changed

+41
-27
lines changed

7 files changed

+41
-27
lines changed

externs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <fuse.h>
2-
#include "support/gstring.h"
32

43
extern int repo_count;
54
extern int *rev_count;

headers.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#define POLICY_SIMPLE 1
4646
#define POLICY_LIMIT 2
4747

48-
#define CURRENT_SNAPSHOT "mirror_metadata.current.snapshot"
49-
5048
#define ARCHFS_DIR_FORMAT "%4d-%02d-%02dT%02d:%02d:%02d"
5149
#define ARCHFS_DIR_FORMAT_LENGTH "XXXX-XX-XXTXX:XX:XX"
5250

layout/versions.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ void read_revision_versions(char *rev, int rev_index, char *, int);
1212

1313
int versions_add_repo_dir(char *, int);
1414

15+
#define CURRENT_SNAPSHOT "mirror_metadata.current.snapshot"
16+
1517
// public:
1618

1719
int versions_init(char *repo){
@@ -39,9 +41,9 @@ int versions_init(char *repo){
3941
for (i = rev_count[0] - 1; i >= 0; i--){
4042
extension = gpthext(revs[i]);
4143
if (strcmp(extension, "snapshot") == 0)
42-
snapshot_copy(revs[i], data_dir);
44+
snapshot_copy(revs[i], CURRENT_SNAPSHOT, data_dir);
4345
else // strcmp(extension, "diff") == 0)
44-
snapshot_append(revs[i], data_dir);
46+
snapshot_append(revs[i], CURRENT_SNAPSHOT, data_dir);
4547
gstrdel(extension);
4648
read_revision_versions(revs[i], rev_count[0] - i - 1, NULL, -1);
4749
};
@@ -88,9 +90,9 @@ int versions_init_multi(int count, char **repos){
8890
for (j = rev_count[i] - 1; j >= 0; j--){
8991
extension = gpthext(revs[j]);
9092
if (strcmp(extension, "snapshot") == 0)
91-
snapshot_copy(revs[j], data_dir);
93+
snapshot_copy(revs[j], CURRENT_SNAPSHOT, data_dir);
9294
else // strcmp(extension, "diff") == 0)
93-
snapshot_append(revs[j], data_dir);
95+
snapshot_append(revs[j], CURRENT_SNAPSHOT, data_dir);
9496
gstrdel(extension);
9597
read_revision_versions(revs[j], rev_count[i] - j - 1, repo_names[i], i);
9698
};

structure/full.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ void read_revision_all(char *, char *, int, int);
1010

1111
int read_stats_all(struct stats *stats, char *prefix, int repo, int rev, FILE *file);
1212

13+
#define CURRENT_SNAPSHOT "mirror_metadata.current.snapshot"
14+
1315
// variables:
1416

1517
tree_t structure_tree = NULL;
@@ -40,9 +42,9 @@ int full_build(char *repo){
4042
for (i = rev_count[0] - 1; i >= 0; i--){
4143
extension = gpthext(revs[i]);
4244
if (strcmp(extension, "snapshot") == 0)
43-
snapshot_copy(revs[i], data_dir);
45+
snapshot_copy(revs[i], CURRENT_SNAPSHOT, data_dir);
4446
else // strcmp(extension, "diff") == 0)
45-
snapshot_append(revs[i], data_dir);
47+
snapshot_append(revs[i], CURRENT_SNAPSHOT, data_dir);
4648
gstrdel(extension);
4749
read_revision_all(NULL, revs[i], -1, rev_count[0] - i - 1);
4850
};
@@ -91,9 +93,9 @@ int full_build_multi(int count, char **repo){
9193
for (j = rev_count[i] - 1; j >= 0; j--){
9294
extension = gpthext(revs[j]);
9395
if (strcmp(extension, "snapshot") == 0)
94-
snapshot_copy(revs[j], data_dir);
96+
snapshot_copy(revs[j], CURRENT_SNAPSHOT, data_dir);
9597
else // strcmp(extension, "diff") == 0)
96-
snapshot_append(revs[j], data_dir);
98+
snapshot_append(revs[j], CURRENT_SNAPSHOT, data_dir);
9799
gstrdel(extension);
98100
read_revision_all(repo_names[i], revs[j], i, rev_count[i] - j - 1);
99101
};

structure/necessary.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,11 @@ int necessary_build_multi(int count, char **repo){
9494
for (i = 0; i < repo_count; i++){
9595
if ((rev_count[i] = gather_revisions(repos[i], data_dir, &revs)) == -1)
9696
necessary_build_multi_finish(-1);
97-
pass(4)
9897
repositories[i].revisions = calloc(rev_count[i], sizeof(revision_t));
9998
for (j = 0; j < rev_count[i]; j++){
100-
pass(5);
10199
repositories[i].revisions[j].name = get_revs_dir(revs[i]);
102-
pass(6);
103100
gstrcpy(&repositories[0].revisions[i].file, revs[i]);
104-
pass(7);
105101
}
106-
pass(8);
107102
}
108103
necessary_build_multi_finish(0);
109104
}
@@ -344,7 +339,7 @@ char * build_snapshot(revision_t *revisions, int count, int rev_index, int snaps
344339
if ((snapshot_desc = mkstemp(temp_snapshot)) == -1)
345340
build_snapshot_error;
346341
gmstrcpy(&snapshot, data_dir, "/", revisions[snapshot_index].file, 0);
347-
printf("%s\n", snapshot);
342+
348343
if ((revision_desc = open(snapshot, O_RDONLY)) == -1)
349344
build_snapshot_error;
350345
if (gdesccopy(revision_desc, snapshot_desc))

support/grdiff.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ int get_revisions(char *where, int count, char **revs){
256256

257257
}
258258

259-
int snapshot_copy(char *revision, char *directory){
259+
int snapshot_copy(char *revision, char *target, char *directory){
260260

261261
char *path = NULL;
262262
char *snapshot = NULL;
@@ -266,7 +266,7 @@ int snapshot_copy(char *revision, char *directory){
266266
size_t result = 0;
267267

268268
gmstrcpy(&path, directory, "/", revision, 0);
269-
gmstrcpy(&snapshot, directory, "/", CURRENT_SNAPSHOT, 0);
269+
gmstrcpy(&snapshot, directory, "/", target, 0);
270270
#ifdef DEBUG_DEEP
271271
printf("[Function: snapshot_copy] Copying from %s to %s\n", path, snapshot);
272272
#endif
@@ -285,23 +285,23 @@ int snapshot_copy(char *revision, char *directory){
285285

286286
};
287287

288-
int snapshot_append(char *file, char *directory){
288+
int snapshot_append(char *revision, char *target, char *directory){
289289

290290
char *snapshot = NULL;
291291
int snapshot_desc = 0;
292-
char *revision = NULL;
292+
char *path = NULL;
293293
int revision_desc = 0;
294294
char buffer[1024];
295295
size_t result = 0;
296296

297-
gmstrcpy(&revision, directory, "/", file, 0);
298-
gmstrcpy(&snapshot, directory, "/", CURRENT_SNAPSHOT, 0);
297+
gmstrcpy(&path, directory, "/", revision, 0);
298+
gmstrcpy(&snapshot, directory, "/", target, 0);
299299
#ifdef DEBUG_DEEP
300-
printf("[Function: snapshot_append] Appending from %s to %s\n", revision, snapshot);
300+
printf("[Function: snapshot_append] Appending from %s to %s\n", path, snapshot);
301301
#endif
302302
if ((snapshot_desc = open(snapshot, O_WRONLY | O_APPEND)) == -1)
303303
return -1;
304-
if ((revision_desc = open(revision, O_RDONLY)) == -1){
304+
if ((revision_desc = open(path, O_RDONLY)) == -1){
305305
close(snapshot_desc);
306306
return -1;
307307
};

support/grdiff.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,27 @@ int read_stats(struct stats *stats, FILE *file);
5858

5959
int get_revisions(char *, int, char **);
6060

61-
int snapshot_copy(char *, char *);
61+
/*
62+
* copy given revision to a certain target in a given directory
63+
*
64+
* @1: revision file name to be copied
65+
* @2: target file name
66+
* @3: directory where both files are stored
67+
*
68+
* returns: 0 on sucess, -1 otherwise
69+
*/
70+
int snapshot_copy(char *, char *, char *);
6271

63-
int snapshot_append(char *file, char *);
72+
/*
73+
* append given revision to a certain target in a given directory
74+
*
75+
* @1: revision file name to be appended
76+
* @2: target file name
77+
* @3: directory where both files are stored
78+
*
79+
* returns: 0 on sucess, -1 otherwise
80+
*/
81+
int snapshot_append(char *, char *, char *);
6482

6583
int update_tree(tree_t, stats_t *);
6684

0 commit comments

Comments
 (0)