Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/cs/vcs_src/vcs_replica.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "vcs_rscs.h"
21
#include "vcs_replica.h"
22
#include <dirent.h>
23
#include <tm.h>
24
25
char* getrdir(rp, buf, bufsize)
26
register char* rp;
27
char* buf;
28
int bufsize;
29
{
30
register char* s;
31
32
strcpy(buf, rp);
33
if (!(s = pathcanon(buf, bufsize, PATH_PHYSICAL|PATH_EXISTS)))
34
return 0;
35
*s++ = '/';
36
strcpy(s, REPL_DIR);
37
return buf;
38
}
39
40
int replica_creat(path, sf)
41
char* path;
42
Sfio_t* sf;
43
{
44
register char* rf;
45
register char* rd;
46
char dirbuf[1024];
47
register DIR* dir;
48
register struct dirent* rca;
49
register char* s;
50
register char* e;
51
Sfio_t* fd;
52
int cnt = 0;
53
struct stat st;
54
55
if (((rd = getrdir(path, dirbuf, sizeof(dirbuf))) == NULL) || (dir = opendir(rd)) == NULL)
56
return (-1);
57
58
e = rd + sizeof(dirbuf);
59
for(s = rd; *s; s++);
60
61
if ((rf = strrchr(path, '/')))
62
rf++;
63
else
64
rf = path;
65
66
67
while((rca = readdir(dir)))
68
{
69
/*
70
* skip all entries staring with ``.''
71
*/
72
73
if (rca->d_name[0] == '.')
74
continue;
75
76
/*
77
* skip regular file
78
*/
79
sfsprintf(s, e - s, "/%s", rca->d_name);
80
if (stat(dirbuf, &st) || !S_ISDIR(st.st_mode))
81
continue;
82
83
sfsprintf(s, e - s, "/%s/%s", rca->d_name, rf);
84
if ((fd = sfopen(NULL, dirbuf, "w")))
85
{
86
sfseek(sf, 0L, 0);
87
sfmove(sf, fd, -1, -1);
88
sfclose(fd);
89
cnt++;
90
}
91
}
92
if (cnt)
93
{
94
/* send message to the server */
95
96
97
}
98
99
return (cnt);
100
101
}
102
103
int replica(path, df, tp)
104
char* path;
105
Sfio_t* df;
106
tag_t* tp;
107
{
108
register char* rf;
109
register char* rd;
110
char dirbuf[1024];
111
register DIR* dir;
112
register struct dirent* rca;
113
register char* s;
114
register char* e;
115
Sfio_t* fd;
116
int cnt = 0;
117
struct stat st;
118
119
120
if (((rd = getrdir(path, dirbuf, sizeof(dirbuf))) == NULL) || (dir = opendir(rd)) == NULL)
121
return (-1);
122
123
e = rd + sizeof(dirbuf) - 1;
124
for(s = rd; *s; s++);
125
126
if ((rf = strrchr(path, '/')))
127
rf++;
128
else
129
rf = path;
130
131
132
while((rca = readdir(dir)))
133
{
134
/*
135
* skip all entries staring with ``.''
136
*/
137
138
if (rca->d_name[0] == '.')
139
continue;
140
141
/*
142
* skip regular file
143
*/
144
sfsprintf(s, e - s, "/%s", rca->d_name);
145
if (stat(dirbuf, &st) || !S_ISDIR(st.st_mode))
146
continue;
147
sfsprintf(s, e - s, "/%s/%s.%d", rca->d_name, rf, cs.time);
148
if ((fd = sfopen(NULL, dirbuf, "a")))
149
{
150
sfwrite(fd,(char *)tp,tp->length);
151
if (df)
152
{
153
sfseek(df, 0L, 0);
154
sfmove(df,fd,-1,-1);
155
}
156
sfclose(fd);
157
cnt++;
158
}
159
}
160
if (cnt)
161
{
162
/* send message to the server */
163
164
165
}
166
167
return (cnt);
168
169
}
170
171