Back to index

nordugrid-arc-nox  1.1.0~rc6
arcrm.cpp File Reference
#include <string>
#include <list>
#include <arc/ArcLocation.h>
#include <arc/Logger.h>
#include <arc/StringConv.h>
#include <arc/URL.h>
#include <arc/UserConfig.h>
#include <arc/credential/Credential.h>
#include <arc/data/DataHandle.h>
#include <arc/data/DataMover.h>
#include <arc/OptionParser.h>

Go to the source code of this file.


static Arc::Logger logger (Arc::Logger::getRootLogger(),"arcrm")
bool arcrm (const Arc::URL &file_url, const Arc::UserConfig &usercfg, bool errcont, int timeout)
int main (int argc, char **argv)

Function Documentation

bool arcrm ( const Arc::URL file_url,
const Arc::UserConfig usercfg,
bool  errcont,
int  timeout 

Definition at line 22 of file arcrm.cpp.

  if (!file_url) {
    logger.msg(Arc::ERROR, "Invalid URL: %s", file_url.str());
    return false;
  if (file_url.Protocol() == "filelist") {
    std::list<Arc::URL> files = Arc::ReadURLList(file_url);
    if (files.size() == 0) {
      logger.msg(Arc::ERROR, "Can't read list of locations from file %s",
      return false;
    bool r = true;
    for (std::list<Arc::URL>::iterator file = files.begin();
         file != files.end(); file++) {
      if (!arcrm(*file, usercfg, errcont, timeout))
        r = false;
    return r;

  if (file_url.IsSecureProtocol() && !Arc::Credential::IsCredentialsValid(usercfg)) {
    logger.msg(Arc::ERROR, "Unable to remove file (%s): No valid credentials found", file_url.str());
    return false;

  Arc::DataHandle url(file_url, usercfg);
  if (!url) {
    logger.msg(Arc::ERROR, "Unsupported url given");
    return false;
  // only one try
  Arc::DataMover mover;
  Arc::DataStatus res =  mover.Delete(*url,errcont);
  if (!res.Passed()) {
    logger.msg(Arc::ERROR, "Delete failed: %s", std::string(res));
    if (res.Retryable())
      logger.msg(Arc::ERROR, "This seems like a temporary error, please try again later");
    return false;
  return true;

Here is the call graph for this function:

Here is the caller graph for this function:

static Arc::Logger logger ( Arc::Logger::  getRootLogger(),
) [static]
int main ( int  argc,
char **  argv 

Definition at line 69 of file arcrm.cpp.


  setlocale(LC_ALL, "");

  Arc::LogStream logcerr(std::cerr);


  Arc::OptionParser options(istring("url"),
                            istring("The arcrm command deletes files and on "
                                    "grid storage elements."));

  bool force = false;
  options.AddOption('f', "force",
                    istring("remove logical file name registration even "
                            "if not all physical instances were removed"),

  int timeout = 20;
  options.AddOption('t', "timeout", istring("timeout in seconds (default 20)"),
                    istring("seconds"), timeout);

  std::string conffile;
  options.AddOption('z', "conffile",
                    istring("configuration file (default ~/.arc/client.conf)"),
                    istring("filename"), conffile);

  std::string debug;
  options.AddOption('d', "debug",
                    istring("FATAL, ERROR, WARNING, INFO, VERBOSE or DEBUG"),
                    istring("debuglevel"), debug);

  bool version = false;
  options.AddOption('v', "version", istring("print version information"),

  std::list<std::string> params = options.Parse(argc, argv);

  // If debug is specified as argument, it should be set before loading the configuration.
  if (!debug.empty())

  Arc::UserConfig usercfg(conffile);
  if (!usercfg) {
    logger.msg(Arc::ERROR, "Failed configuration initialization");
    return 1;

  if (debug.empty() && !usercfg.Verbosity().empty())

  if (version) {
    std::cout << Arc::IString("%s version %s", "arcrm", VERSION) << std::endl;
    return 0;

  if (params.size() != 1) {
    logger.msg(Arc::ERROR, "Wrong number of parameters specified");
    return 1;

  std::list<std::string>::iterator it = params.begin();
  if (!arcrm(*it, usercfg, force, timeout))
    return 1;

  return 0;

Here is the call graph for this function: