/* Global variables */
+static STORES *me;
static DEVICE *dev = NULL;
static B_DB *db;
static JCR *bjcr; /* jcr for bscan */
static char *db_name = "bacula";
static char *db_user = "bacula";
static char *db_password = "";
-static char *wd = "/tmp";
+static char *wd = NULL;
static int verbose = 0;
static int update_db = 0;
static int update_vol_info = 0;
char *configfile;
+
static void usage()
{
fprintf(stderr, _(
" -r list records\n"
" -s synchronize or store in database\n"
" -v verbose\n"
-" -w dir specify working directory (default /tmp)\n"
+" -w dir specify working directory (default from conf file)\n"
" -? print this message\n\n"));
exit(1);
}
int main (int argc, char *argv[])
{
int ch;
+ struct stat stat_buf;
my_name_is(argc, argv, "bscan");
init_msg(NULL, NULL);
usage();
}
- working_directory = wd;
-
if (configfile == NULL) {
configfile = bstrdup(CONFIG_FILE);
}
parse_config(configfile);
+ LockRes();
+ me = (STORES *)GetNextRes(R_STORAGE, NULL);
+ if (!me) {
+ UnlockRes();
+ Emsg1(M_ERROR_TERM, 0, _("No Storage resource defined in %s. Cannot continue.\n"),
+ configfile);
+ }
+ UnlockRes();
+ /* Check if -w option given, otherwise use resource for working directory */
+ if (wd) {
+ working_directory = wd;
+ } else if (!me->working_directory) {
+ Emsg1(M_ERROR_TERM, 0, _("No Working Directory defined in %s. Cannot continue.\n"),
+ configfile);
+ } else {
+ working_directory = me->working_directory;
+ }
+
+ /* Check that working directory is good */
+ if (stat(working_directory, &stat_buf) != 0) {
+ Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s not found. Cannot continue.\n"),
+ working_directory);
+ }
+ if (!S_ISDIR(stat_buf.st_mode)) {
+ Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s is not a directory. Cannot continue.\n"),
+ working_directory);
+ }
bjcr = setup_jcr("bscan", argv[0], bsr);
dev = setup_to_access_device(bjcr, 1); /* read device */