... | ... |
@@ -1156,9 +1156,9 @@ fc_error_t select_from_official_databases( |
1156 | 1156 |
continue; |
1157 | 1157 |
} |
1158 | 1158 |
|
1159 |
- logg("*Selecting optional database: %s\n", optionalDatabases[i]); |
|
1160 |
- if (FC_SUCCESS != (ret = string_list_add(optionalDatabases[i], &selectedDatabases, &nSelectedDatabases))) { |
|
1161 |
- logg("!Failed to add optional database %s to list of selected databases.\n", optionalDatabases[i]); |
|
1159 |
+ logg("*Selecting optional database: %s\n", optInList[i]); |
|
1160 |
+ if (FC_SUCCESS != (ret = string_list_add(optInList[i], &selectedDatabases, &nSelectedDatabases))) { |
|
1161 |
+ logg("!Failed to add optional database %s to list of selected databases.\n", optInList[i]); |
|
1162 | 1162 |
status = ret; |
1163 | 1163 |
goto done; |
1164 | 1164 |
} |
... | ... |
@@ -307,9 +307,26 @@ fc_error_t fc_prune_database_directory(char **databaseList, uint32_t nDatabases) |
307 | 307 |
|
308 | 308 |
DIR *dir = NULL; |
309 | 309 |
struct dirent *dent; |
310 |
- char fname[PATH_MAX]; |
|
311 | 310 |
char *extension = NULL; |
312 | 311 |
|
312 |
+ char currDir[PATH_MAX]; |
|
313 |
+ |
|
314 |
+ /* Store CWD */ |
|
315 |
+ if (!getcwd(currDir, PATH_MAX)) { |
|
316 |
+ logg("!getcwd() failed\n"); |
|
317 |
+ status = FC_EDIRECTORY; |
|
318 |
+ goto done; |
|
319 |
+ } |
|
320 |
+ |
|
321 |
+ /* Change directory to database directory */ |
|
322 |
+ if (chdir(g_databaseDirectory)) { |
|
323 |
+ logg("!Can't change dir to %s\n", g_databaseDirectory); |
|
324 |
+ status = FC_EDIRECTORY; |
|
325 |
+ goto done; |
|
326 |
+ } |
|
327 |
+ |
|
328 |
+ logg("*Current working dir is %s\n", g_databaseDirectory); |
|
329 |
+ |
|
313 | 330 |
if (!(dir = opendir(g_databaseDirectory))) { |
314 | 331 |
logg("!checkdbdir: Can't open directory %s\n", g_databaseDirectory); |
315 | 332 |
status = FC_EDBDIRACCESS; |
... | ... |
@@ -331,7 +348,7 @@ fc_error_t fc_prune_database_directory(char **databaseList, uint32_t nDatabases) |
331 | 331 |
if (!bFound) { |
332 | 332 |
/* Prune CVD/CLD */ |
333 | 333 |
mprintf("Pruning unwanted or deprecated database file %s.\n", dent->d_name); |
334 |
- if (unlink(fname)) { |
|
334 |
+ if (unlink(dent->d_name)) { |
|
335 | 335 |
mprintf("!Failed to prune unwanted database file %s, consider removing it manually.\n", dent->d_name); |
336 | 336 |
status = FC_EDBDIRACCESS; |
337 | 337 |
goto done; |
... | ... |
@@ -347,6 +364,17 @@ done: |
347 | 347 |
if (NULL != dir) { |
348 | 348 |
closedir(dir); |
349 | 349 |
} |
350 |
+ |
|
351 |
+ if (currDir[0] != '\0') { |
|
352 |
+ /* Restore CWD */ |
|
353 |
+ if (chdir(currDir)) { |
|
354 |
+ logg("!Failed to change back to original directory %s\n", currDir); |
|
355 |
+ status = FC_EDIRECTORY; |
|
356 |
+ goto done; |
|
357 |
+ } |
|
358 |
+ logg("*Current working dir restored to %s\n", currDir); |
|
359 |
+ } |
|
360 |
+ |
|
350 | 361 |
return status; |
351 | 362 |
} |
352 | 363 |
|