dav/scfg.c

changeset 226
acc997e0d0f9
parent 225
a297c2e28fa1
child 232
df3fa8637a58
equal deleted inserted replaced
225:a297c2e28fa1 226:acc997e0d0f9
192 return -1; 192 return -1;
193 } 193 }
194 194
195 SyncDirectory *dir = malloc(sizeof(SyncDirectory)); 195 SyncDirectory *dir = malloc(sizeof(SyncDirectory));
196 dir->name = strdup(name); 196 dir->name = strdup(name);
197 dir->path = strdup(path); 197 dir->path = scfg_create_path(path);
198 dir->collection = collection ? strdup(collection) : NULL; 198 dir->collection = collection ? strdup(collection) : NULL;
199 dir->repository = strdup(repository); 199 dir->repository = strdup(repository);
200 dir->database = strdup(database); 200 dir->database = strdup(database);
201 dir->max_retry = max_retry; 201 dir->max_retry = max_retry;
202 dir->backuppull = backuppull; 202 dir->backuppull = backuppull;
216 regcomp(matchnothing, "///", REG_NOSUB); 216 regcomp(matchnothing, "///", REG_NOSUB);
217 dir->exclude = ucx_list_append(NULL, matchnothing); 217 dir->exclude = ucx_list_append(NULL, matchnothing);
218 } 218 }
219 219
220 if (trash && sstrtrim(sstr(trash)).length > 0) { 220 if (trash && sstrtrim(sstr(trash)).length > 0) {
221 if (trash[0] == '/') { 221 if (trash[0] == '/' || trash[0] == '$') {
222 dir->trash = strdup(trash); 222 dir->trash = scfg_create_path(trash);
223 } else { 223 } else {
224 char *t = util_concat_path(path, trash); 224 char *t = util_concat_path(dir->path, trash);
225 dir->trash = util_concat_path(t, "/");
226 free(t);
227 }
228
229 if(dir->trash[strlen(dir->trash)-1] != '/') {
230 char *t = dir->trash;
225 dir->trash = util_concat_path(t, "/"); 231 dir->trash = util_concat_path(t, "/");
226 free(t); 232 free(t);
227 } 233 }
228 234
229 // create trash directory 235 // create trash directory
242 return 0; 248 return 0;
243 } 249 }
244 250
245 SyncDirectory* scfg_get_dir(char *name) { 251 SyncDirectory* scfg_get_dir(char *name) {
246 return ucx_map_cstr_get(directories, name); 252 return ucx_map_cstr_get(directories, name);
253 }
254
255 char* scfg_create_path(char *cfg) {
256 if(!cfg) {
257 return NULL;
258 }
259 if(cfg[0] != '$') {
260 return strdup(cfg);
261 }
262
263 sstr_t s = sstr(cfg);
264 sstr_t path = sstrchr(sstr(cfg), '/');
265 char *localpath = NULL;
266 if(path.length > 0) {
267 // path = $var/path/
268
269 sstr_t var = sstrsubsl(s, 1, path.ptr - s.ptr - 1);
270 if(var.length > 0) {
271 char *env = sstrdup(var).ptr;
272 char *envval = getenv(env);
273 free(env);
274 if(envval) {
275 localpath = util_concat_path(envval, path.ptr);
276 } else {
277 fprintf(
278 stderr,
279 "Environment variable %.*s not set.\nAbort.\n",
280 (int)var.length,
281 var.ptr);
282 exit(-1);
283 }
284 } else {
285 localpath = sstrdup(path).ptr;
286 }
287 } else {
288 // path = $var
289 char *envval = getenv(cfg + 1);
290 if(envval) {
291 localpath = strdup(envval);
292 } else {
293 fprintf(
294 stderr,
295 "Environment variable %s not set.\nAbort.\n",
296 cfg);
297 exit(-1);
298 }
299 }
300 return localpath;
247 } 301 }
248 302
249 303
250 int add_directory(SyncDirectory *dir) { 304 int add_directory(SyncDirectory *dir) {
251 char *file = util_concat_path(ENV_HOME, ".dav/sync.xml"); 305 char *file = util_concat_path(ENV_HOME, ".dav/sync.xml");

mercurial