-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdCommandLine.cc
1961 lines (1654 loc) · 59 KB
/
XrdCommandLine.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************/
/* */
/* X r d C o m m a n d L i n e . c c */
/* */
/* Author: Fabrizio Furano (INFN Padova, 2005) */
/* Rewritten by Elvin Sindrilaru <elvin.alin.sindrilaru@cern.ch> */
/* with mods from Lukasz Janyst <ljanyst@cern.ch> (CERN, 2010) */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
//------------------------------------------------------------------------------
// A command line tool for xrootd environments. The executable normally
// is named xrd.
//------------------------------------------------------------------------------
#include "XrdClient/XrdClientUrlInfo.hh"
#include "XrdClient/XrdClient.hh"
#include "XrdClient/XrdClientAdmin.hh"
#include "XrdClient/XrdClientDebug.hh"
#include "XrdClient/XrdClientEnv.hh"
#include "XrdOuc/XrdOucTokenizer.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include <stdio.h>
#include <unistd.h>
#include <stdarg.h>
#include <sstream>
#include <string>
#include <signal.h>
#include <iomanip>
#ifdef HAVE_READLINE
#include <readline/readline.h>
#include <readline/history.h>
#endif
#define XRDCLI_VERSION "(C) 2004-2010 by the Xrootd group. Xrootd version: " XrdVSTRING
//------------------------------------------------------------------------------
// Some globals
//------------------------------------------------------------------------------
char *opaqueinfo = 0; // opaque info to be added to urls
kXR_unt16 xrd_wr_flags = kXR_async | kXR_mkpath | kXR_open_updt | kXR_new;
char *initialhost = 0;
XrdClient *genclient = 0;
XrdClientAdmin *genadmin = 0;
XrdOucString currentpath = "/";
XrdOucString cmdline_cmd;
//------------------------------------------------------------------------------
// Interrupt signal handler
//------------------------------------------------------------------------------
void CtrlCHandler(int sig)
{
std::cerr << std::endl;
std::cerr << "Please use 'exit' to terminate this program." << std::endl;
}
//------------------------------------------------------------------------------
// Commandline help message
//------------------------------------------------------------------------------
void PrintUsage()
{
std::cerr << "usage: xrd [host]";
std::cerr << "[-DSparmname stringvalue] ... [-DIparmname intvalue] ";
std::cerr << "[-O<opaque info>] [command]" << std::endl;
std::cerr << " -DSparmname stringvalue : ";
std::cerr << "override the default value of an internal XrdClient setting ";
std::cerr << "(of string type)" << std::endl;
std::cerr << " -DIparmname intvalue : ";
std::cerr << "override the default value of an internal XrdClient setting ";
std::cerr << "(of int type)" << std::endl;
std::cerr << " -O : adds some opaque information to any used ";
std::cerr << "xrootd url" << std::endl;
std::cerr << " -h : this help screen" << std::endl;
std::cerr <<std::endl << " where:" << std::endl;
std::cerr << " parmname is the name of an internal parameter";
std::cerr << std::endl;
std::cerr << " stringvalue is a string to be assigned to an internal ";
std::cerr << "parameter" << std::endl;
std::cerr << " intvalue is an int to be assigned to an internal ";
std::cerr << "parameter" << std::endl;
std::cerr << " command is a command line to be executed. in this ";
std::cerr << "case the host is mandatory." << std::endl;
std::cerr << std::endl;
}
//------------------------------------------------------------------------------
// Commandline prompt
//------------------------------------------------------------------------------
void BuildPrompt( std::stringstream &s )
{
s.clear();
if (genadmin)
{
s << "root://" << genadmin->GetCurrentUrl().Host;
s << ":" << genadmin->GetCurrentUrl().Port;
s << "/" << currentpath;
}
s << "> ";
}
//------------------------------------------------------------------------------
// Out own primitive implementation of GNU readline
//------------------------------------------------------------------------------
#ifndef HAVE_READLINE
char *readline(const char *prompt)
{
std::cout << prompt << std::flush;
std::string input;
std::getline( std::cin, input );
if( !cin.good() )
return 0;
char *linebuf = (char *)malloc( input.size()+1 );
strncpy( linebuf, input.c_str(), input.size()+1 );
return linebuf;
}
#endif
//------------------------------------------------------------------------------
// Print help
//------------------------------------------------------------------------------
void PrintHelp()
{
std::cout << std::endl << XRDCLI_VERSION << std::endl << std::endl;
std::cout << "Usage: xrd [-O<opaque_info>] [-DS<var_name> stringvalue] ";
std::cout << "[-DI<var_name> integervalue] [host[:port]] [batchcommand]";
std::cout << std::endl << std::endl;
std::cout << "List of available commands:" << std::endl << std::endl;
std::cout << std::left;
std::cout << std::setw(55) << "cat <filename> [xrdcp parameters]";
std::cout << "Output a file on standard output using xrdcp. <filename> ";
std::cout << "can be a root:// URL." << std::endl;
std::cout << std::setw(55) << "cd <dirname>";
std::cout << "Change the current directory. Note: no existence check is ";
std::cout << "performed." << std::endl;
std::cout << std::setw(55) << "chmod <fileordirname> <user> <group> <other>";
std::cout << "Modify file permissions." << std::endl;
std::cout << std::setw(55) << "connect [hostname[:port]]";
std::cout << "Connect to the specified host." << std::endl;
std::cout << std::setw(55) << "cp <fileordirname> <fileordirname> [xrdcp parameters]";
std::cout << "Copies a file using xrdcp. <fileordirname> are always ";
std::cout << "relative to the" << std::endl;
std::cout << std::setw(55) << " " << "current remote path. Also, they ";
std::cout << "can be root:// URLs specifying any other host." << std::endl;
std::cout << std::setw(55) << "dirlist [dirname]";
std::cout << "Get the requested directory listing." << std::endl;
std::cout << std::setw(55) << "dirlistrec [dirname]";
std::cout << "Get the requested recursive directory listing.";
std::cout << std::endl;
std::cout << std::setw(55) << "envputint <varname> <intval>";
std::cout << "Put an integer in the internal environment." << std::endl;
std::cout << std::setw(55) << "envputstring <varname> <stringval>";
std::cout << "Put a string in the internal environment." << std::endl;
std::cout << std::setw(55) << "exit";
std::cout << "Exits from the program." << std::endl;
std::cout << std::setw(55) << "help";
std::cout << "This help screen." << std::endl;
std::cout << std::setw(55) << "stat [fileordirname]";
std::cout << "Get info about the given file or directory path.";
std::cout << std::endl;
std::cout << std::setw(55) << "statvfs [vfilesystempath]";
std::cout << "Get info about a virtual file system." << std::endl;
std::cout << std::setw(55) << "existfile <filename>";
std::cout << "Test if the specified file exists." << std::endl;
std::cout << std::setw(55) << "existdir <dirname>";
std::cout << "Test if the specified directory exists." << std::endl;
std::cout << std::setw(55) << "getchecksum <filename>";
std::cout << "Get the checksum for the specified file." << std::endl;
std::cout << std::setw(55) << "isfileonline <filename>";
std::cout << "Test if the specified file is online." << std::endl;
std::cout << std::setw(55) << "locatesingle <filename> <writable>";
std::cout << "Give a location of the given file in the currently ";
std::cout << "connected cluster." << std::endl;
std::cout << std::setw(55) << " " << "if writable is true only a ";
std::cout << "writable location is searched" << std::endl;
std::cout << std::setw(55) << " " << "but, if no writable locations ";
std::cout << "are found, the result is negative but may" << std::endl;
std::cout << std::setw(55) << " " << "propose a non writable one.";
std::cout << std::endl;
std::cout << std::setw(55) << "locateall <filename>";
std::cout << "Give all the locations of the given file in the currently";
std::cout << "connected cluster." << std::endl;
std::cout << std::setw(55) << "mv <filename1> <filename2>";
std::cout << "Move filename1 to filename2 locally to the same server.";
std::cout << std::endl;
std::cout << std::setw(55) << "mkdir <dirname> [user] [group] [other]";
std::cout << "Creates a directory." << std::endl;
std::cout << std::setw(55) << "rm <filename>";
std::cout << "Remove a file." << std::endl;
std::cout << std::setw(55) << "rmdir <dirname>";
std::cout << "Removes a directory." << std::endl;
std::cout << std::setw(55) << "prepare <filename> <options> <priority>";
std::cout << "Stage a file in." << std::endl;
std::cout << std::setw(55) << "query <reqcode> <parms>";
std::cout << "Obtain server information." << std::endl;
std::cout << std::setw(55) << "queryspace <logicalname>";
std::cout << "Obtain space information." << std::endl;
std::cout << std::setw(55) << "truncate <filename> <length>";
std::cout << "Truncate a file." << std::endl;
std::cout << std::endl << "For further information, please read the ";
std::cout << "xrootd protocol documentation." << std::endl;
std::cout << std::endl;
}
//------------------------------------------------------------------------------
// Check the answer of the server
//------------------------------------------------------------------------------
bool CheckAnswer(XrdClientAbs *gencli)
{
if (!gencli->LastServerResp()) return false;
switch (gencli->LastServerResp()->status)
{
case kXR_ok:
return true;
case kXR_error:
std::cout << "Error " << gencli->LastServerError()->errnum;
std::cout << ": " << gencli->LastServerError()->errmsg << std::endl;
std::cout << std::endl;
return false;
default:
std::cout << "Server response: " << gencli->LastServerResp()->status;
std::cout << std::endl;
return true;
}
}
//------------------------------------------------------------------------------
// Print the output from locate
//------------------------------------------------------------------------------
void PrintLocateInfo(XrdClientLocate_Info &loc)
{
std::cout << "InfoType: ";
switch (loc.Infotype)
{
case XrdClientLocate_Info::kXrdcLocNone:
std::cout << "none" << std::endl;
break;
case XrdClientLocate_Info::kXrdcLocDataServer:
std::cout << "kXrdcLocDataServer" << std::endl;
break;
case XrdClientLocate_Info::kXrdcLocDataServerPending:
std::cout << "kXrdcLocDataServerPending" << std::endl;
break;
case XrdClientLocate_Info::kXrdcLocManager:
std::cout << "kXrdcLocManager" << std::endl;
break;
case XrdClientLocate_Info::kXrdcLocManagerPending:
std::cout << "kXrdcLocManagerPending" << std::endl;
break;
default:
std::cout << "Invalid Infotype" << std::endl;
}
std::cout << "CanWrite: ";
if (loc.CanWrite) std::cout << "true" << std::endl;
else std::cout << "false" << std::endl;
std::cout << "Location: '" << loc.Location << "'" << std::endl;
}
//------------------------------------------------------------------------------
// process the "EXISTDIR" command
//------------------------------------------------------------------------------
void executeExistDir(XrdOucTokenizer &tkzer)
{
int retval = 0;
if (!genadmin)
{
std::cout << "Not connected to any server." << std::endl << std::endl;
retval = 1;
}
if (!retval)
{
char *fname = tkzer.GetToken(0, 0);
XrdOucString pathname;
if (fname)
{
if (fname[0] == '/')
pathname = fname;
else
pathname = currentpath + "/" + fname;
}
else pathname = currentpath;
// Try to issue the request
vecBool vb;
vecString vs;
vs.Push_back(pathname);
genadmin->ExistDirs(vs, vb);
// Check the answer
if (vb[0] && (vb.GetSize() >= 1))
std::cout << "The directory exists." << std::endl;
else
std::cout << "Directory not found." << std::endl;
std::cout << std::endl;
return;
}
}
//------------------------------------------------------------------------------
// process the "CD" command
//------------------------------------------------------------------------------
void executeCd(XrdOucTokenizer &tkzer)
{
char *parmname = tkzer.GetToken(0, 0);
XrdOucString pathname;
if (!genadmin)
{
std::cout << "Not connected to any server." << std::endl << std::endl;
return;
}
if (!parmname || !strlen(parmname))
{
std::cout << "A directory name is needed." << std::endl << std::endl;
}
else
{
// Quite trivial directory processing
if (!strcmp(parmname, ".."))
{
if (currentpath == "/") return;
int pos = currentpath.rfind('/');
if (pos != STR_NPOS)
currentpath.erase(pos);
if (!currentpath.length())
currentpath = "/";
return;
}
else if (!strcmp(parmname, "."))
{
return;
}
if (!currentpath.length() || (currentpath[currentpath.length()-1] != '/'))
currentpath += "/";
XrdOucString tmpPath;
if (parmname[0] == '/')
tmpPath = parmname;
else
tmpPath = currentpath + parmname;
// Verify if tmpPath really exists
vecBool vb;
vecString vs;
vs.Push_back(tmpPath);
genadmin->ExistDirs(vs, vb);
// Now check the answer
if (CheckAnswer(genadmin))
currentpath = tmpPath;
else
std::cout << "The directory does not exist." << std::endl << std::endl;
return;
}
}
//------------------------------------------------------------------------------
// process the "ENVPUTINT" command
//------------------------------------------------------------------------------
void executeEnvPutInt(XrdOucTokenizer &tkzer)
{
char *parmname = tkzer.GetToken(0, 0),
*val = tkzer.GetToken(0, 1);
if (!parmname || !val)
{
std::cout << "Please provide command parameters:envputint <varname> ";
std::cout << "<intvalue>" << std::endl << std::endl;
}
else
{
EnvPutInt(parmname, atoi(val));
DebugSetLevel(EnvGetLong(NAME_DEBUG));
}
return;
}
//------------------------------------------------------------------------------
// process the "ENVPUTSTRING" command
//------------------------------------------------------------------------------
void executeEnvPutString(XrdOucTokenizer &tkzer)
{
char *parmname = tkzer.GetToken(0, 0),
*val = tkzer.GetToken(0, 1);
if (!parmname || !val)
{
std::cout << "Please provide command parameters:envputstring <varname> ";
std::cout << "<stringvalue>" << std::endl << std::endl;
}
else
EnvPutString(parmname, val);
return;
}
//------------------------------------------------------------------------------
// process the "HELP" command
//------------------------------------------------------------------------------
void executeHelp(XrdOucTokenizer &)
{
PrintHelp();
}
//------------------------------------------------------------------------------
// process the "CONNECT" command
//------------------------------------------------------------------------------
void executeConnect(XrdOucTokenizer &tkzer)
{
int retval = 0;
char *host = initialhost;
// If no host was given, then pretend one
if (!host)
{
host = tkzer.GetToken(0, 1);
if (!host || !strlen(host))
{
std::cout << "A hostname is needed to connect somewhere.";
std::cout << std::endl << std::endl;
retval = 1;
}
}
if (!retval)
{
// Init the instance
if (genadmin) delete genadmin;
XrdOucString h(host);
h = "root://" + h;
h += "//dummy";
genadmin = new XrdClientAdmin(h.c_str());
// Then connect
if (!genadmin->Connect())
{
delete genadmin;
genadmin = 0;
}
}
}
//------------------------------------------------------------------------------
// process the "DIRLISTREC" command
//------------------------------------------------------------------------------
void executeDirListRec(XrdOucTokenizer &tkzer)
{
XrdClientVector<XrdOucString> pathq;
int retval = 0;
if (!genadmin)
{
std::cout << "Not connected to any server." << std::endl << std::endl;
retval = 1;
}
if (!retval)
{
char *dirname = tkzer.GetToken(0, 0);
XrdOucString path;
if (dirname)
{
if (dirname[0] == '/')
path = dirname;
else
{
if ((currentpath.length() > 0) &&
(currentpath[currentpath.length()-1] != '/'))
path = currentpath + "/" + dirname;
else
path = currentpath + dirname;
}
}
else path = currentpath;
if (!path.length())
{
std::cout << "The current path is an empty string. Assuming '/'.";
std::cout << std::endl << std::endl;
path = '/';
}
// Initialize the queue with this path
pathq.Push_back(path);
while (pathq.GetSize() > 0)
{
XrdOucString pathtodo = pathq.Pop_back();
// Now try to issue the request
XrdClientVector<XrdClientAdmin::DirListInfo> nfo;
genadmin->DirList(pathtodo.c_str(), nfo, true);
// Now check the answer
if (!CheckAnswer(genadmin))
{
retval = 1;
std::cout << "In server ";
std::cout << genadmin->GetCurrentUrl().HostWPort;
std::cout << " or in some of its child nodes." << std::endl;
break;
}
for (int i = 0; i < nfo.GetSize(); i++)
{
if ((nfo[i].flags & kXR_isDir) &&
(nfo[i].flags & kXR_readable) &&
(nfo[i].flags & kXR_xset))
{
// The path has not to be pushed if it's already present
// This may happen if several servers have the same path
bool foundpath = false;
for (int ii = 0; ii < pathq.GetSize(); ii++)
{
if (nfo[i].fullpath == pathq[ii])
{
foundpath = true;
break;
}
}
if (!foundpath)
pathq.Push_back(nfo[i].fullpath);
else
// If the path is already present in the queue
// then it was already printed as well.
continue;
}
char ts[256];
strcpy(ts, "n/a");
struct tm *t = gmtime(&nfo[i].modtime);
strftime(ts, 255, "%F %T", t);
char cflgs[16];
memset(cflgs, 0, 16);
if (nfo[i].flags & kXR_isDir)
strcat(cflgs, "d");
else strcat(cflgs, "-");
if (nfo[i].flags & kXR_readable)
strcat(cflgs, "r");
else strcat(cflgs, "-");
if (nfo[i].flags & kXR_writable)
strcat(cflgs, "w");
else strcat(cflgs, "-");
if (nfo[i].flags & kXR_xset)
strcat(cflgs, "x");
else strcat(cflgs, "-");
printf( "%s(%03ld) %12lld %s %s\n",
cflgs, nfo[i].flags, nfo[i].size,
ts, nfo[i].fullpath.c_str());
}
}
}
std::cout << std::endl;
return;
}
//------------------------------------------------------------------------------
// process the "DIRLIST" command
//------------------------------------------------------------------------------
void executeDirList(XrdOucTokenizer &tkzer)
{
int retval = 0;
if (!genadmin)
{
std::cout << "Not connected to any server." << std::endl << std::endl;
retval = 1;
}
if (!retval)
{
char *dirname = tkzer.GetToken(0, 0);
XrdOucString path;
if (dirname)
{
if (dirname[0] == '/')
path = dirname;
else
{
if ((currentpath.length() > 0) &&
(currentpath[currentpath.length()-1] != '/'))
path = currentpath + "/" + dirname;
else
path = currentpath + dirname;
}
}
else path = currentpath;
if (!path.length())
{
std::cout << "The current path is an empty string. Assuming '/'.";
std::cout << std::endl << std::endl;
path = '/';
}
// Now try to issue the request
XrdClientVector<XrdClientAdmin::DirListInfo> nfo;
genadmin->DirList(path.c_str(), nfo, true);
// Now check the answer
if (!CheckAnswer(genadmin))
{
retval = 1;
std::cout << "In server " << genadmin->GetCurrentUrl().HostWPort;
std::cout << " or in some of its child nodes." << std::endl;
//nfo.Clear();
}
for (int i = 0; i < nfo.GetSize(); i++)
{
char ts[256];
strcpy(ts, "n/a");
struct tm *t = gmtime(&nfo[i].modtime);
strftime(ts, 255, "%F %T", t);
char cflgs[16];
memset(cflgs, 0, 16);
if (nfo[i].flags & kXR_isDir)
strcat(cflgs, "d");
else strcat(cflgs, "-");
if (nfo[i].flags & kXR_readable)
strcat(cflgs, "r");
else strcat(cflgs, "-");
if (nfo[i].flags & kXR_writable)
strcat(cflgs, "w");
else strcat(cflgs, "-");
if (nfo[i].flags & kXR_xset)
strcat(cflgs, "x");
else strcat(cflgs, "-");
printf( "%s(%03ld) %12lld %s %s\n",
cflgs, nfo[i].flags, nfo[i].size, ts,
nfo[i].fullpath.c_str());
}
std::cout << std::endl;
}
return;
}
//------------------------------------------------------------------------------
// process the "LOCATESINGLE" command
//------------------------------------------------------------------------------
void executeLocateSingle(XrdOucTokenizer &tkzer)
{
int retval = 0;
if (!genadmin)
{
std::cout << "Not connected to any server." <<std::endl;
retval = 1;
}
if (!retval)
{
char *fname = tkzer.GetToken(0, 0);
XrdOucString pathname;
if (fname)
{
if (fname[0] == '/')
pathname = fname;
else
pathname = currentpath + "/" + fname;
}
else pathname = currentpath;
char *writable = tkzer.GetToken(0, 1);
bool wrt = false;
if (writable)
{
wrt = true;
if (!strcmp(writable, "false") ||
!strcmp(writable, "0")) wrt = false;
else
std::cout << "Checking for a writable location." <<std::endl;
}
// Now try to issue the request
XrdClientLocate_Info loc;
bool r;
r = genadmin->Locate((kXR_char *)pathname.c_str(), loc, wrt);
if (!r)
std::cout << "No matching files were found." <<std::endl;
PrintLocateInfo(loc);
std::cout << std::endl;
}
return;
}
//------------------------------------------------------------------------------
// process the "LOCATEALL" command
//------------------------------------------------------------------------------
void executeLocateAll(XrdOucTokenizer &tkzer)
{
int retval = 0;
if (!genadmin)
{
std::cout << "Not connected to any server." <<std::endl << std::endl;
retval = 1;
}
if (!retval)
{
char *fname = tkzer.GetToken(0, 0);
XrdOucString pathname;
if (fname)
{
if (fname[0] == '/')
pathname = fname;
else
pathname = currentpath + "/" + fname;
}
else pathname = currentpath;
// Now try to issue the request
XrdClientVector<XrdClientLocate_Info> loc;
bool r;
r = genadmin->Locate((kXR_char *)pathname.c_str(), loc);
if (!r)
std::cout << "No matching files were found." <<std::endl;
for (int ii = 0; ii < loc.GetSize(); ii++)
{
std::cout << std::endl << std::endl;
std::cout << "------------- Location #" << ii+1 << std::endl;
PrintLocateInfo(loc[ii]);
}
std::cout << std::endl;
}
}
//------------------------------------------------------------------------------
// process the "STAT" command
//------------------------------------------------------------------------------
void executeStat(XrdOucTokenizer &tkzer)
{
int retval = 0;
if (!genadmin)
{
std::cout << "Not connected to any server." << std::endl << std::endl;
retval = 1;
}
if (!retval)
{
char *fname = tkzer.GetToken(0, 0);
XrdOucString pathname;
if (fname)
{
if (fname[0] == '/')
pathname = fname;
else
pathname = currentpath + "/" + fname;
}
else pathname = currentpath;
// Now try to issue the request
long id, flags, modtime;
long long size;
genadmin->Stat(pathname.c_str(), id, size, flags, modtime);
// Now check the answer
if (!CheckAnswer(genadmin))
{
std::cout << "The command returned an error.";
std::cout << std::endl << std::endl;
}
else
{
std::cout << "Id: " << id << " Size: " << size << " Flags: ";
std::cout << flags << " Modtime: " << modtime << std::endl;
std::cout <<std::endl;
}
}
}
//------------------------------------------------------------------------------
// process the "STATVFS" command
//------------------------------------------------------------------------------
void executeStatvfs(XrdOucTokenizer &tkzer)
{
int retval = 0;
if (!genadmin)
{
std::cout << "Not connected to any server." << std::endl << std::endl;
retval = 1;
}
if (!retval)
{
char *fname = tkzer.GetToken(0, 0);
XrdOucString pathname;
if (fname)
{
if (fname[0] == '/')
pathname = fname;
else
pathname = currentpath + "/" + fname;
}
else pathname = currentpath;
// Now try to issue the request
int rwservers = 0;
long long rwfree = 0;
int rwutil = 0;
int stagingservers = 0;
long long stagingfree = 0;
int stagingutil = 0;
genadmin->Stat_vfs(pathname.c_str(), rwservers, rwfree, rwutil,
stagingservers, stagingfree, stagingutil);
// Now check the answer
if (!CheckAnswer(genadmin))
{
std::cout << "The command returned an error.";
std::cout << std::endl <<std::endl;
}
else
{
std::cout << "r/w nodes: " << rwservers;
std::cout << " r/w free space: " << rwfree;
std::cout << " r/w utilization: " << rwutil;
std::cout << " staging nodes: " << rwservers;
std::cout << " staging free space: " << rwfree;
std::cout << " staging utilization: " << rwutil;
std::cout << std::endl << std::endl;
}
}
}
//------------------------------------------------------------------------------
// process the "EXISTFILE" command
//------------------------------------------------------------------------------
void executeExistFile(XrdOucTokenizer &tkzer)
{
int retval = 0;
if (!genadmin)
{
std::cout << "Not connected to any server." << std::endl << std::endl;
retval = 1;
}
if (!retval)
{
char *fname = tkzer.GetToken(0, 0);
XrdOucString pathname;
if (fname)
{
if (fname[0] == '/')
pathname = fname;
else
pathname = currentpath + "/" + fname;
}
else pathname = currentpath;
// Now try to issue the request
vecBool vb;
vecString vs;
vs.Push_back(pathname);
genadmin->ExistFiles(vs, vb);
// Now check the answer
if (!CheckAnswer(genadmin))
retval = 1;
if (vb[0] && (vb.GetSize() >= 1))
std::cout << "The file exists." << std::endl;
else
std::cout << "File not found." << std::endl;
std::cout <<std::endl;
}
}
//------------------------------------------------------------------------------
// process the "GETCHECKSUM" command
//------------------------------------------------------------------------------
void executeGetCheckSum(XrdOucTokenizer &tkzer)
{
int retval = 0;
if (!genadmin)
{
std::cout << "Not connected to any server." << std::endl << std::endl;
retval = 1;
}
if (!retval)
{
char *fname = tkzer.GetToken(0, 0);
XrdOucString pathname;