Skip to content

Commit 03ca237

Browse files
author
gruszczy
committed
option for revision directories to be created using local time rather than utc
1 parent bf482fa commit 03ca237

File tree

8 files changed

+50
-32
lines changed

8 files changed

+50
-32
lines changed

headers.h

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#define lock(mutex) pthread_mutex_lock(&mutex)
4747
#define unlock(mutex) pthread_mutex_unlock(&mutex)
4848

49+
#define REV_LOCAL_TIME 1
50+
#define REV_GMT_TIME 2
51+
4952
struct file_system_info {
5053
int repo_count;
5154
int *rev_count;
@@ -56,6 +59,8 @@ struct file_system_info {
5659
// TODO: this must be fixed; it doesn't hold actual information about revs,
5760
// but only the most recent revs for multiple repos
5861
char **revs;
62+
63+
int rev_dir_time;
5964
};
6065

6166
#endif

layout/versions.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ struct node *version_tree = NULL;
88

99
int read_layout_versions(char *, char *);
1010

11-
void read_revision_versions(char *rev, int rev_index, char *);
11+
void read_revision_versions(struct file_system_info *, char *rev,
12+
int rev_index, char *);
1213

1314
#define CURRENT_SNAPSHOT "mirror_metadata.current.snapshot"
1415

@@ -26,7 +27,7 @@ int versions_init(struct file_system_info *fsinfo){
2627
read_layout_versions(fsinfo->revs[fsinfo->rev_count[0] - 1], NULL);
2728
for (i = fsinfo->rev_count[0] - 1; i >= 0; i--){
2829
add_snapshot(fsinfo->revs[i], CURRENT_SNAPSHOT, data_dir);
29-
read_revision_versions(fsinfo->revs[i], fsinfo->rev_count[0] - i - 1, NULL);
30+
read_revision_versions(fsinfo, fsinfo->revs[i], fsinfo->rev_count[0] - i - 1, NULL);
3031
};
3132
return 0;
3233

@@ -64,7 +65,7 @@ int versions_init_multi(struct file_system_info *fsinfo){
6465
};
6566
for (j = fsinfo->rev_count[i] - 1; j >= 0; j--){
6667
add_snapshot(fsinfo->revs[j], CURRENT_SNAPSHOT, data_dir);
67-
read_revision_versions(fsinfo->revs[j], fsinfo->rev_count[i] - j - 1, fsinfo->repo_names[i]);
68+
read_revision_versions(fsinfo, fsinfo->revs[j], fsinfo->rev_count[i] - j - 1, fsinfo->repo_names[i]);
6869
};
6970
versions_init_multi_free_revs;
7071
};
@@ -122,7 +123,8 @@ int read_layout_versions(char *revision, char *prefix){
122123

123124
};
124125

125-
void read_revision_versions(char *revision, int rev_index, char *prefix){
126+
void read_revision_versions(struct file_system_info *fsinfo, char *revision,
127+
int rev_index, char *prefix){
126128

127129
#define read_revision_versions_finish { \
128130
gmstrcpy(&path, data_dir, "/", revision, 0); \
@@ -136,7 +138,7 @@ void read_revision_versions(char *revision, int rev_index, char *prefix){
136138
}
137139

138140
char *path = NULL;
139-
char *sufix = get_revs_dir(revision);
141+
char *sufix = get_revs_dir(fsinfo, revision);
140142
char *file_path = NULL;
141143
struct stats stats, *temp;
142144
FILE *file = NULL;

parse.c

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#define OPT_FUSE "-o"
3131

32+
#define OPT_DIR_LOCAL_TIME_FULL "--local-time"
33+
3234
#define isOption(string) ((string[0] == '-') ? 1 : 0)
3335

3436
// private functions
@@ -137,6 +139,8 @@ void parse_option(struct file_system_info *fsinfo, int argc, char **argv, int *i
137139
if (add_fuse_option(argc, argv, index) != 0)
138140
fail(ERR_PARAMETRES);
139141
}
142+
else if (strcmp(argv[*index], OPT_DIR_LOCAL_TIME_FULL) == 0)
143+
fsinfo->rev_dir_time = REV_LOCAL_TIME;
140144
else
141145
fail(ERR_UNKNOWN_OPTION);
142146

rdiff-backup-fs.c

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ int run(int argc, char **argv){
2727
int i = 0, options_count = 0;
2828

2929
file_system_info = single(struct file_system_info);
30+
file_system_info->rev_dir_time = REV_GMT_TIME;
3031

3132
parse(file_system_info, argc, argv);
3233
initialize(file_system_info);

structure/full.c

+12-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
// prototypes:
44

5-
int add_revs_dir(char *, char *);
5+
int add_revs_dir(struct file_system_info *, char *, char *);
66

7-
void read_revision_all(char *, char *, int);
7+
void read_revision_all(struct file_system_info *, char *, char *, int);
88

99
int read_stats_all(struct stats *stats, char *prefix, int rev, FILE *file);
1010

@@ -25,7 +25,7 @@ int full_build(struct file_system_info *fsinfo){
2525
return -1;
2626
for (i = fsinfo->rev_count[0] - 1; i >= 0; i--){
2727
add_snapshot(fsinfo->revs[i], CURRENT_SNAPSHOT, data_dir);
28-
read_revision_all(NULL, fsinfo->revs[i], fsinfo->rev_count[0] - i - 1);
28+
read_revision_all(fsinfo, NULL, fsinfo->revs[i], fsinfo->rev_count[0] - i - 1);
2929
};
3030
gtreenlinks(structure_tree);
3131
return 0;
@@ -60,7 +60,7 @@ int full_build_multi(struct file_system_info *fsinfo){
6060
};
6161
for (j = fsinfo->rev_count[i] - 1; j >= 0; j--){
6262
add_snapshot(fsinfo->revs[j], CURRENT_SNAPSHOT, data_dir);
63-
read_revision_all(fsinfo->repo_names[i], fsinfo->revs[j], fsinfo->rev_count[i] - j - 1);
63+
read_revision_all(fsinfo, fsinfo->repo_names[i], fsinfo->revs[j], fsinfo->rev_count[i] - j - 1);
6464
};
6565
full_build_multi_free_revs;
6666
};
@@ -98,7 +98,8 @@ char** full_get_children(struct file_system_info *fsinfo, char *repo, char *revi
9898

9999
// private:
100100

101-
void read_revision_all(char *repo, char *rev, int rev_index){
101+
void read_revision_all(struct file_system_info *fsinfo, char *repo, char *rev,
102+
int rev_index){
102103

103104
#define read_revision_error { \
104105
gstrdel(file); \
@@ -115,18 +116,18 @@ void read_revision_all(char *repo, char *rev, int rev_index){
115116
struct stats *stats = calloc(1, sizeof(struct stats));
116117

117118
if (repo == NULL){
118-
if (gmstrcpy(&rev_dir, "/", get_revs_dir(rev), 0) != 0)
119+
if (gmstrcpy(&rev_dir, "/", get_revs_dir(fsinfo, rev), 0) != 0)
119120
read_revision_error;
120121
}
121122
else{ // repo != NULL
122-
if (gmstrcpy(&rev_dir, "/", repo, "/", get_revs_dir(rev), 0) != 0)
123+
if (gmstrcpy(&rev_dir, "/", repo, "/", get_revs_dir(fsinfo, rev), 0) != 0)
123124
read_revision_error;
124125
};
125126
if (gmstrcpy(&file_path, data_dir, "/", CURRENT_SNAPSHOT, 0) != 0)
126127
read_revision_error;
127128
if ((file = fopen(file_path, "r")) == NULL)
128129
read_revision_error;
129-
add_revs_dir(rev, repo);
130+
add_revs_dir(fsinfo, rev, repo);
130131

131132
while (read_stats_all(stats, rev_dir, rev_index, file) == 0)
132133
update_tree(structure_tree, stats, stats->path);
@@ -158,21 +159,21 @@ int read_stats_all(struct stats *stats, char *prefix, int rev, FILE *file){
158159

159160
};
160161

161-
int add_revs_dir(char *revision, char *repository){
162+
int add_revs_dir(struct file_system_info *fsinfo, char *revision, char *repository){
162163

163164
struct stats stats;
164165

165166
memset(&stats, 0, sizeof(stats));
166167
if (revision == NULL)
167168
return -1;
168169
if (repository == NULL){
169-
gmstrcpy(&stats.path, "/", get_revs_dir(revision), NULL);
170+
gmstrcpy(&stats.path, "/", get_revs_dir(fsinfo, revision), NULL);
170171
// printf("[Function: add_revs_dir] Adding revision %s to the data structure;\n", stats->path);
171172
// stats->name = stats->path + strlen("/")'
172173
stats.name = stats.path + 1;
173174
}
174175
else{
175-
gmstrcpy(&stats.path, "/", repository, "/", get_revs_dir(revision), NULL);
176+
gmstrcpy(&stats.path, "/", repository, "/", get_revs_dir(fsinfo, revision), NULL);
176177
// stats->name = stats->path + strlen("/") + strlen(repository) + strlen("/");
177178
stats.name = stats.path + 1 + strlen(repository) + 1;
178179
};

structure/necessary.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int necessary_build(struct file_system_info *fsinfo){
9999
pthread_mutex_init(&cache_list.mutex, 0);
100100
repositories[0].revisions = calloc(fsinfo->rev_count[0], sizeof(revision_t));
101101
for (i = 0; i < fsinfo->rev_count[0]; i++) {
102-
repositories[0].revisions[i].name = get_revs_dir(fsinfo->revs[i]);
102+
repositories[0].revisions[i].name = get_revs_dir(fsinfo, fsinfo->revs[i]);
103103
gstrcpy(&repositories[0].revisions[i].file, fsinfo->revs[i]);
104104
pthread_mutex_init(&repositories[0].revisions[i].mutex, 0);
105105
set_directory_stats(&repositories[0].revisions[i].stats);
@@ -127,7 +127,7 @@ int necessary_build_multi(struct file_system_info *fsinfo){
127127
return -1;
128128
repositories[i].revisions = calloc(fsinfo->rev_count[i], sizeof(revision_t));
129129
for (j = 0; j < fsinfo->rev_count[i]; j++){
130-
repositories[i].revisions[j].name = get_revs_dir(fsinfo->revs[j]);
130+
repositories[i].revisions[j].name = get_revs_dir(fsinfo, fsinfo->revs[j]);
131131
set_directory_stats(&repositories[i].revisions[j].stats);
132132
gstrcpy(&repositories[i].revisions[j].file, fsinfo->revs[j]);
133133
}

support/grdiff.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
*/
1717
int unzip(char *, char *);
1818

19+
/*
20+
* returns gmt time of revision creation
21+
*
22+
* @1: filename of revision's mirror_metadata file
23+
*
24+
* returns: gmt time on success, -1 otherwise
25+
*/
26+
static time_t get_revs_date(char *);
27+
1928
// public:
2029

2130
int update_tree(tree_t tree, stats_t *stats, char *path){
@@ -109,7 +118,7 @@ int gather_revisions(struct file_system_info *fsinfo, char *repo_path, char *des
109118
};
110119

111120
// FIXME: what about seasonal time?
112-
time_t get_revs_date(char *mirror){
121+
static time_t get_revs_date(char *mirror){
113122

114123
#define FACTORS_COUNT 8
115124
#define FACTORS_SHORT_COUNT 6
@@ -146,10 +155,16 @@ time_t get_revs_date(char *mirror){
146155

147156
};
148157

149-
char* get_revs_dir(char *mirror){
158+
char* get_revs_dir(struct file_system_info *fsinfo, char *mirror){
150159

151160
time_t rev_date = get_revs_date(mirror);
152-
struct tm *rev_tm = gmtime(&rev_date);
161+
struct tm *rev_tm = 0;
162+
if (fsinfo->rev_dir_time == REV_LOCAL_TIME)
163+
rev_tm = localtime(&rev_date);
164+
else if (fsinfo->rev_dir_time == REV_GMT_TIME)
165+
rev_tm = gmtime(&rev_date);
166+
else
167+
return NULL;
153168
char *result = gstralloc(strlen(ARCHFS_DIR_FORMAT_LENGTH));
154169

155170
sprintf(result, ARCHFS_DIR_FORMAT, rev_tm->tm_year + 1900,

support/grdiff.h

+1-11
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,14 @@ int unzip_revs(char *, char *);
2727
*/
2828
int count_revs(char *);
2929

30-
/*
31-
* returns gmt time of revision creation
32-
*
33-
* @1: filename of revision's mirror_metadata file
34-
*
35-
* returns: gmt time on success, -1 otherwise
36-
*/
37-
38-
time_t get_revs_date(char *);
39-
4030
/*
4131
* returns name of directory for a revision
4232
*
4333
* @1: filename of revision's mirror_metadata file
4434
*
4535
* returns: name of directory on success, NULL otherwise
4636
*/
47-
char* get_revs_dir(char *);
37+
char* get_revs_dir(struct file_system_info *, char *);
4838

4939
/*
5040
* read single portion of file stats from a stream

0 commit comments

Comments
 (0)