47 #include <readline/readline.h>
48 #include <readline/history.h>
51 using namespace XrdCl;
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);
284 std::string
getSizeStr(uint64_t size,
bool human, uint64_t base) {
285 std::ostringstream oss;
294 void PrintDirListStatInfo(
StatInfo *info,
bool hascks =
false, uint32_t ownerwidth = 0, uint32_t groupwidth = 0, uint32_t sizewidth = 0,
bool human =
false, uint64_t base = 1000 )
304 std::cout <<
" " << std::setw( ownerwidth ) << info->
GetOwner();
305 std::cout <<
" " << std::setw( groupwidth ) << info->
GetGroup();
306 std::cout <<
" " << std::setw( sizewidth ) <<
getSizeStr(info->
GetSize(),human, base);
308 std::cout <<
" " << std::setw( sizewidth ) << info->
GetChecksum();
335 uint64_t size = info->
GetSize();
336 std::string displaySize =
getSizeStr(size,human,base);
337 int width = displaySize.size() + 2;
341 std::cout << std::setw( width ) << displaySize <<
" ";
356 uint32_t argc = args.size();
358 bool showUrls =
false;
361 uint64_t base = 1024;
371 for( uint32_t i = 1; i < args.size(); ++i )
373 if( args[i] ==
"-l" )
378 else if( args[i] ==
"-u" )
380 else if( args[i] ==
"-R" )
384 else if( args[i] ==
"-D" )
389 else if( args[i] ==
"-Z" )
394 else if( args[i] ==
"-C" )
401 else if ( args [i] ==
"-h" )
414 std::string newPath =
"/";
419 if( !
BuildPath( newPath, env, path ).IsOK() )
421 log->
Error(
AppMsg,
"Invalid arguments. Invalid path." );
429 log->
Debug(
AppMsg,
"Attempting to stat: %s", newPath.c_str() );
433 std::unique_ptr<StatInfo> ptr( info );
452 std::cout << newPath << std::endl;
460 log->
Debug(
AppMsg,
"Attempting to list: %s", newPath.c_str() );
463 st = fs->
DirList( newPath, flags, list );
472 std::cerr <<
"[!] Some of the requests failed. The result may be ";
473 std::cerr <<
"incomplete." << std::endl;
476 uint32_t ownerwidth = 0, groupwidth = 0, sizewidth = 0, ckswidth = 0;
478 for( it = list->
Begin(); it != list->
End() && stats; ++it )
480 StatInfo *info = (*it)->GetStatInfo();
483 uint32_t sizeWidthComp;
485 sizeWidthComp = size.size();
490 if( ownerwidth < info->GetOwner().size() )
491 ownerwidth = info->
GetOwner().size();
492 if( groupwidth < info->GetGroup().size() )
493 groupwidth = info->
GetGroup().size();
494 if( sizewidth < sizeWidthComp )
495 sizewidth = sizeWidthComp;
496 if( ckswidth < info->GetChecksum().size() )
503 for( it = list->
Begin(); it != list->
End(); ++it )
507 StatInfo *info = (*it)->GetStatInfo();
509 std::cout <<
"---- 0000-00-00 00:00:00 ? ";
514 std::cout <<
"root://" << (*it)->GetHostAddress() <<
"/";
515 std::cout << list->
GetParentName() << (*it)->GetName() << std::endl;
532 uint32_t argc = args.size();
534 if( argc < 2 || argc > 4 )
542 std::string modeStr =
"rwxr-x---";
543 std::string path =
"";
545 for( uint32_t i = 1; i < args.size(); ++i )
547 if( args[i] ==
"-p" )
549 else if( !args[i].compare( 0, 2,
"-m" ) )
550 modeStr = args[i].substr( 2, 9 );
563 if( !
BuildPath( newPath, env, path ).IsOK() )
572 st = fs->
MkDir( newPath, flags, mode );
575 log->
Error(
AppMsg,
"Unable create directory %s: %s",
577 st.
ToStr().c_str() );
595 uint32_t argc = args.size();
599 log->
Error(
AppMsg,
"Wrong number of arguments." );
603 std::string fullPath;
604 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
616 log->
Error(
AppMsg,
"Unable remove directory %s: %s",
618 st.
ToStr().c_str() );
636 uint32_t argc = args.size();
640 log->
Error(
AppMsg,
"Wrong number of arguments." );
644 std::string fullPath1;
645 if( !
BuildPath( fullPath1, env, args[1] ).IsOK() )
651 std::string fullPath2;
652 if( !
BuildPath( fullPath2, env, args[2] ).IsOK() )
660 "cannot move directory to a subdirectory of itself." );
669 fullPath1.c_str(), fullPath2.c_str(),
670 st.
ToStr().c_str() );
688 uint32_t argc = args.size();
692 log->
Error(
AppMsg,
"Wrong number of arguments." );
698 void print(
const std::string &msg )
700 std::unique_lock<std::mutex> lck( mtx );
701 std::cout << msg <<
'\n';
705 std::shared_ptr<print_t> print;
707 print = std::make_shared<print_t>();
709 std::vector<Pipeline> rms;
710 rms.reserve( argc - 1 );
711 for(
size_t i = 1; i < argc; ++i )
713 std::string fullPath;
714 if( !
BuildPath( fullPath, env, args[i] ).IsOK() )
716 log->
Error(
AppMsg,
"Invalid path: %s", fullPath.c_str() );
719 rms.emplace_back(
Rm( fs, fullPath ) >>
724 log->Error( AppMsg,
"Unable remove %s: %s",
726 st.ToStr().c_str() );
730 print->print(
"rm " + fullPath +
" : " + st.ToString() );
740 const size_t rs = rms.size();
759 uint32_t argc = args.size();
763 log->
Error(
AppMsg,
"Wrong number of arguments." );
767 std::string fullPath;
768 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
775 uint64_t size = ::strtoll( args[2].c_str(), &result, 0 );
778 log->
Error(
AppMsg,
"Size parameter needs to be an integer" );
790 st.
ToStr().c_str() );
808 uint32_t argc = args.size();
812 log->
Error(
AppMsg,
"Wrong number of arguments." );
816 std::string fullPath;
817 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
834 st = fs->
ChMod( fullPath, mode );
837 log->
Error(
AppMsg,
"Unable change mode of %s: %s",
839 st.
ToStr().c_str() );
857 uint32_t argc = args.size();
861 log->
Error(
AppMsg,
"Wrong number of arguments." );
867 bool hasPath =
false;
868 bool doDeepLocate =
false;
869 for( uint32_t i = 1; i < argc; ++i )
871 if( args[i] ==
"-n" )
873 else if( args[i] ==
"-r" )
875 else if( args[i] ==
"-m" || args[i] ==
"-h" )
877 else if( args[i] ==
"-i" )
879 else if( args[i] ==
"-d" )
881 else if( args[i] ==
"-p" )
884 env->
PutInt(
"PreserveLocateTried", 0 );
893 log->
Error(
AppMsg,
"Invalid argument: %s.", args[i].c_str() );
898 std::string fullPath;
903 if( !
BuildPath( fullPath, env, path ).IsOK() )
918 st = fs->
Locate( fullPath, flags, info );
924 st.
ToStr().c_str() );
933 std::cerr <<
"[!] Some of the requests failed. The result may be ";
934 std::cerr <<
"incomplete." << std::endl;
938 for( it = info->
Begin(); it != info->
End(); ++it )
940 std::cout << it->GetAddress() <<
" ";
941 switch( it->GetType() )
944 std::cout <<
"Manager ";
947 std::cout <<
"ManagerPending ";
950 std::cout <<
"Server ";
953 std::cout <<
"ServerPending ";
956 std::cout <<
"Unknown ";
959 switch( it->GetAccessType() )
965 std::cout <<
"ReadWrite ";
968 std::cout <<
"Unknown ";
970 std::cout << std::endl;
987 bool isOrQuery =
false;
989 if( query.find(
'|' ) != std::string::npos )
994 std::vector<std::string> queryFlags;
1003 std::map<std::string, StatInfo::Flags> flagMap;
1013 std::vector<std::string>::iterator it;
1014 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1015 if( flagMap.find( *it ) == flagMap.end() )
1017 log->
Error(
AppMsg,
"Flag '%s' is not recognized.", it->c_str() );
1026 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1032 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1053 uint32_t argc = args.size();
1057 log->
Error(
AppMsg,
"Wrong number of arguments." );
1061 std::vector<std::string> paths;
1064 for( uint32_t i = 1; i < args.size(); ++i )
1066 if( args[i] ==
"-q" )
1068 if( i < args.size()-1 )
1075 log->
Error(
AppMsg,
"Parameter '-q' requires an argument." );
1080 paths.emplace_back( args[i] );
1083 std::vector<XrdCl::Pipeline> stats;
1084 std::vector<std::tuple<std::future<StatInfo>, std::string>> results;
1085 for(
auto &path : paths )
1087 std::string fullPath;
1088 if( !
BuildPath( fullPath, env, path ).IsOK() )
1093 std::future<XrdCl::StatInfo> ftr;
1094 stats.emplace_back(
XrdCl::Stat( fs, fullPath ) >> ftr );
1095 results.emplace_back( std::move( ftr ), std::move( fullPath ) );
1107 for(
auto &tpl : results )
1109 auto &ftr = std::get<0>( tpl );
1110 auto &fullPath = std::get<1>( tpl );
1111 std::cout << std::endl;
1118 flags +=
"XBitSet|";
1124 flags +=
"Offline|";
1126 flags +=
"POSCPending|";
1128 flags +=
"IsReadable|";
1130 flags +=
"IsWritable|";
1132 flags +=
"BackUpExists|";
1134 if( !flags.empty() )
1135 flags.erase( flags.length()-1, 1 );
1137 std::cout <<
"Path: " << fullPath << std::endl;
1138 std::cout <<
"Id: " << info.
GetId() << std::endl;
1139 std::cout <<
"Size: " << info.
GetSize() << std::endl;
1148 std::cout <<
"Flags: " << info.
GetFlags() <<
" (" << flags <<
")";
1154 std::cout <<
"Owner: " << info.
GetOwner() << std::endl;
1155 std::cout <<
"Group: " << info.
GetGroup();
1158 std::cout << std::endl;
1160 if( query.length() != 0 )
1165 std::cout <<
"Query: " << query <<
" " << std::endl;
1171 log->
Error(
AppMsg,
"Unable stat %s: %s", fullPath.c_str(), st.
ToStr().c_str() );
1189 uint32_t argc = args.size();
1193 log->
Error(
AppMsg,
"Wrong number of arguments." );
1197 std::string fullPath;
1198 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
1214 st.
ToStr().c_str() );
1221 std::cout <<
"Path: ";
1222 std::cout << fullPath << std::endl;
1223 std::cout <<
"Nodes with RW space: ";
1224 std::cout << info->
GetNodesRW() << std::endl;
1225 std::cout <<
"Size of largest RW space (MB): ";
1226 std::cout << info->
GetFreeRW() << std::endl;
1227 std::cout <<
"Utilization of RW space (%): ";
1229 std::cout <<
"Nodes with staging space: ";
1231 std::cout <<
"Size of largest staging space (MB): ";
1233 std::cout <<
"Utilization of staging space (%): ";
1251 uint32_t argc = args.size();
1253 if( !( argc >= 3 ) )
1255 log->
Error(
AppMsg,
"Wrong number of arguments." );
1260 if( args[1] ==
"config" )
1262 else if( args[1] ==
"checksumcancel" )
1264 else if( args[1] ==
"checksum" )
1266 else if( args[1] ==
"opaque" )
1268 else if( args[1] ==
"opaquefile" )
1270 else if( args[1] ==
"prepare" )
1272 else if( args[1] ==
"space" )
1274 else if( args[1] ==
"stats" )
1276 else if( args[1] ==
"xattr" )
1286 log->
Error(
AppMsg,
"Wrong number of arguments." );
1290 std::string strArg = args[2];
1295 for(
size_t i = 3; i < args.size(); ++i )
1297 std::string path = args[i];
1298 if( !
BuildPath( path, env, path ).IsOK() )
1310 std::string strArg = args[2];
1315 if( !
BuildPath( strArg, env, args[2] ).IsOK() )
1326 Buffer arg( strArg.size() );
1335 st.
ToStr().c_str() );
1342 std::cout << response->
ToString() << std::endl;
1358 uint32_t argc = args.size();
1362 log->
Error(
AppMsg,
"Wrong number of arguments." );
1367 std::vector<std::string> files;
1368 uint8_t priority = 0;
1371 for( uint32_t i = 1; i < args.size(); ++i )
1373 if( args[i] ==
"-p" )
1375 if( i < args.size()-1 )
1378 int32_t param = ::strtol( args[i+1].c_str(), &result, 0 );
1379 if( *result != 0 || param > 3 || param < 0 )
1381 log->
Error(
AppMsg,
"Size priotiry needs to be an integer between 0 "
1385 priority = (uint8_t)param;
1390 log->
Error(
AppMsg,
"Parameter '-p' requires an argument." );
1394 else if( args[i] ==
"-c" )
1396 else if( args[i] ==
"-f" )
1398 else if( args[i] ==
"-s" )
1400 else if( args[i] ==
"-w" )
1402 else if( args[i] ==
"-e" )
1404 else if( args[i] ==
"-a" )
1407 if( i < args.size()-1 )
1411 files.push_back( args[i+1] );
1416 log->
Error(
AppMsg,
"Parameter '-a' requires an argument." );
1421 files.push_back( args[i] );
1443 std::cout << response->
ToString() <<
'\n';
1467 JobProgress( jobNum, pBytesProcessed, pBytesTotal );
1468 std::cerr << std::endl;
1475 uint64_t bytesProcessed,
1476 uint64_t bytesTotal )
1478 pBytesProcessed = bytesProcessed;
1479 pBytesTotal = bytesTotal;
1481 time_t now = time(0);
1482 if( (now - pPrevious < 1) && (bytesProcessed != bytesTotal) )
1487 std::cerr <<
"Progress: ";
1491 std::cerr <<
"(" << bytesProcessed*100/bytesTotal <<
"%)";
1493 std::cerr << std::flush;
1497 uint64_t pBytesProcessed;
1498 uint64_t pBytesTotal;
1513 uint32_t argc = args.size();
1517 log->
Error(
AppMsg,
"Wrong number of arguments." );
1523 if( server.empty() )
1525 log->
Error(
AppMsg,
"Invalid address: \"%s\".", server.c_str() );
1529 std::vector<std::string> remotes;
1532 for( uint32_t i = 1; i < args.size(); ++i )
1534 if( args[i] ==
"-o" )
1536 if( i < args.size()-1 )
1543 log->
Error(
AppMsg,
"Parameter '-o' requires an argument." );
1548 remotes.emplace_back( args[i] );
1551 if( !local.empty() && remotes.size() > 1 )
1553 log->
Error(
AppMsg,
"If '-o' is used only can be used with only one remote file." );
1557 std::vector<URL> remoteUrls;
1558 remoteUrls.reserve( remotes.size() );
1559 for(
auto &remote : remotes )
1561 std::string remoteFile;
1562 if( !
BuildPath( remoteFile, env, remote ).IsOK() )
1568 remoteUrls.emplace_back( server );
1569 remoteUrls.back().SetPath( remoteFile );
1577 std::vector<PropertyList> props( remoteUrls.size() ), results( remoteUrls.size() );
1579 for(
size_t i = 0; i < remoteUrls.size(); ++i )
1581 props[i].Set(
"source", remoteUrls[i].GetURL() );
1582 if( !local.empty() )
1584 props[i].Set(
"target", std::string(
"file://" ) + local );
1588 props[i].Set(
"target",
"stdio://-" );
1590 props[i].Set(
"dynamicSource",
true );
1607 st = process.
Run(handler);
1628 uint32_t argc = args.size();
1630 if( argc < 2 || argc > 5 )
1632 log->
Error(
AppMsg,
"Wrong number of arguments." );
1638 if( server.empty() )
1640 log->
Error(
AppMsg,
"Invalid address: \"%s\".", server.c_str() );
1645 bool followMode =
false;
1646 uint32_t offset = 512;
1648 for( uint32_t i = 1; i < args.size(); ++i )
1650 if( args[i] ==
"-f" )
1652 else if( args[i] ==
"-c" )
1654 if( i < args.size()-1 )
1657 offset = ::strtol( args[i+1].c_str(), &result, 0 );
1660 log->
Error(
AppMsg,
"Offset from the end needs to be a number: %s",
1661 args[i+1].c_str() );
1668 log->
Error(
AppMsg,
"Parameter '-n' requires an argument." );
1676 std::string remoteFile;
1677 if( !
BuildPath( remoteFile, env, remote ).IsOK() )
1683 URL remoteUrl( server );
1684 remoteUrl.
SetPath( remoteFile );
1700 st = file.
Stat(
false, info );
1706 offset = size - offset;
1708 uint32_t chunkSize = 1*1024*1024;
1709 char *buffer =
new char[chunkSize];
1710 uint32_t bytesRead = 0;
1713 st = file.
Read( offset, chunkSize, buffer, bytesRead );
1722 offset += bytesRead;
1723 int ret =
write( 1, buffer, bytesRead );
1726 log->
Error(
AppMsg,
"Unable to write to stdout: %s",
1732 if( bytesRead < chunkSize )
1753 using namespace XrdCl;
1759 uint32_t argc = args.size();
1763 log->
Error(
AppMsg,
"Wrong number of arguments." );
1775 std::cerr <<
"[!] Some of the requests failed. The result may be ";
1776 std::cerr <<
"incomplete." << std::endl;
1779 std::cout <<
"Path: " << args[1] << std::endl;
1780 std::cout <<
"Total: " << i->
GetTotal() << std::endl;
1781 std::cout <<
"Free: " << i->
GetFree() << std::endl;
1782 std::cout <<
"Used: " << i->
GetUsed() << std::endl;
1800 uint32_t argc = args.size();
1804 log->
Error(
AppMsg,
"Wrong number of arguments." );
1809 if( args[2] ==
"set")
1811 else if( args[2] ==
"get" )
1813 else if( args[2] ==
"del" )
1815 else if( args[2] ==
"list" )
1824 if( !
BuildPath( path, env, args[1] ).IsOK() )
1840 log->
Error(
AppMsg,
"Wrong number of arguments." );
1844 std::string key_value = args[3];
1845 size_t pos = key_value.find(
'=' );
1846 std::string key = key_value.substr( 0, pos );
1847 std::string value = key_value.substr( pos + 1 );
1848 std::vector<xattr_t> attrs;
1849 attrs.push_back( std::make_tuple( key, value ) );
1851 std::vector<XAttrStatus> result;
1858 if( !status.
IsOK() )
1859 log->
Error(
AppMsg,
"Unable to xattr set %s %s: %s",
1860 key.c_str(), value.c_str(),
1861 status.
ToStr().c_str() );
1869 log->
Error(
AppMsg,
"Wrong number of arguments." );
1873 std::string key = args[3];
1874 std::vector<std::string> attrs;
1875 attrs.push_back( key );
1877 std::vector<XAttr> result;
1879 XAttr xattr = status.
IsOK() ? result.front() :
XAttr( key, status );
1884 if( !status.
IsOK() )
1885 log->
Error(
AppMsg,
"Unable to xattr get %s : %s",
1887 status.
ToStr().c_str() );
1890 std::cout <<
"# file: " << path <<
'\n';
1891 std::cout << xattr.
name <<
"=\"" << xattr.
value <<
"\"\n";
1901 log->
Error(
AppMsg,
"Wrong number of arguments." );
1905 std::string key = args[3];
1906 std::vector<std::string> attrs;
1907 attrs.push_back( key );
1909 std::vector<XAttrStatus> result ;
1916 if( !status.
IsOK() )
1917 log->
Error(
AppMsg,
"Unable to xattr del %s : %s",
1919 status.
ToStr().c_str() );
1927 log->
Error(
AppMsg,
"Wrong number of arguments." );
1931 std::vector<XAttr> result;
1934 if( !status.
IsOK() )
1936 status.
ToStr().c_str() );
1939 std::cout <<
"# file: " << path <<
'\n';
1940 auto itr = result.begin();
1941 for( ; itr != result.end(); ++itr )
1942 std::cout << itr->name <<
"=\"" << itr->value <<
"\"\n";
1959 printf(
"Usage:\n" );
1960 printf(
" xrdfs [--no-cwd] host[:port] - interactive mode\n" );
1961 printf(
" xrdfs host[:port] command args - batch mode\n\n" );
1963 printf(
"Available options:\n\n" );
1965 printf(
" --no-cwd no CWD is being preset\n\n" );
1967 printf(
"Available commands:\n\n" );
1969 printf(
" exit\n" );
1970 printf(
" Exits from the program.\n\n" );
1972 printf(
" help\n" );
1973 printf(
" This help screen.\n\n" );
1975 printf(
" cache {evict | fevict} <path>\n" );
1976 printf(
" Evict a file from a cache if not in use; while fevict\n" );
1977 printf(
" forcibly evicts the file causing any current uses of the\n" );
1978 printf(
" file to get read failures on a subsequent read\n\n" );
1980 printf(
" cd <path>\n" );
1981 printf(
" Change the current working directory\n\n" );
1983 printf(
" chmod <path> <user><group><other>\n" );
1984 printf(
" Modify permissions. Permission string example:\n" );
1985 printf(
" rwxr-x--x\n\n" );
1987 printf(
" ls [-l] [-u] [-R] [-D] [-Z] [-C] [dirname]\n" );
1988 printf(
" Get directory listing.\n" );
1989 printf(
" -l stat every entry and print long listing\n" );
1990 printf(
" -u print paths as URLs\n" );
1991 printf(
" -R list subdirectories recursively\n" );
1992 printf(
" -D show duplicate entries\n" );
1993 printf(
" -Z if a ZIP archive list its content\n" );
1994 printf(
" -C checksum every entry\n\n" );
1996 printf(
" locate [-n] [-r] [-d] [-m] [-i] [-p] <path>\n" );
1997 printf(
" Get the locations of the path.\n" );
1998 printf(
" -r refresh, don't use cached locations\n" );
1999 printf(
" -n make the server return the response immediately even\n" );
2000 printf(
" though it may be incomplete\n" );
2001 printf(
" -d do a recursive (deep) locate\n" );
2002 printf(
" -m|-h prefer host names to IP addresses\n" );
2003 printf(
" -i ignore network dependencies\n" );
2004 printf(
" -p be passive: ignore tried/triedrc cgi opaque info\n\n" );
2006 printf(
" mkdir [-p] [-m<user><group><other>] <dirname>\n" );
2007 printf(
" Creates a directory/tree of directories.\n\n" );
2009 printf(
" mv <path1> <path2>\n" );
2010 printf(
" Move path1 to path2 locally on the same server.\n\n" );
2012 printf(
" stat [-q query] <path>\n" );
2013 printf(
" Get info about the file or directory.\n" );
2014 printf(
" -q query optional flag query parameter that makes\n" );
2015 printf(
" xrdfs return error code to the shell if the\n" );
2016 printf(
" requested flag combination is not present;\n" );
2017 printf(
" flags may be combined together using '|' or '&'\n" );
2018 printf(
" Available flags:\n" );
2019 printf(
" XBitSet, IsDir, Other, Offline, POSCPending,\n" );
2020 printf(
" IsReadable, IsWritable\n\n" );
2022 printf(
" statvfs <path>\n" );
2023 printf(
" Get info about a virtual file system.\n\n" );
2025 printf(
" query <code> <parameters>\n" );
2026 printf(
" Obtain server information. Query codes:\n\n" );
2028 printf(
" config <what> Server configuration; <what> is\n" );
2029 printf(
" one of the following:\n" );
2030 printf(
" bind_max - the maximum number of parallel streams\n" );
2031 printf(
" chksum - the supported checksum\n" );
2032 printf(
" cms - the status of the cmsd\n" );
2033 printf(
" pio_max - maximum number of parallel I/O requests\n" );
2034 printf(
" readv_ior_max - maximum size of a readv element\n" );
2035 printf(
" readv_iov_max - maximum number of readv entries\n" );
2036 printf(
" role - the role in a cluster\n" );
2037 printf(
" sitename - the site name\n" );
2038 printf(
" tpc - support for third party copies\n" );
2039 printf(
" version - the version of the server\n" );
2040 printf(
" wan_port - the port to use for wan copies\n" );
2041 printf(
" wan_window - the wan_port window size\n" );
2042 printf(
" window - the tcp window size\n" );
2043 printf(
" checksumcancel <path> File checksum cancellation\n" );
2044 printf(
" checksum <path> File checksum\n" );
2045 printf(
" opaque <arg> Implementation dependent\n" );
2046 printf(
" opaquefile <arg> Implementation dependent\n" );
2047 printf(
" space <space> Logical space stats\n" );
2048 printf(
" stats <what> Server stats; <what> is a list\n" );
2049 printf(
" of letters indicating information\n");
2050 printf(
" to be returned:\n" );
2051 printf(
" a - all statistics\n" );
2052 printf(
" p - protocol statistics\n" );
2053 printf(
" b - buffer usage statistics\n" );
2054 printf(
" s - scheduling statistics\n" );
2055 printf(
" d - device polling statistics\n" );
2056 printf(
" u - usage statistics\n" );
2057 printf(
" i - server identification\n" );
2058 printf(
" z - synchronized statistics\n" );
2059 printf(
" l - connection statistics\n" );
2060 printf(
" xattr <path> Extended attributes\n" );
2061 printf(
" prepare <reqid> [filenames] Prepare request status\n\n" );
2063 printf(
" rm <filename>\n" );
2064 printf(
" Remove a file.\n\n" );
2066 printf(
" rmdir <dirname>\n" );
2067 printf(
" Remove a directory.\n\n" );
2069 printf(
" truncate <filename> <length>\n" );
2070 printf(
" Truncate a file.\n\n" );
2072 printf(
" prepare [-c] [-f] [-s] [-w] [-e] [-p priority] [-a requestid] filenames\n" );
2073 printf(
" Prepare one or more files for access.\n" );
2074 printf(
" -c co-locate staged files if possible\n" );
2075 printf(
" -f refresh file access time even if the location is known\n" );
2076 printf(
" -s stage the files to disk if they are not online\n" );
2077 printf(
" -w the files will be accessed for modification\n" );
2078 printf(
" -p priority of the request, 0 (lowest) - 3 (highest)\n" );
2079 printf(
" -a abort stage request\n" );
2080 printf(
" -e evict the file from disk cache\n\n" );
2082 printf(
" cat [-o local file] files\n" );
2083 printf(
" Print contents of one or more files to stdout.\n" );
2084 printf(
" -o print to the specified local file\n\n" );
2086 printf(
" tail [-c bytes] [-f] file\n" );
2087 printf(
" Output last part of files to stdout.\n" );
2088 printf(
" -c num_bytes out last num_bytes\n" );
2089 printf(
" -f output appended data as file grows\n\n" );
2091 printf(
" spaceinfo path\n" );
2092 printf(
" Get space statistics for given path.\n\n" );
2094 printf(
" xattr <path> <code> <params> \n" );
2095 printf(
" Operation on extended attributes. Codes:\n\n" );
2096 printf(
" set <attr> Set extended attribute; <attr> is\n" );
2097 printf(
" string of form name=value\n" );
2098 printf(
" get <name> Get extended attribute\n" );
2099 printf(
" del <name> Delete extended attribute\n" );
2100 printf(
" list List extended attributes\n\n" );
2141 std::vector<std::string> args;
2143 for (
int i = 0; i < argc; ++i)
2145 args.push_back(argv[i]);
2149 std::cerr << st.
ToStr() << std::endl;
2156 #ifndef HAVE_READLINE
2159 std::cout << prompt << std::flush;
2163 if( !std::cin.good() )
2166 char *linebuf = (
char *)malloc( input.size()+1 );
2167 strncpy( linebuf, input.c_str(), input.size()+1 );
2198 std::ostringstream prompt;
2199 std::string cwd =
"/";
2201 prompt <<
"[" << url.
GetHostId() <<
"] " << cwd <<
" > ";
2202 return prompt.str();
2212 bool getArguments (std::vector<std::string> & result,
const std::string &input)
2215 static const char delimiter =
' ';
2217 const char singleQuote =
'\'', doubleQuote =
'\"';
2221 char currentQuote =
'\0';
2224 for (std::string::const_iterator it = input.begin (); it != input.end (); ++it)
2227 if (*it == singleQuote || *it == doubleQuote)
2236 else if (currentQuote == *it)
2238 currentQuote =
'\0';
2243 if (currentQuote || *it != delimiter)
2253 result.push_back(tmp);
2261 result.push_back(tmp);
2264 return currentQuote ==
'\0';
2275 std::string historyFile = getenv(
"HOME" );
2276 historyFile +=
"/.xrdquery.history";
2287 std::string cmdline;
2295 if( !linebuf || !strncmp( linebuf,
"exit", 4 ) || !strncmp( linebuf,
"quit", 4 ) )
2297 std::cout <<
"Goodbye." << std::endl << std::endl;
2305 std::vector<std::string> args;
2314 std::cerr << st.
ToStr() << std::endl;
2334 std::string commandline;
2335 for(
int i = 0; i < argc; ++i )
2337 commandline += argv[i];
2363 if( !strcmp( argv[1],
"--help" ) ||
2364 !strcmp( argv[1],
"-h" ) )
2372 if( !strcmp( argv[1],
"--no-cwd") )
2378 URL url( argv[urlIndex] );
2385 if( argc == urlIndex + 1 )
2387 int shift = urlIndex + 1;
void PrintDirListStatInfo(StatInfo *info, bool hascks=false, uint32_t ownerwidth=0, uint32_t groupwidth=0, uint32_t sizewidth=0, bool human=false, uint64_t base=1000)
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)
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)
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)
FSExecutor * CreateExecutor(const URL &url)
int read_history(const char *)
char * readline(const char *prompt)
XRootDStatus ConvertMode(Access::Mode &mode, const std::string &modeStr)
std::string getSizeStr(uint64_t size, bool human, uint64_t base)
XRootDStatus DoTruncate(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus PrintHelp(FileSystem *, Env *, const FSExecutor::CommandParams &)
static bool is_subdirectory(const std::string_view dir, const std::string_view subdir)
void getline(uchar *buff, int blen)
const char * XrdSysE2T(int errcode)
virtual void EndJob(uint32_t jobNum, const XrdCl::PropertyList *results)
virtual void JobProgress(uint32_t jobNum, uint64_t bytesProcessed, uint64_t bytesTotal)
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.
DirList::iterator Iterator
Directory listing iterator.
Iterator End()
Get the end iterator.
Iterator Begin()
Get the begin iterator.
const std::string & GetParentName() const
Get parent directory name.
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.
Env * GetEnv()
Get the environment.
XRootDStatus Execute(const CommandParams &args)
bool AddCommand(const std::string &name, Command command)
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 Mv(const std::string &source, const std::string &dest, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus DirList(const std::string &path, DirListFlags::Flags flags, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Locate(const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus SendCache(const std::string &info, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Truncate(const std::string &path, uint64_t size, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus RmDir(const std::string &path, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus ListXAttr(const std::string &path, ResponseHandler *handler, time_t timeout=0)
XRootDStatus Stat(const std::string &path, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus StatVFS(const std::string &path, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus GetXAttr(const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
XRootDStatus ChMod(const std::string &path, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus DelXAttr(const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
XRootDStatus Prepare(const std::vector< std::string > &fileList, PrepareFlags::Flags flags, uint8_t priority, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus MkDir(const std::string &path, MkDirFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Query(QueryCode::Code queryCode, const Buffer &arg, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus SetXAttr(const std::string &path, const std::vector< xattr_t > &attrs, ResponseHandler *handler, time_t timeout=0)
bool GetProperty(const std::string &name, std::string &value) const
XRootDStatus DeepLocate(const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Close(ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Stat(bool force, ResponseHandler *handler, time_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.
static std::string genHumanSize(size_t size, uint64_t base)
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, time_t timeout=0)
std::future< XRootDStatus > Async(Pipeline pipeline, time_t timeout=0)
ParallelOperation< false > Parallel(Container &&container)
Factory function for creating parallel operation from a vector.
const uint16_t errInvalidArgs
XRootDStatus WaitFor(Pipeline pipeline, time_t timeout=0)
@ 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.
int GetShellCode() const
Get the status code that may be returned to the shell.
Extended attribute operation status.
Extended attributes with status.