コード例 #1
0
ファイル: init.cpp プロジェクト: PedroLopes/taskd
void command_init (Database& db, const std::vector <std::string>& args)
{
  // Verify that root exists.
  std::string root = db._config->get ("root");
  if (root == "")
    throw std::string ("ERROR: The '--data' option is required.");

  Directory root_dir (root);
  if (!root_dir.exists ())
    throw std::string ("ERROR: The '--data' path does not exist.");

  if (!root_dir.is_directory ())
     throw std::string ("ERROR: The '--data' path is not a directory.");

  if (!root_dir.readable ())
    throw std::string ("ERROR: The '--data' directory is not readable.");

  if (!root_dir.writable ())
    throw std::string ("ERROR: The '--data' directory is not writable.");

  if (!root_dir.executable ())
    throw std::string ("ERROR: The '--data' directory is not executable.");

  // Provide some defaults and overrides.
  db._config->set ("extensions", TASKD_EXTDIR);
  db._config->setIfBlank ("log",           "/tmp/taskd.log");
  db._config->setIfBlank ("queue.size",    "10");
  db._config->setIfBlank ("pid.file",      "/tmp/taskd.pid");
  db._config->setIfBlank ("ip.log",        "on");
  db._config->setIfBlank ("request.limit", "1048576");
  db._config->setIfBlank ("confirmation",  "1");
  db._config->setIfBlank ("verbose",       "1");

  // Suggestions for missing items.
  if (db._config->get ("server") == "")
    std::cout << "You must specify the 'server' variable, for example:\n"
              << "  taskd config server localhost:53589\n"
              << "\n";

  // Create the data structure.
  Directory sub (root_dir);
  sub.cd ();
  sub += "orgs";
  if (!sub.exists ())
    if (!sub.create (0700))
      throw std::string ("ERROR: Could not create '") + sub._data + "'.";

  // Dump the config file?
  db._config->_original_file = root_dir._data + "/config";

  if (! db._config->_original_file.exists ())
    db._config->_original_file.create (0600);

  if (db._config->dirty ())
  {
    db._config->save ();
    if (db._config->getBoolean ("verbose"))
      std::cout << "Created " << std::string (db._config->_original_file) << "\n";
  }
}
コード例 #2
0
ファイル: init.cpp プロジェクト: goldenHairDafo/taskd
void command_init (Database& db, const std::vector <std::string>& args)
{
  // Verify that root exists.
  std::string root = db._config->get ("root");
  if (root == "")
    throw std::string (STRING_INIT_DATA_REQUIRED);

  Directory root_dir (root);
  if (!root_dir.exists ())
    throw std::string (STRING_INIT_PATH_MISSING);

  if (!root_dir.is_directory ())
    throw std::string (STRING_INIT_PATH_NOT_DIR);

  if (!root_dir.readable ())
    throw std::string (STRING_INIT_PATH_NOT_READ);

  if (!root_dir.writable ())
    throw std::string (STRING_INIT_PATH_NOT_WRITE);

  if (!root_dir.executable ())
    throw std::string (STRING_INIT_PATH_NOT_EXE);

  // Provide some defaults and overrides.
  db._config->set ("extensions", TASKD_EXTDIR);
  db._config->setIfBlank ("log",           "/tmp/taskd.log");
  db._config->setIfBlank ("queue.size",    "10");
  db._config->setIfBlank ("pid.file",      "/tmp/taskd.pid");
  db._config->setIfBlank ("ip.log",        "on");
  db._config->setIfBlank ("request.limit", "1048576");
  db._config->setIfBlank ("confirmation",  "1");
  db._config->setIfBlank ("verbose",       "1");
  db._config->setIfBlank ("trust",         "strict");

  // Suggestions for missing items.
  if (db._config->get ("server") == "")
    std::cout << STRING_INIT_SERVER
              << "\n"
              << "  taskd config server localhost:53589\n"
              << "\n";

  // Create the data structure.
  Directory sub (root_dir);
  sub.cd ();
  sub += "orgs";
  if (!sub.exists ())
    if (!sub.create (0700))
      throw format (STRING_INIT_COULD_NOT_CREATE, sub._data);

  // Dump the config file?
  db._config->_original_file = root_dir._data + "/config";

  if (! db._config->_original_file.exists ())
    db._config->_original_file.create (0600);

  if (db._config->dirty ())
  {
    db._config->save ();
    if (db._config->getBoolean ("verbose"))
      std::cout << format (STRING_INIT_CREATED, db._config->_original_file)
                << "\n";
  }
}