106{
107 extern char *optarg;
108 extern int optind, opterr;
109
110 static const int MaxPathLen = MAXPATHLEN+1;
114
115 std::vector<std::string> fList;
117 const char *msgArgs[] = {"execute", "prepare"};
118 char Target[512];
119 char *inFile = 0;
121 int rc, Prty = 0,
Debug = 0;
122 char c, lastOpt = 0;
123 bool isQuery = false, needHandle = false;
124
125
126
127 if (argc <= 1)
Usage(0);
128
129
130
131 opterr = 0;
132 if (argc > 1 && '-' == *argv[1])
133 while ((c = getopt(argc,argv,"d:Ef:p:sStw")) && ((unsigned char)c != 0xff))
134 { switch(c)
135 {
136 case 'd':
if (!GetNum(
"debug level", optarg, &
Debug, 0, 5)) exit(1);
137 break;
138 case 'E': lastOpt = c;
140 break;
141 case 'f': inFile = optarg;
142 break;
143 case 'p': lastOpt = c;
144 if (!GetNum("priority", optarg, &Prty, 0, 3)) exit(1);
145 break;
147 break;
149 break;
151 break;
153 break;
154 default:
EMSG(
"Invalid option '-"<<argv[
optind-1]<<
"'");
156 }
157 }
158
159
160
163 else if (!strcmp(argv[
optind],
"query")) isQuery =
true;
164 else if (!strcmp(argv[
optind],
"prepare")){
optind++;
break;}
165 else break;
166 if (lastOpt)
167 {
EMSG(
'-'<<lastOpt<<
"' option is invalid for '"<<argv[
optind]<<
"'");
169 }
170 needHandle = true;
171 msgArgs[0] = argv[
optind++];
172 break;
173 }
174
175
176
178 {
EMSG(
"target host name not specified");
180 }
181
182
183
184 strcpy(Target, "root://");
185 strcat(Target, argv[
optind]);
187
188
189
190 if (needHandle)
192 {
EMSG(msgArgs[0]<<
" prepare request handle not specified");
194 }
195 }
196
197
198
199 std::string strArg;
200 int totArgLen = 0;
201 for (
int i =
optind; i < argc; i++)
202 {strArg = argv[i];
203 totArgLen += strArg.size() + 1;
204 fList.push_back(strArg);
205 }
206
207
208
209 if (inFile)
212 exit(4);
213 }
214 char *sP, fBuff[MaxPathLen];
215 do {
if (!(sP = fgets(fBuff, MaxPathLen,
Stream)))
break;
216 while(*sP && *sP == ' ') sP++;
217 if (*sP && *sP != '\n')
218 {strArg = sP;
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);
223 }
225 if ((rc = ferror(
Stream)))
227 exit(4);
228 }
230 }
231
232
233
234 if (!needHandle && fList.size() == 0)
235 {
EMSG(
"No files specified for 'prepare'");
237 }
238
239
240
242
243
244
246 {const char *dbg[] = {"Info","Warning","Error","Debug","Dump"};
249 }
250
251
252
254
255
256
259 if (!isQuery) st =
Admin.Prepare(fList, Opts, uint8_t(Prty), response);
260 else {
Buffer qryArgs(totArgLen);
261 char *bP = qryArgs.GetBuffer();
262 for (int i = 0; i < (int)fList.size(); i++)
263 {strcpy(bP, fList[i].c_str());
264 bP += fList[i].size();
265 *bP++ = '\n';
266 }
267 *(bP-1) = 0;
269 }
270
271
272
274 {std::string estr = st.
ToStr();
275 const char *einfo, *etxt = estr.c_str();
276 if (!(einfo = rindex(etxt, ']'))) einfo = etxt;
277 else {einfo++;
278 while(*einfo && *einfo == ' ') einfo++;
279 }
280 EMSG(
"Unable to "<<msgArgs[0]<<
' '<<msgArgs[1]<<
"; "
281 <<(char)tolower(*einfo)<<einfo+1);
282 exit(8);
283 }
284
285
286
287 std::string rstr = response->
ToString();
288 const char *xx = rstr.c_str();
289 if (*xx) std::cout << xx << std::endl;
290 delete response;
291
292
293
294 exit(0);
295}
void Usage(const char *msg)
const char * XrdSysE2T(int errcode)
Binary blob representation.
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.