47#include <readline/readline.h>
48#include <readline/history.h>
57 const std::string &path )
63 env->
GetInt(
"NoCWD", noCwd );
65 if( path[0] ==
'/' || noCwd )
71 std::string cwd =
"/";
80 std::list<std::string> pathComponents;
81 std::list<std::string>::iterator it;
84 for( it = pathComponents.begin(); it != pathComponents.end(); )
88 it = pathComponents.erase( it );
94 if( it == pathComponents.begin() )
96 std::list<std::string>::iterator it1 = it;
98 it = pathComponents.erase( it1 );
99 it = pathComponents.erase( it );
106 for( it = pathComponents.begin(); it != pathComponents.end(); ++it )
111 if( newPath.length() > 1 )
112 newPath.erase( newPath.length()-1, 1 );
122 if( modeStr.length() != 9 )
126 for(
int i = 0; i < 3; ++i )
128 if( modeStr[i] ==
'r' )
130 else if( modeStr[i] ==
'w' )
132 else if( modeStr[i] ==
'x' )
134 else if( modeStr[i] !=
'-' )
137 for(
int i = 3; i < 6; ++i )
139 if( modeStr[i] ==
'r' )
141 else if( modeStr[i] ==
'w' )
143 else if( modeStr[i] ==
'x' )
145 else if( modeStr[i] !=
'-' )
148 for(
int i = 6; i < 9; ++i )
150 if( modeStr[i] ==
'r' )
152 else if( modeStr[i] ==
'w' )
154 else if( modeStr[i] ==
'x' )
156 else if( modeStr[i] !=
'-' )
173 uint32_t argc = args.size();
177 log->
Error(
AppMsg,
"Wrong number of arguments." );
179 "Wrong number of arguments." );
182 if( args[1] !=
"evict" && args[1] !=
"fevict")
188 std::string fullPath;
189 if( !
BuildPath( fullPath, env, args[2] ).IsOK() )
198 std::string cmd = args[1];
200 cmd.append(fullPath);
211 st.
ToStr().c_str() );
217 std::cout << response->
ToString() <<
'\n';
235 if( args.size() != 2 )
237 log->
Error(
AppMsg,
"Invalid arguments. Expected a path." );
244 env->
PutInt(
"NoCWD", 0 );
247 if( !
BuildPath( newPath, env, args[1] ).IsOK() )
266 log->
Error(
AppMsg,
"%s is not a directory.", newPath.c_str() );
280 if( nb == 0 )
return 1;
281 return uint32_t( log10(
double(nb) ) + 1);
295 std::cout <<
" " << std::setw( ownerwidth ) << info->
GetOwner();
296 std::cout <<
" " << std::setw( groupwidth ) << info->
GetGroup();
297 std::cout <<
" " << std::setw( sizewidth ) << info->
GetSize();
299 std::cout <<
" " << std::setw( sizewidth ) << info->
GetChecksum();
326 uint64_t size = info->
GetSize();
328 if( width < 12 ) width = 12;
329 std::cout << std::setw( width ) << info->
GetSize() <<
" ";
344 uint32_t argc = args.size();
346 bool showUrls =
false;
357 for( uint32_t i = 1; i < args.size(); ++i )
359 if( args[i] ==
"-l" )
364 else if( args[i] ==
"-u" )
366 else if( args[i] ==
"-R" )
370 else if( args[i] ==
"-D" )
375 else if( args[i] ==
"-Z" )
380 else if( args[i] ==
"-C" )
396 std::string newPath =
"/";
401 if( !
BuildPath( newPath, env, path ).IsOK() )
403 log->
Error(
AppMsg,
"Invalid arguments. Invalid path." );
411 log->
Debug(
AppMsg,
"Attempting to stat: %s", newPath.c_str() );
415 std::unique_ptr<StatInfo> ptr( info );
434 std::cout << newPath << std::endl;
442 log->
Debug(
AppMsg,
"Attempting to list: %s", newPath.c_str() );
445 st = fs->
DirList( newPath, flags, list );
454 std::cerr <<
"[!] Some of the requests failed. The result may be ";
455 std::cerr <<
"incomplete." << std::endl;
458 uint32_t ownerwidth = 0, groupwidth = 0, sizewidth = 0, ckswidth = 0;
460 for( it = list->
Begin(); it != list->
End() && stats; ++it )
462 StatInfo *info = (*it)->GetStatInfo();
463 if( ownerwidth < info->GetOwner().size() )
464 ownerwidth = info->
GetOwner().size();
465 if( groupwidth < info->GetGroup().size() )
466 groupwidth = info->
GetGroup().size();
469 if( ckswidth < info->GetChecksum().size() )
476 for( it = list->
Begin(); it != list->
End(); ++it )
480 StatInfo *info = (*it)->GetStatInfo();
482 std::cout <<
"---- 0000-00-00 00:00:00 ? ";
487 std::cout <<
"root://" << (*it)->GetHostAddress() <<
"/";
488 std::cout << list->
GetParentName() << (*it)->GetName() << std::endl;
505 uint32_t argc = args.size();
507 if( argc < 2 || argc > 4 )
515 std::string modeStr =
"rwxr-x---";
516 std::string path =
"";
518 for( uint32_t i = 1; i < args.size(); ++i )
520 if( args[i] ==
"-p" )
522 else if( !args[i].compare( 0, 2,
"-m" ) )
523 modeStr = args[i].substr( 2, 9 );
536 if( !
BuildPath( newPath, env, path ).IsOK() )
545 st = fs->
MkDir( newPath, flags, mode );
548 log->
Error(
AppMsg,
"Unable create directory %s: %s",
550 st.
ToStr().c_str() );
568 uint32_t argc = args.size();
572 log->
Error(
AppMsg,
"Wrong number of arguments." );
576 std::string fullPath;
577 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
589 log->
Error(
AppMsg,
"Unable remove directory %s: %s",
591 st.
ToStr().c_str() );
609 uint32_t argc = args.size();
613 log->
Error(
AppMsg,
"Wrong number of arguments." );
617 std::string fullPath1;
618 if( !
BuildPath( fullPath1, env, args[1] ).IsOK() )
624 std::string fullPath2;
625 if( !
BuildPath( fullPath2, env, args[2] ).IsOK() )
633 "cannot move directory to a subdirectory of itself." );
642 fullPath1.c_str(), fullPath2.c_str(),
643 st.
ToStr().c_str() );
661 uint32_t argc = args.size();
665 log->
Error(
AppMsg,
"Wrong number of arguments." );
671 void print(
const std::string &msg )
673 std::unique_lock<std::mutex> lck( mtx );
674 std::cout << msg <<
'\n';
678 std::shared_ptr<print_t> print;
680 print = std::make_shared<print_t>();
682 std::vector<Pipeline> rms;
683 rms.reserve( argc - 1 );
684 for(
size_t i = 1; i < argc; ++i )
686 std::string fullPath;
687 if( !
BuildPath( fullPath, env, args[i] ).IsOK() )
689 log->
Error(
AppMsg,
"Invalid path: %s", fullPath.c_str() );
692 rms.emplace_back(
Rm( fs, fullPath ) >>
699 st.
ToStr().c_str() );
703 print->print(
"rm " + fullPath +
" : " + st.
ToString() );
713 const size_t rs = rms.size();
732 uint32_t argc = args.size();
736 log->
Error(
AppMsg,
"Wrong number of arguments." );
740 std::string fullPath;
741 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
748 uint64_t size = ::strtoll( args[2].c_str(), &result, 0 );
751 log->
Error(
AppMsg,
"Size parameter needs to be an integer" );
763 st.
ToStr().c_str() );
781 uint32_t argc = args.size();
785 log->
Error(
AppMsg,
"Wrong number of arguments." );
789 std::string fullPath;
790 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
807 st = fs->
ChMod( fullPath, mode );
810 log->
Error(
AppMsg,
"Unable change mode of %s: %s",
812 st.
ToStr().c_str() );
830 uint32_t argc = args.size();
834 log->
Error(
AppMsg,
"Wrong number of arguments." );
840 bool hasPath =
false;
841 bool doDeepLocate =
false;
842 for( uint32_t i = 1; i < argc; ++i )
844 if( args[i] ==
"-n" )
846 else if( args[i] ==
"-r" )
848 else if( args[i] ==
"-m" || args[i] ==
"-h" )
850 else if( args[i] ==
"-i" )
852 else if( args[i] ==
"-d" )
854 else if( args[i] ==
"-p" )
857 env->
PutInt(
"PreserveLocateTried", 0 );
866 log->
Error(
AppMsg,
"Invalid argument: %s.", args[i].c_str() );
871 std::string fullPath;
876 if( !
BuildPath( fullPath, env, path ).IsOK() )
891 st = fs->
Locate( fullPath, flags, info );
897 st.
ToStr().c_str() );
906 std::cerr <<
"[!] Some of the requests failed. The result may be ";
907 std::cerr <<
"incomplete." << std::endl;
911 for( it = info->
Begin(); it != info->
End(); ++it )
913 std::cout << it->GetAddress() <<
" ";
914 switch( it->GetType() )
917 std::cout <<
"Manager ";
920 std::cout <<
"ManagerPending ";
923 std::cout <<
"Server ";
926 std::cout <<
"ServerPending ";
929 std::cout <<
"Unknown ";
932 switch( it->GetAccessType() )
938 std::cout <<
"ReadWrite ";
941 std::cout <<
"Unknown ";
943 std::cout << std::endl;
960 bool isOrQuery =
false;
962 if( query.find(
'|' ) != std::string::npos )
967 std::vector<std::string> queryFlags;
976 std::map<std::string, StatInfo::Flags> flagMap;
986 std::vector<std::string>::iterator it;
987 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
988 if( flagMap.find( *it ) == flagMap.end() )
990 log->
Error(
AppMsg,
"Flag '%s' is not recognized.", it->c_str() );
999 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1005 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1026 uint32_t argc = args.size();
1030 log->
Error(
AppMsg,
"Wrong number of arguments." );
1034 std::vector<std::string> paths;
1037 for( uint32_t i = 1; i < args.size(); ++i )
1039 if( args[i] ==
"-q" )
1041 if( i < args.size()-1 )
1048 log->
Error(
AppMsg,
"Parameter '-q' requires an argument." );
1053 paths.emplace_back( args[i] );
1056 std::vector<XrdCl::Pipeline> stats;
1057 std::vector<std::tuple<std::future<StatInfo>, std::string>> results;
1058 for(
auto &path : paths )
1060 std::string fullPath;
1061 if( !
BuildPath( fullPath, env, path ).IsOK() )
1066 std::future<XrdCl::StatInfo> ftr;
1067 stats.emplace_back(
XrdCl::Stat( fs, fullPath ) >> ftr );
1068 results.emplace_back( std::move( ftr ), std::move( fullPath ) );
1080 for(
auto &tpl : results )
1082 auto &ftr = std::get<0>( tpl );
1083 auto &fullPath = std::get<1>( tpl );
1084 std::cout << std::endl;
1091 flags +=
"XBitSet|";
1097 flags +=
"Offline|";
1099 flags +=
"POSCPending|";
1101 flags +=
"IsReadable|";
1103 flags +=
"IsWritable|";
1105 flags +=
"BackUpExists|";
1107 if( !flags.empty() )
1108 flags.erase( flags.length()-1, 1 );
1110 std::cout <<
"Path: " << fullPath << std::endl;
1111 std::cout <<
"Id: " << info.
GetId() << std::endl;
1112 std::cout <<
"Size: " << info.
GetSize() << std::endl;
1121 std::cout <<
"Flags: " << info.
GetFlags() <<
" (" << flags <<
")";
1127 std::cout <<
"Owner: " << info.
GetOwner() << std::endl;
1128 std::cout <<
"Group: " << info.
GetGroup();
1131 std::cout << std::endl;
1133 if( query.length() != 0 )
1138 std::cout <<
"Query: " << query <<
" " << std::endl;
1144 log->
Error(
AppMsg,
"Unable stat %s: %s", fullPath.c_str(), st.
ToStr().c_str() );
1162 uint32_t argc = args.size();
1166 log->
Error(
AppMsg,
"Wrong number of arguments." );
1170 std::string fullPath;
1171 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
1187 st.
ToStr().c_str() );
1194 std::cout <<
"Path: ";
1195 std::cout << fullPath << std::endl;
1196 std::cout <<
"Nodes with RW space: ";
1197 std::cout << info->
GetNodesRW() << std::endl;
1198 std::cout <<
"Size of largest RW space (MB): ";
1199 std::cout << info->
GetFreeRW() << std::endl;
1200 std::cout <<
"Utilization of RW space (%): ";
1202 std::cout <<
"Nodes with staging space: ";
1204 std::cout <<
"Size of largest staging space (MB): ";
1206 std::cout <<
"Utilization of staging space (%): ";
1224 uint32_t argc = args.size();
1226 if( !( argc >= 3 ) )
1228 log->
Error(
AppMsg,
"Wrong number of arguments." );
1233 if( args[1] ==
"config" )
1235 else if( args[1] ==
"checksumcancel" )
1237 else if( args[1] ==
"checksum" )
1239 else if( args[1] ==
"opaque" )
1241 else if( args[1] ==
"opaquefile" )
1243 else if( args[1] ==
"prepare" )
1245 else if( args[1] ==
"space" )
1247 else if( args[1] ==
"stats" )
1249 else if( args[1] ==
"xattr" )
1259 log->
Error(
AppMsg,
"Wrong number of arguments." );
1263 std::string strArg = args[2];
1268 for(
size_t i = 3; i < args.size(); ++i )
1270 std::string path = args[i];
1271 if( !
BuildPath( path, env, path ).IsOK() )
1283 std::string strArg = args[2];
1288 if( !
BuildPath( strArg, env, args[2] ).IsOK() )
1299 Buffer arg( strArg.size() );
1308 st.
ToStr().c_str() );
1315 std::cout << response->
ToString() << std::endl;
1331 uint32_t argc = args.size();
1335 log->
Error(
AppMsg,
"Wrong number of arguments." );
1340 std::vector<std::string> files;
1341 uint8_t priority = 0;
1344 for( uint32_t i = 1; i < args.size(); ++i )
1346 if( args[i] ==
"-p" )
1348 if( i < args.size()-1 )
1351 int32_t param = ::strtol( args[i+1].c_str(), &result, 0 );
1352 if( *result != 0 || param > 3 || param < 0 )
1354 log->
Error(
AppMsg,
"Size priotiry needs to be an integer between 0 "
1358 priority = (uint8_t)param;
1363 log->
Error(
AppMsg,
"Parameter '-p' requires an argument." );
1367 else if( args[i] ==
"-c" )
1369 else if( args[i] ==
"-f" )
1371 else if( args[i] ==
"-s" )
1373 else if( args[i] ==
"-w" )
1375 else if( args[i] ==
"-e" )
1377 else if( args[i] ==
"-a" )
1380 if( i < args.size()-1 )
1384 files.push_back( args[i+1] );
1389 log->
Error(
AppMsg,
"Parameter '-a' requires an argument." );
1394 files.push_back( args[i] );
1416 std::cout << response->
ToString() <<
'\n';
1440 JobProgress( jobNum, pBytesProcessed, pBytesTotal );
1441 std::cerr << std::endl;
1448 uint64_t bytesProcessed,
1449 uint64_t bytesTotal )
1451 pBytesProcessed = bytesProcessed;
1452 pBytesTotal = bytesTotal;
1454 time_t now = time(0);
1455 if( (now - pPrevious < 1) && (bytesProcessed != bytesTotal) )
1460 std::cerr <<
"Progress: ";
1464 std::cerr <<
"(" << bytesProcessed*100/bytesTotal <<
"%)";
1466 std::cerr << std::flush;
1470 uint64_t pBytesProcessed;
1471 uint64_t pBytesTotal;
1486 uint32_t argc = args.size();
1490 log->
Error(
AppMsg,
"Wrong number of arguments." );
1496 if( server.empty() )
1498 log->
Error(
AppMsg,
"Invalid address: \"%s\".", server.c_str() );
1502 std::vector<std::string> remotes;
1505 for( uint32_t i = 1; i < args.size(); ++i )
1507 if( args[i] ==
"-o" )
1509 if( i < args.size()-1 )
1516 log->
Error(
AppMsg,
"Parameter '-o' requires an argument." );
1521 remotes.emplace_back( args[i] );
1524 if( !local.empty() && remotes.size() > 1 )
1526 log->
Error(
AppMsg,
"If '-o' is used only can be used with only one remote file." );
1530 std::vector<URL> remoteUrls;
1531 remoteUrls.reserve( remotes.size() );
1532 for(
auto &remote : remotes )
1534 std::string remoteFile;
1535 if( !
BuildPath( remoteFile, env, remote ).IsOK() )
1541 remoteUrls.emplace_back( server );
1542 remoteUrls.back().SetPath( remoteFile );
1550 std::vector<PropertyList> props( remoteUrls.size() ), results( remoteUrls.size() );
1552 for(
size_t i = 0; i < remoteUrls.size(); ++i )
1554 props[i].Set(
"source", remoteUrls[i].GetURL() );
1555 if( !local.empty() )
1557 props[i].Set(
"target", std::string(
"file://" ) + local );
1561 props[i].Set(
"target",
"stdio://-" );
1563 props[i].Set(
"dynamicSource",
true );
1580 st = process.
Run(handler);
1601 uint32_t argc = args.size();
1603 if( argc < 2 || argc > 5 )
1605 log->
Error(
AppMsg,
"Wrong number of arguments." );
1611 if( server.empty() )
1613 log->
Error(
AppMsg,
"Invalid address: \"%s\".", server.c_str() );
1618 bool followMode =
false;
1619 uint32_t offset = 512;
1621 for( uint32_t i = 1; i < args.size(); ++i )
1623 if( args[i] ==
"-f" )
1625 else if( args[i] ==
"-c" )
1627 if( i < args.size()-1 )
1630 offset = ::strtol( args[i+1].c_str(), &result, 0 );
1633 log->
Error(
AppMsg,
"Offset from the end needs to be a number: %s",
1634 args[i+1].c_str() );
1641 log->
Error(
AppMsg,
"Parameter '-n' requires an argument." );
1649 std::string remoteFile;
1650 if( !
BuildPath( remoteFile, env, remote ).IsOK() )
1656 URL remoteUrl( server );
1657 remoteUrl.
SetPath( remoteFile );
1673 st = file.
Stat(
false, info );
1679 offset = size - offset;
1681 uint32_t chunkSize = 1*1024*1024;
1682 char *buffer =
new char[chunkSize];
1683 uint32_t bytesRead = 0;
1686 st = file.
Read( offset, chunkSize, buffer, bytesRead );
1695 offset += bytesRead;
1696 int ret =
write( 1, buffer, bytesRead );
1699 log->
Error(
AppMsg,
"Unable to write to stdout: %s",
1705 if( bytesRead < chunkSize )
1726 using namespace XrdCl;
1732 uint32_t argc = args.size();
1736 log->
Error(
AppMsg,
"Wrong number of arguments." );
1748 std::cerr <<
"[!] Some of the requests failed. The result may be ";
1749 std::cerr <<
"incomplete." << std::endl;
1752 std::cout <<
"Path: " << args[1] << std::endl;
1753 std::cout <<
"Total: " << i->
GetTotal() << std::endl;
1754 std::cout <<
"Free: " << i->
GetFree() << std::endl;
1755 std::cout <<
"Used: " << i->
GetUsed() << std::endl;
1773 uint32_t argc = args.size();
1777 log->
Error(
AppMsg,
"Wrong number of arguments." );
1782 if( args[2] ==
"set")
1784 else if( args[2] ==
"get" )
1786 else if( args[2] ==
"del" )
1788 else if( args[2] ==
"list" )
1797 if( !
BuildPath( path, env, args[1] ).IsOK() )
1813 log->
Error(
AppMsg,
"Wrong number of arguments." );
1817 std::string key_value = args[3];
1818 size_t pos = key_value.find(
'=' );
1819 std::string key = key_value.substr( 0, pos );
1820 std::string
value = key_value.substr( pos + 1 );
1821 std::vector<xattr_t> attrs;
1822 attrs.push_back( std::make_tuple( key,
value ) );
1824 std::vector<XAttrStatus> result;
1831 if( !status.
IsOK() )
1832 log->
Error(
AppMsg,
"Unable to xattr set %s %s: %s",
1833 key.c_str(),
value.c_str(),
1834 status.
ToStr().c_str() );
1842 log->
Error(
AppMsg,
"Wrong number of arguments." );
1846 std::string key = args[3];
1847 std::vector<std::string> attrs;
1848 attrs.push_back( key );
1850 std::vector<XAttr> result;
1852 XAttr xattr = status.
IsOK() ? result.front() :
XAttr( key, status );
1857 if( !status.
IsOK() )
1858 log->
Error(
AppMsg,
"Unable to xattr get %s : %s",
1860 status.
ToStr().c_str() );
1863 std::cout <<
"# file: " << path <<
'\n';
1864 std::cout << xattr.
name <<
"=\"" << xattr.
value <<
"\"\n";
1874 log->
Error(
AppMsg,
"Wrong number of arguments." );
1878 std::string key = args[3];
1879 std::vector<std::string> attrs;
1880 attrs.push_back( key );
1882 std::vector<XAttrStatus> result ;
1889 if( !status.
IsOK() )
1890 log->
Error(
AppMsg,
"Unable to xattr del %s : %s",
1892 status.
ToStr().c_str() );
1900 log->
Error(
AppMsg,
"Wrong number of arguments." );
1904 std::vector<XAttr> result;
1907 if( !status.
IsOK() )
1909 status.
ToStr().c_str() );
1912 std::cout <<
"# file: " << path <<
'\n';
1913 auto itr = result.begin();
1914 for( ; itr != result.end(); ++itr )
1915 std::cout << itr->name <<
"=\"" << itr->value <<
"\"\n";
1932 printf(
"Usage:\n" );
1933 printf(
" xrdfs [--no-cwd] host[:port] - interactive mode\n" );
1934 printf(
" xrdfs host[:port] command args - batch mode\n\n" );
1936 printf(
"Available options:\n\n" );
1938 printf(
" --no-cwd no CWD is being preset\n\n" );
1940 printf(
"Available commands:\n\n" );
1942 printf(
" exit\n" );
1943 printf(
" Exits from the program.\n\n" );
1945 printf(
" help\n" );
1946 printf(
" This help screen.\n\n" );
1948 printf(
" cache {evict | fevict} <path>\n" );
1949 printf(
" Evict a file from a cache if not in use; while fevict\n" );
1950 printf(
" forcibly evicts the file causing any current uses of the\n" );
1951 printf(
" file to get read failures on a subsequent read\n\n" );
1953 printf(
" cd <path>\n" );
1954 printf(
" Change the current working directory\n\n" );
1956 printf(
" chmod <path> <user><group><other>\n" );
1957 printf(
" Modify permissions. Permission string example:\n" );
1958 printf(
" rwxr-x--x\n\n" );
1960 printf(
" ls [-l] [-u] [-R] [-D] [-Z] [-C] [dirname]\n" );
1961 printf(
" Get directory listing.\n" );
1962 printf(
" -l stat every entry and print long listing\n" );
1963 printf(
" -u print paths as URLs\n" );
1964 printf(
" -R list subdirectories recursively\n" );
1965 printf(
" -D show duplicate entries" );
1966 printf(
" -Z if a ZIP archive list its content\n" );
1967 printf(
" -C checksum every entry\n\n" );
1969 printf(
" locate [-n] [-r] [-d] [-m] [-i] [-p] <path>\n" );
1970 printf(
" Get the locations of the path.\n" );
1971 printf(
" -r refresh, don't use cached locations\n" );
1972 printf(
" -n make the server return the response immediately even\n" );
1973 printf(
" though it may be incomplete\n" );
1974 printf(
" -d do a recursive (deep) locate\n" );
1975 printf(
" -m|-h prefer host names to IP addresses\n" );
1976 printf(
" -i ignore network dependencies\n" );
1977 printf(
" -p be passive: ignore tried/triedrc cgi opaque info\n\n" );
1979 printf(
" mkdir [-p] [-m<user><group><other>] <dirname>\n" );
1980 printf(
" Creates a directory/tree of directories.\n\n" );
1982 printf(
" mv <path1> <path2>\n" );
1983 printf(
" Move path1 to path2 locally on the same server.\n\n" );
1985 printf(
" stat [-q query] <path>\n" );
1986 printf(
" Get info about the file or directory.\n" );
1987 printf(
" -q query optional flag query parameter that makes\n" );
1988 printf(
" xrdfs return error code to the shell if the\n" );
1989 printf(
" requested flag combination is not present;\n" );
1990 printf(
" flags may be combined together using '|' or '&'\n" );
1991 printf(
" Available flags:\n" );
1992 printf(
" XBitSet, IsDir, Other, Offline, POSCPending,\n" );
1993 printf(
" IsReadable, IsWritable\n\n" );
1995 printf(
" statvfs <path>\n" );
1996 printf(
" Get info about a virtual file system.\n\n" );
1998 printf(
" query <code> <parameters>\n" );
1999 printf(
" Obtain server information. Query codes:\n\n" );
2001 printf(
" config <what> Server configuration; <what> is\n" );
2002 printf(
" one of the following:\n" );
2003 printf(
" bind_max - the maximum number of parallel streams\n" );
2004 printf(
" chksum - the supported checksum\n" );
2005 printf(
" cms - the status of the cmsd\n" );
2006 printf(
" pio_max - maximum number of parallel I/O requests\n" );
2007 printf(
" readv_ior_max - maximum size of a readv element\n" );
2008 printf(
" readv_iov_max - maximum number of readv entries\n" );
2009 printf(
" role - the role in a cluster\n" );
2010 printf(
" sitename - the site name\n" );
2011 printf(
" tpc - support for third party copies\n" );
2012 printf(
" version - the version of the server\n" );
2013 printf(
" wan_port - the port to use for wan copies\n" );
2014 printf(
" wan_window - the wan_port window size\n" );
2015 printf(
" window - the tcp window size\n" );
2016 printf(
" checksumcancel <path> File checksum cancellation\n" );
2017 printf(
" checksum <path> File checksum\n" );
2018 printf(
" opaque <arg> Implementation dependent\n" );
2019 printf(
" opaquefile <arg> Implementation dependent\n" );
2020 printf(
" space <space> Logical space stats\n" );
2021 printf(
" stats <what> Server stats; <what> is a list\n" );
2022 printf(
" of letters indicating information\n");
2023 printf(
" to be returned:\n" );
2024 printf(
" a - all statistics\n" );
2025 printf(
" p - protocol statistics\n" );
2026 printf(
" b - buffer usage statistics\n" );
2027 printf(
" s - scheduling statistics\n" );
2028 printf(
" d - device polling statistics\n" );
2029 printf(
" u - usage statistics\n" );
2030 printf(
" i - server identification\n" );
2031 printf(
" z - synchronized statistics\n" );
2032 printf(
" l - connection statistics\n" );
2033 printf(
" xattr <path> Extended attributes\n" );
2034 printf(
" prepare <reqid> [filenames] Prepare request status\n\n" );
2036 printf(
" rm <filename>\n" );
2037 printf(
" Remove a file.\n\n" );
2039 printf(
" rmdir <dirname>\n" );
2040 printf(
" Remove a directory.\n\n" );
2042 printf(
" truncate <filename> <length>\n" );
2043 printf(
" Truncate a file.\n\n" );
2045 printf(
" prepare [-c] [-f] [-s] [-w] [-e] [-p priority] [-a requestid] filenames\n" );
2046 printf(
" Prepare one or more files for access.\n" );
2047 printf(
" -c co-locate staged files if possible\n" );
2048 printf(
" -f refresh file access time even if the location is known\n" );
2049 printf(
" -s stage the files to disk if they are not online\n" );
2050 printf(
" -w the files will be accessed for modification\n" );
2051 printf(
" -p priority of the request, 0 (lowest) - 3 (highest)\n" );
2052 printf(
" -a abort stage request\n" );
2053 printf(
" -e evict the file from disk cache\n\n" );
2055 printf(
" cat [-o local file] files\n" );
2056 printf(
" Print contents of one or more files to stdout.\n" );
2057 printf(
" -o print to the specified local file\n\n" );
2059 printf(
" tail [-c bytes] [-f] file\n" );
2060 printf(
" Output last part of files to stdout.\n" );
2061 printf(
" -c num_bytes out last num_bytes\n" );
2062 printf(
" -f output appended data as file grows\n\n" );
2064 printf(
" spaceinfo path\n" );
2065 printf(
" Get space statistics for given path.\n\n" );
2067 printf(
" xattr <path> <code> <params> \n" );
2068 printf(
" Operation on extended attributes. Codes:\n\n" );
2069 printf(
" set <attr> Set extended attribute; <attr> is\n" );
2070 printf(
" string of form name=value\n" );
2071 printf(
" get <name> Get extended attribute\n" );
2072 printf(
" del <name> Delete extended attribute\n" );
2073 printf(
" list List extended attributes\n\n" );
2114 std::vector<std::string> args;
2116 for (
int i = 0; i < argc; ++i)
2118 args.push_back(argv[i]);
2122 std::cerr << st.
ToStr() << std::endl;
2129#ifndef HAVE_READLINE
2132 std::cout << prompt << std::flush;
2134 std::getline( std::cin, input );
2136 if( !std::cin.good() )
2139 char *linebuf = (
char *)malloc( input.size()+1 );
2140 strncpy( linebuf, input.c_str(), input.size()+1 );
2171 std::ostringstream prompt;
2172 std::string cwd =
"/";
2174 prompt <<
"[" << url.
GetHostId() <<
"] " << cwd <<
" > ";
2175 return prompt.str();
2185bool getArguments (std::vector<std::string> & result,
const std::string &input)
2188 static const char delimiter =
' ';
2190 const char singleQuote =
'\'', doubleQuote =
'\"';
2194 char currentQuote =
'\0';
2197 for (std::string::const_iterator it = input.begin (); it != input.end (); ++it)
2200 if (*it == singleQuote || *it == doubleQuote)
2209 else if (currentQuote == *it)
2211 currentQuote =
'\0';
2216 if (currentQuote || *it != delimiter)
2226 result.push_back(tmp);
2234 result.push_back(tmp);
2237 return currentQuote ==
'\0';
2248 std::string historyFile = getenv(
"HOME" );
2249 historyFile +=
"/.xrdquery.history";
2260 std::string cmdline;
2268 if( !linebuf || !strncmp( linebuf,
"exit", 4 ) || !strncmp( linebuf,
"quit", 4 ) )
2270 std::cout <<
"Goodbye." << std::endl << std::endl;
2278 std::vector<std::string> args;
2287 std::cerr << st.
ToStr() << std::endl;
2307 std::string commandline;
2308 for(
int i = 0; i < argc; ++i )
2310 commandline += argv[i];
2336 if( !strcmp( argv[1],
"--help" ) ||
2337 !strcmp( argv[1],
"-h" ) )
2345 if( !strcmp( argv[1],
"--no-cwd") )
2351 URL url( argv[urlIndex] );
2358 if( argc == urlIndex + 1 )
2360 int shift = urlIndex + 1;
uint32_t nbDigits(uint64_t nb)
XRootDStatus DoQuery(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus DoLocate(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
int write_history(const char *)
XRootDStatus DoMkDir(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
void add_history(const char *)
XRootDStatus DoRmDir(FileSystem *query, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus DoRm(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus DoTail(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
int ExecuteInteractive(const URL &url, bool noCwd=false)
int main(int argc, char **argv)
void rl_bind_key(char, uint16_t)
XRootDStatus DoStat(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus ProcessStatQuery(StatInfo &info, const std::string &query)
XRootDStatus DoCat(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
std::string BuildPrompt(Env *env, const URL &url)
XRootDStatus DoMv(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus DoPrepare(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
int ExecuteCommand(FSExecutor *ex, int argc, char **argv)
XRootDStatus DoChMod(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
void PrintDirListStatInfo(StatInfo *info, bool hascks=false, uint32_t ownerwidth=0, uint32_t groupwidth=0, uint32_t sizewidth=0)
FSExecutor * CreateExecutor(const URL &url)
XRootDStatus DoLS(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
bool getArguments(std::vector< std::string > &result, const std::string &input)
XRootDStatus DoCD(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus DoXAttr(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
char * readline(const char *prompt)
XRootDStatus DoStatVFS(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus DoCache(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus DoSpaceInfo(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus BuildPath(std::string &newPath, Env *env, const std::string &path)
int read_history(const char *)
XRootDStatus ConvertMode(Access::Mode &mode, const std::string &modeStr)
XRootDStatus DoTruncate(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus PrintHelp(FileSystem *, Env *, const FSExecutor::CommandParams &)
static bool is_subdirectory(const std::string &dir, const std::string &subdir)
const char * XrdSysE2T(int errcode)
virtual void EndJob(uint16_t jobNum, const XrdCl::PropertyList *results)
virtual void JobProgress(uint16_t jobNum, uint64_t bytesProcessed, uint64_t bytesTotal)
Job progress.
Binary blob representation.
void FromString(const std::string str)
Fill the buffer from a string.
std::string ToString() const
Convert the buffer to a string.
Copy the data from one point to another.
XRootDStatus Run(CopyProgressHandler *handler)
Run the copy jobs.
XRootDStatus AddJob(const PropertyList &properties, PropertyList *results)
Interface for copy progress notification.
static Log * GetLog()
Get default log.
static Env * GetEnv()
Get default client environment.
const std::string & GetParentName() const
Get parent directory name.
DirList::iterator Iterator
Directory listing iterator.
Iterator End()
Get the end iterator.
Iterator Begin()
Get the begin iterator.
bool PutInt(const std::string &key, int value)
bool PutString(const std::string &key, const std::string &value)
bool GetString(const std::string &key, std::string &value)
bool GetInt(const std::string &key, int &value)
Execute queries given as a commandline.
std::vector< std::string > CommandParams
Definition of command argument list.
XRootDStatus Execute(const CommandParams &args)
bool AddCommand(const std::string &name, Command command)
Env * GetEnv()
Get the environment.
Container for space information.
uint64_t GetUsed() const
Amount of used space in MB.
uint64_t GetLargestFreeChunk() const
Largest single chunk of free space.
uint64_t GetTotal() const
Amount of total space in MB.
uint64_t GetFree() const
Amount of free space in MB.
static XRootDStatus GetSpaceInfo(SpaceInfo *&result, FileSystem *fs, const std::string &path)
Recursively get space information for given path.
Send file/filesystem queries to an XRootD cluster.
XRootDStatus SetXAttr(const std::string &path, const std::vector< xattr_t > &attrs, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus RmDir(const std::string &path, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus DirList(const std::string &path, DirListFlags::Flags flags, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Mv(const std::string &source, const std::string &dest, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Query(QueryCode::Code queryCode, const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Locate(const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Stat(const std::string &path, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Prepare(const std::vector< std::string > &fileList, PrepareFlags::Flags flags, uint8_t priority, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus ChMod(const std::string &path, Access::Mode mode, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus DelXAttr(const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus ListXAttr(const std::string &path, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus DeepLocate(const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus SendCache(const std::string &info, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus GetXAttr(const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Truncate(const std::string &path, uint64_t size, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
bool GetProperty(const std::string &name, std::string &value) const
XRootDStatus MkDir(const std::string &path, MkDirFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus StatVFS(const std::string &path, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Close(ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Stat(bool force, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Iterator Begin()
Get the location begin iterator.
@ Read
read access is allowed
@ ReadWrite
write access is allowed
@ ServerPending
server node where the file is pending to be online
@ ManagerOnline
manager node where the file is online
@ ServerOnline
server node where the file is online
@ ManagerPending
manager node where the file is pending to be online
LocationList::iterator Iterator
Iterator over locations.
Iterator End()
Get the location end iterator.
void Error(uint64_t topic, const char *format,...)
Report an error.
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Pipeline exception, wrapps an XRootDStatus.
const XRootDStatus & GetError() const
A key-value pair map storing both keys and values as strings.
uint64_t GetFreeRW() const
Get size of the largest contiguous area of free r/w space (in MB)
uint64_t GetNodesStaging() const
Get number of nodes that can provide staging space.
uint8_t GetUtilizationStaging() const
Get percentage of the partition utilization represented by FreeStaging.
uint64_t GetFreeStaging() const
Get size of the largest contiguous area of free staging space (in MB)
uint8_t GetUtilizationRW() const
Get percentage of the partition utilization represented by FreeRW.
uint64_t GetNodesRW() const
Get number of nodes that can provide read/write space.
std::string GetChangeTimeAsString() const
Get change time.
std::string GetModTimeAsString() const
Get modification time.
bool HasChecksum() const
Has checksum.
bool TestFlags(uint32_t flags) const
Test flags.
uint64_t GetSize() const
Get size (in bytes)
const std::string GetModeAsOctString() const
Get mode.
const std::string & GetOwner() const
Get owner.
@ IsReadable
Read access is allowed.
@ IsDir
This is a directory.
@ Other
Neither a file nor a directory.
@ BackUpExists
Back up copy exists.
@ XBitSet
Executable/searchable bit set.
@ Offline
File is not online (ie. on disk)
@ IsWritable
Write access is allowed.
uint32_t GetFlags() const
Get flags.
bool ExtendedFormat() const
Has extended stat information.
const std::string & GetModeAsString() const
Get mode.
const std::string & GetId() const
Get id.
const std::string & GetGroup() const
Get group.
std::string GetAccessTimeAsString() const
Get change time.
const std::string & GetChecksum() const
Get checksum.
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
std::string GetURL() const
Get the URL.
std::string GetObfuscatedURL() const
Get the URL with authz information obfuscated.
void SetPath(const std::string &path)
Set the path.
bool IsValid() const
Is the url valid.
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
static std::string BytesToString(uint64_t bytes)
Convert bytes to a human readable string.
std::string ToStr() const
Convert to string.
const uint16_t errInvalidAddr
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errResponseNegative
Query response was negative.
StatImpl< false > Stat(Ctx< File > file, Arg< bool > force, uint16_t timeout=0)
XRootDStatus WaitFor(Pipeline pipeline, uint16_t timeout=0)
const uint16_t errInvalidArgs
std::future< XRootDStatus > Async(Pipeline pipeline, uint16_t timeout=0)
ParallelOperation< false > Parallel(Container &&container)
Factory function for creating parallel operation from a vector.
Response NullRef< Response >::value
@ OX
world executable/browsable
@ GX
group executable/browsable
@ UX
owner executable/browsable
@ Zip
List content of ZIP files.
@ Recursive
Do a recursive listing.
@ Cksm
Get checksum for every entry.
@ MakePath
create the entire directory tree if it doesn't exist
Flags
Open flags, may be or'd when appropriate.
@ Read
Open only for reading.
@ Cancel
cancel staging request
@ Colocate
co-locate staged files, if possible
Code
XRootD query request codes.
@ OpaqueFile
Implementation dependent.
@ XAttr
Query file extended attributes.
@ Opaque
Implementation dependent.
@ Config
Query server configuration.
@ Stats
Query server stats.
@ ChecksumCancel
Query file checksum cancellation.
@ Checksum
Query file checksum.
@ Space
Query logical space stats.
@ Prepare
Query prepare status.
uint16_t code
Error type, or additional hints on what to do.
bool IsOK() const
We're fine.
std::string ToString() const
Create a string representation.
int GetShellCode() const
Get the status code that may be returned to the shell.
Extended attribute operation status.
Extended attributes with status.