40 #include <sys/param.h>
41 #include <sys/types.h>
48 using namespace XrdCl;
54 #define EMSG(x) std::cerr <<"xrdprep: "<<x<<std::endl
62 bool GetNum(
const char *
emsg,
const char *item,
int *val,
int minv,
int maxv=-1)
67 {
EMSG(
emsg<<
" value not specified");
return false;}
70 *val = strtol(item, &eP, 10);
72 {
EMSG(
emsg<<
" '"<<item<<
"' is not a number");
77 {
EMSG(
emsg<<
" may not be less than "<<minv);
return false;}
78 if (maxv >= 0 && *val > maxv)
79 {
EMSG(
emsg<<
" may not be greater than "<<maxv);
return false;}
93 std::cerr<<
"\nUsage: xrdprep [opts1] [prepare] host[:port] [path [...]]\n";
94 std::cerr<<
"\n xrdprep [opts2] {cancel | query} host[:port] handle [path [...]]\n";
95 std::cerr<<
"\nOpts1: [-E] [-p prty] [-s] [-S] [-w] [opts2]\n";
96 std::cerr<<
"\nOpts2: [-d n] [-f fn]" <<std::endl;
105 int main(
int argc,
char **argv)
108 extern int optind, opterr;
110 static const int MaxPathLen = MAXPATHLEN+1;
115 std::vector<std::string> fList;
117 const char *msgArgs[] = {
"execute",
"prepare"};
121 int rc, Prty = 0,
Debug = 0;
123 bool isQuery =
false, needHandle =
false;
127 if (argc <= 1)
Usage(0);
132 if (argc > 1 &&
'-' == *argv[1])
133 while ((c = getopt(argc,argv,
"d:Ef:p:sStw")) && ((
unsigned char)c != 0xff))
136 case 'd':
if (!GetNum(
"debug level", optarg, &
Debug, 0, 5)) exit(1);
138 case 'E': lastOpt = c;
141 case 'f': inFile = optarg;
143 case 'p': lastOpt = c;
144 if (!GetNum(
"priority", optarg, &Prty, 0, 3)) exit(1);
154 default:
EMSG(
"Invalid option '-"<<argv[
optind-1]<<
"'");
163 else if (!strcmp(argv[
optind],
"query")) isQuery =
true;
164 else if (!strcmp(argv[
optind],
"prepare")){
optind++;
break;}
167 {
EMSG(
'-'<<lastOpt<<
"' option is invalid for '"<<argv[
optind]<<
"'");
171 msgArgs[0] = argv[
optind++];
178 {
EMSG(
"target host name not specified");
184 strcpy(Target,
"root://");
185 strcat(Target, argv[
optind]);
192 {
EMSG(msgArgs[0]<<
" prepare request handle not specified");
201 for (
int i =
optind; i < argc; i++)
203 totArgLen += strArg.size() + 1;
204 fList.push_back(strArg);
214 char *sP, fBuff[MaxPathLen];
215 do {
if (!(sP = fgets(fBuff, MaxPathLen,
Stream)))
break;
216 while(*sP && *sP ==
' ') sP++;
217 if (*sP && *sP !=
'\n')
219 if (strArg.size() && strArg.back() ==
'\n') strArg.pop_back();
220 while(strArg.size() && strArg.back() ==
' ') strArg.pop_back();
221 totArgLen += strArg.size() + 1;
222 fList.push_back(strArg);
225 if ((rc = ferror(
Stream)))
234 if (!needHandle && fList.size() == 0)
235 {
EMSG(
"No files specified for 'prepare'");
246 {
const char *dbg[] = {
"Info",
"Warning",
"Error",
"Debug",
"Dump"};
259 if (!isQuery) st =
Admin.Prepare(fList,
Opts, uint8_t(Prty), response);
260 else {
Buffer qryArgs(totArgLen);
262 for (
int i = 0; i < (int)fList.size(); i++)
263 {strcpy(bP, fList[i].c_str());
264 bP += fList[i].size();
274 {std::string estr = st.
ToStr();
275 const char *einfo, *etxt = estr.c_str();
276 if (!(einfo = rindex(etxt,
']'))) einfo = etxt;
278 while(*einfo && *einfo ==
' ') einfo++;
280 EMSG(
"Unable to "<<msgArgs[0]<<
' '<<msgArgs[1]<<
"; "
281 <<(
char)tolower(*einfo)<<einfo+1);
287 std::string rstr = response->
ToString();
288 const char *xx = rstr.c_str();
289 if (*xx) std::cout << xx << std::endl;
void Usage(const char *msg)
int main(int argc, char **argv)
int emsg(int rc, char *msg)
const char * XrdSysE2T(int errcode)
Binary blob representation.
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
std::string ToString() const
Convert the buffer to a string.
Send file/filesystem queries to an XRootD cluster.
std::string ToStr() const
Convert to string.
static int Export(const char *Var, const char *Val)
@ Cancel
cancel staging request
@ Colocate
co-locate staged files, if possible
@ Prepare
Query prepare status.
bool IsOK() const
We're fine.