Skip to content

Commit d3a6f79

Browse files
committed
refactoring: new error for failing to read repo; not using global variables in unzipping functions
1 parent 5d78cbe commit d3a6f79

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

errors.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ void fail(int error){
3333
case (ERR_FULL_ONLY):
3434
printf("Disk-only filesystem cannot be used, probably because of chosen layout;\n");
3535
break;
36+
case (ERR_REPO_READ):
37+
printf("Failed to read repository;\n");
38+
break;
3639
default:
3740
printf("Unknown error\n");
3841
break;

errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define ERR_RDIFF 7
1212

1313
#define ERR_FULL_ONLY 9
14+
#define ERR_REPO_READ 10
1415

1516
void fail(int);
1617

initialize.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ void initialize(){
125125
layout_setup();
126126
fuse_operations_setup();
127127

128-
if (repo_count == 1)
129-
init(repos[0]);
128+
if (repo_count == 1){
129+
if (init(repos[0]) == -1)
130+
fail(ERR_REPO_READ);
131+
}
130132
else if (repo_count > 1)
131133
init_multi(repo_count, repos);
132134
else

layout/versions.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ int versions_init(char *repo){
3333
// printf("[Function: init_versions] Received repo path %s;\n", path);
3434
gtreenew(&version_tree);
3535
rev_count = single(int);
36-
rev_count[0] = gather_revisions(repo, &revs);
36+
if ((rev_count[0] = gather_revisions(repo, &revs)) <= 0)
37+
versions_init_finish(-1);
3738
read_layout_versions(revs[rev_count[0] - 1], NULL);
3839
for (i = rev_count[0] - 1; i >= 0; i--){
3940
extension = gpthext(revs[i]);
@@ -139,7 +140,7 @@ int read_layout_versions(char *revision, char *prefix){
139140
char *path = NULL;
140141
FILE *file = NULL;
141142
struct stats stats;
142-
143+
143144
if (gmstrcpy(&path, data_dir, "/", revision, 0) != 0)
144145
read_layout_versions_finish(-1);
145146
if ((file = fopen(path, "r")) == NULL)

structure/necessary.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static struct stats root;
2424

2525
static struct node * get_revision_tree(char *repo, char *revision);
2626

27-
static void free_revision_tree(char *repo, char *revision);
27+
// static void free_revision_tree(char *repo, char *revision);
2828

2929
static int build_revision_tree(revision_t *, int, int);
3030

@@ -172,7 +172,7 @@ tree_t get_revision_tree(char *repo, char *rev){
172172
return revisions[j].tree;
173173
}
174174

175-
void free_revision_tree(char *repo, char *rev){
175+
/*void free_revision_tree(char *repo, char *rev){
176176
177177
revision_t *revisions = NULL;
178178
int count = 0;
@@ -201,7 +201,7 @@ void free_revision_tree(char *repo, char *rev){
201201
return;
202202
gtreedel(revisions[j].tree, "/");
203203
free(revisions[j].tree);
204-
};
204+
};*/
205205

206206
int build_revision_tree(revision_t *revisions, int count, int rev_index){
207207

support/grdiff.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
// prototypes:
44

5-
int unzip(char *path);
5+
/*
6+
* unzip target file to target directory
7+
*
8+
* @1: file to be unzipped
9+
* @2: directory where unzipped file should be stored
10+
*
11+
* returns: 0 on sucesss, -1 otherwise
12+
*/
13+
int unzip(char *, char *);
614

715
// public:
816

@@ -22,9 +30,7 @@ int unzip_revs(char *path, char *dest){
2230
char *extension = NULL;
2331
int descriptor = 0;
2432

25-
#ifdef DEBUG_DEEP
26-
printf("[Function: unzip_revs] Unzipping revisions in %s directory;\n", path);
27-
#endif
33+
// printf("[Function: unzip_revs] Unzipping revisions in %s directory;\n", path);
2834
if ((dir = opendir(path)) == NULL)
2935
return -1;
3036
for (entry = readdir(dir); entry != NULL; entry = readdir(dir)){
@@ -34,7 +40,7 @@ int unzip_revs(char *path, char *dest){
3440
extension = gpthext(entry->d_name);
3541
if (strcmp(extension, "gz") == 0){
3642
gstrdel(extension);
37-
if (unzip(mirror) == -1)
43+
if (unzip(mirror, dest) == -1)
3844
continue;
3945
}
4046
else{
@@ -50,7 +56,6 @@ int unzip_revs(char *path, char *dest){
5056
};
5157
};
5258
closedir(dir);
53-
5459
return rev_count;
5560

5661
};
@@ -312,7 +317,7 @@ int snapshot_append(char *file){
312317

313318
// private:
314319

315-
int unzip(char *path){
320+
int unzip(char *path, char *dest){
316321

317322
#define unzip_error { \
318323
gstrdel(temp); \
@@ -333,13 +338,11 @@ int unzip(char *path){
333338
FILE *file = NULL;
334339
gzFile archive = NULL;
335340

336-
if (gstrcpy(&temp, path) == -1)
337-
unzip_error;
338-
if (gpthcld(&temp, temp) == -1)
341+
if (gpthcld(&temp, path) == -1)
339342
unzip_error;
340343
if (gpthugz(&temp) == -1)
341344
unzip_error;
342-
if (gmstrcpy(&target, data_dir, "/", temp, 0) == -1)
345+
if (gmstrcpy(&target, dest, "/", temp, 0) == -1)
343346
unzip_error;
344347

345348
if ((file = fopen(target, "w")) == NULL)

0 commit comments

Comments
 (0)