46 #include <readline/readline.h>
47 #include <readline/history.h>
50 using namespace XrdCl;
56 const std::string &path )
62 env->
GetInt(
"NoCWD", noCwd );
64 if( path[0] ==
'/' || noCwd )
70 std::string cwd =
"/";
79 std::list<std::string> pathComponents;
80 std::list<std::string>::iterator it;
83 for( it = pathComponents.begin(); it != pathComponents.end(); )
87 it = pathComponents.erase( it );
93 if( it == pathComponents.begin() )
95 std::list<std::string>::iterator it1 = it;
97 it = pathComponents.erase( it1 );
98 it = pathComponents.erase( it );
105 for( it = pathComponents.begin(); it != pathComponents.end(); ++it )
110 if( newPath.length() > 1 )
111 newPath.erase( newPath.length()-1, 1 );
121 if( modeStr.length() != 9 )
125 for(
int i = 0; i < 3; ++i )
127 if( modeStr[i] ==
'r' )
129 else if( modeStr[i] ==
'w' )
131 else if( modeStr[i] ==
'x' )
133 else if( modeStr[i] !=
'-' )
136 for(
int i = 3; i < 6; ++i )
138 if( modeStr[i] ==
'r' )
140 else if( modeStr[i] ==
'w' )
142 else if( modeStr[i] ==
'x' )
144 else if( modeStr[i] !=
'-' )
147 for(
int i = 6; i < 9; ++i )
149 if( modeStr[i] ==
'r' )
151 else if( modeStr[i] ==
'w' )
153 else if( modeStr[i] ==
'x' )
155 else if( modeStr[i] !=
'-' )
172 uint32_t argc = args.size();
176 log->
Error(
AppMsg,
"Wrong number of arguments." );
178 "Wrong number of arguments." );
181 if( args[1] !=
"evict" && args[1] !=
"fevict")
187 std::string fullPath;
188 if( !
BuildPath( fullPath, env, args[2] ).IsOK() )
197 std::string cmd = args[1];
199 cmd.append(fullPath);
210 st.
ToStr().c_str() );
216 std::cout << response->
ToString() <<
'\n';
234 if( args.size() != 2 )
236 log->
Error(
AppMsg,
"Invalid arguments. Expected a path." );
243 env->
PutInt(
"NoCWD", 0 );
246 if( !
BuildPath( newPath, env, args[1] ).IsOK() )
265 log->
Error(
AppMsg,
"%s is not a directory.", newPath.c_str() );
279 if( nb == 0 )
return 1;
280 return uint32_t( log10(
double(nb) ) + 1);
294 std::cout <<
" " << std::setw( ownerwidth ) << info->
GetOwner();
295 std::cout <<
" " << std::setw( groupwidth ) << info->
GetGroup();
296 std::cout <<
" " << std::setw( sizewidth ) << info->
GetSize();
298 std::cout <<
" " << std::setw( sizewidth ) << info->
GetChecksum();
325 uint64_t size = info->
GetSize();
327 if( width < 12 ) width = 12;
328 std::cout << std::setw( width ) << info->
GetSize() <<
" ";
343 uint32_t argc = args.size();
345 bool showUrls =
false;
356 for( uint32_t i = 1; i < args.size(); ++i )
358 if( args[i] ==
"-l" )
363 else if( args[i] ==
"-u" )
365 else if( args[i] ==
"-R" )
369 else if( args[i] ==
"-D" )
374 else if( args[i] ==
"-Z" )
379 else if( args[i] ==
"-C" )
395 std::string newPath =
"/";
400 if( !
BuildPath( newPath, env, path ).IsOK() )
402 log->
Error(
AppMsg,
"Invalid arguments. Invalid path." );
410 log->
Debug(
AppMsg,
"Attempting to stat: %s", newPath.c_str() );
414 std::unique_ptr<StatInfo> ptr( info );
433 std::cout << newPath << std::endl;
441 log->
Debug(
AppMsg,
"Attempting to list: %s", newPath.c_str() );
444 st = fs->
DirList( newPath, flags, list );
453 std::cerr <<
"[!] Some of the requests failed. The result may be ";
454 std::cerr <<
"incomplete." << std::endl;
457 uint32_t ownerwidth = 0, groupwidth = 0, sizewidth = 0, ckswidth = 0;
459 for( it = list->
Begin(); it != list->
End() && stats; ++it )
461 StatInfo *info = (*it)->GetStatInfo();
462 if( ownerwidth < info->GetOwner().size() )
463 ownerwidth = info->
GetOwner().size();
464 if( groupwidth < info->GetGroup().size() )
465 groupwidth = info->
GetGroup().size();
468 if( ckswidth < info->GetChecksum().size() )
475 for( it = list->
Begin(); it != list->
End(); ++it )
479 StatInfo *info = (*it)->GetStatInfo();
481 std::cout <<
"---- 0000-00-00 00:00:00 ? ";
486 std::cout <<
"root://" << (*it)->GetHostAddress() <<
"/";
487 std::cout << list->
GetParentName() << (*it)->GetName() << std::endl;
504 uint32_t argc = args.size();
506 if( argc < 2 || argc > 4 )
514 std::string modeStr =
"rwxr-x---";
515 std::string path =
"";
517 for( uint32_t i = 1; i < args.size(); ++i )
519 if( args[i] ==
"-p" )
521 else if( !args[i].compare( 0, 2,
"-m" ) )
522 modeStr = args[i].substr( 2, 9 );
535 if( !
BuildPath( newPath, env, path ).IsOK() )
544 st = fs->
MkDir( newPath, flags, mode );
547 log->
Error(
AppMsg,
"Unable create directory %s: %s",
549 st.
ToStr().c_str() );
567 uint32_t argc = args.size();
571 log->
Error(
AppMsg,
"Wrong number of arguments." );
575 std::string fullPath;
576 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
588 log->
Error(
AppMsg,
"Unable remove directory %s: %s",
590 st.
ToStr().c_str() );
608 uint32_t argc = args.size();
612 log->
Error(
AppMsg,
"Wrong number of arguments." );
616 std::string fullPath1;
617 if( !
BuildPath( fullPath1, env, args[1] ).IsOK() )
623 std::string fullPath2;
624 if( !
BuildPath( fullPath2, env, args[2] ).IsOK() )
637 fullPath1.c_str(), fullPath2.c_str(),
638 st.
ToStr().c_str() );
656 uint32_t argc = args.size();
660 log->
Error(
AppMsg,
"Wrong number of arguments." );
666 void print(
const std::string &msg )
668 std::unique_lock<std::mutex> lck( mtx );
669 std::cout << msg <<
'\n';
673 std::shared_ptr<print_t> print;
675 print = std::make_shared<print_t>();
677 std::vector<Pipeline> rms;
678 rms.reserve( argc - 1 );
679 for(
size_t i = 1; i < argc; ++i )
681 std::string fullPath;
682 if( !
BuildPath( fullPath, env, args[i] ).IsOK() )
684 log->
Error(
AppMsg,
"Invalid path: %s", fullPath.c_str() );
687 rms.emplace_back(
Rm( fs, fullPath ) >>
692 log->Error( AppMsg,
"Unable remove %s: %s",
694 st.ToStr().c_str() );
698 print->print(
"rm " + fullPath +
" : " + st.ToString() );
708 const size_t rs = rms.size();
727 uint32_t argc = args.size();
731 log->
Error(
AppMsg,
"Wrong number of arguments." );
735 std::string fullPath;
736 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
743 uint64_t size = ::strtoll( args[2].c_str(), &result, 0 );
746 log->
Error(
AppMsg,
"Size parameter needs to be an integer" );
758 st.
ToStr().c_str() );
776 uint32_t argc = args.size();
780 log->
Error(
AppMsg,
"Wrong number of arguments." );
784 std::string fullPath;
785 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
802 st = fs->
ChMod( fullPath, mode );
805 log->
Error(
AppMsg,
"Unable change mode of %s: %s",
807 st.
ToStr().c_str() );
825 uint32_t argc = args.size();
829 log->
Error(
AppMsg,
"Wrong number of arguments." );
835 bool hasPath =
false;
836 bool doDeepLocate =
false;
837 for( uint32_t i = 1; i < argc; ++i )
839 if( args[i] ==
"-n" )
841 else if( args[i] ==
"-r" )
843 else if( args[i] ==
"-m" || args[i] ==
"-h" )
845 else if( args[i] ==
"-i" )
847 else if( args[i] ==
"-d" )
849 else if( args[i] ==
"-p" )
852 env->
PutInt(
"PreserveLocateTried", 0 );
861 log->
Error(
AppMsg,
"Invalid argument: %s.", args[i].c_str() );
866 std::string fullPath;
871 if( !
BuildPath( fullPath, env, path ).IsOK() )
886 st = fs->
Locate( fullPath, flags, info );
892 st.
ToStr().c_str() );
901 std::cerr <<
"[!] Some of the requests failed. The result may be ";
902 std::cerr <<
"incomplete." << std::endl;
906 for( it = info->
Begin(); it != info->
End(); ++it )
908 std::cout << it->GetAddress() <<
" ";
909 switch( it->GetType() )
912 std::cout <<
"Manager ";
915 std::cout <<
"ManagerPending ";
918 std::cout <<
"Server ";
921 std::cout <<
"ServerPending ";
924 std::cout <<
"Unknown ";
927 switch( it->GetAccessType() )
933 std::cout <<
"ReadWrite ";
936 std::cout <<
"Unknown ";
938 std::cout << std::endl;
955 bool isOrQuery =
false;
957 if( query.find(
'|' ) != std::string::npos )
962 std::vector<std::string> queryFlags;
971 std::map<std::string, StatInfo::Flags> flagMap;
981 std::vector<std::string>::iterator it;
982 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
983 if( flagMap.find( *it ) == flagMap.end() )
985 log->
Error(
AppMsg,
"Flag '%s' is not recognized.", it->c_str() );
994 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1000 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1021 uint32_t argc = args.size();
1025 log->
Error(
AppMsg,
"Wrong number of arguments." );
1029 std::vector<std::string> paths;
1032 for( uint32_t i = 1; i < args.size(); ++i )
1034 if( args[i] ==
"-q" )
1036 if( i < args.size()-1 )
1043 log->
Error(
AppMsg,
"Parameter '-q' requires an argument." );
1048 paths.emplace_back( args[i] );
1051 std::vector<XrdCl::Pipeline> stats;
1052 std::vector<std::tuple<std::future<StatInfo>, std::string>> results;
1053 for(
auto &path : paths )
1055 std::string fullPath;
1056 if( !
BuildPath( fullPath, env, path ).IsOK() )
1061 std::future<XrdCl::StatInfo> ftr;
1062 stats.emplace_back(
XrdCl::Stat( fs, fullPath ) >> ftr );
1063 results.emplace_back( std::move( ftr ), std::move( fullPath ) );
1075 for(
auto &tpl : results )
1077 auto &ftr = std::get<0>( tpl );
1078 auto &fullPath = std::get<1>( tpl );
1079 std::cout << std::endl;
1086 flags +=
"XBitSet|";
1092 flags +=
"Offline|";
1094 flags +=
"POSCPending|";
1096 flags +=
"IsReadable|";
1098 flags +=
"IsWritable|";
1100 flags +=
"BackUpExists|";
1102 if( !flags.empty() )
1103 flags.erase( flags.length()-1, 1 );
1105 std::cout <<
"Path: " << fullPath << std::endl;
1106 std::cout <<
"Id: " << info.
GetId() << std::endl;
1107 std::cout <<
"Size: " << info.
GetSize() << std::endl;
1116 std::cout <<
"Flags: " << info.
GetFlags() <<
" (" << flags <<
")";
1122 std::cout <<
"Owner: " << info.
GetOwner() << std::endl;
1123 std::cout <<
"Group: " << info.
GetGroup();
1126 std::cout << std::endl;
1128 if( query.length() != 0 )
1133 std::cout <<
"Query: " << query <<
" " << std::endl;
1139 log->
Error(
AppMsg,
"Unable stat %s: %s", fullPath.c_str(), st.
ToStr().c_str() );
1157 uint32_t argc = args.size();
1161 log->
Error(
AppMsg,
"Wrong number of arguments." );
1165 std::string fullPath;
1166 if( !
BuildPath( fullPath, env, args[1] ).IsOK() )
1182 st.
ToStr().c_str() );
1189 std::cout <<
"Path: ";
1190 std::cout << fullPath << std::endl;
1191 std::cout <<
"Nodes with RW space: ";
1192 std::cout << info->
GetNodesRW() << std::endl;
1193 std::cout <<
"Size of largest RW space (MB): ";
1194 std::cout << info->
GetFreeRW() << std::endl;
1195 std::cout <<
"Utilization of RW space (%): ";
1197 std::cout <<
"Nodes with staging space: ";
1199 std::cout <<
"Size of largest staging space (MB): ";
1201 std::cout <<
"Utilization of staging space (%): ";
1219 uint32_t argc = args.size();
1221 if( !( argc >= 3 ) )
1223 log->
Error(
AppMsg,
"Wrong number of arguments." );
1228 if( args[1] ==
"config" )
1230 else if( args[1] ==
"checksumcancel" )
1232 else if( args[1] ==
"checksum" )
1234 else if( args[1] ==
"opaque" )
1236 else if( args[1] ==
"opaquefile" )
1238 else if( args[1] ==
"prepare" )
1240 else if( args[1] ==
"space" )
1242 else if( args[1] ==
"stats" )
1244 else if( args[1] ==
"xattr" )
1254 log->
Error(
AppMsg,
"Wrong number of arguments." );
1258 std::string strArg = args[2];
1263 for(
size_t i = 3; i < args.size(); ++i )
1265 std::string path = args[i];
1266 if( !
BuildPath( path, env, path ).IsOK() )
1278 std::string strArg = args[2];
1283 if( !
BuildPath( strArg, env, args[2] ).IsOK() )
1294 Buffer arg( strArg.size() );
1303 st.
ToStr().c_str() );
1310 std::cout << response->
ToString() << std::endl;
1326 uint32_t argc = args.size();
1330 log->
Error(
AppMsg,
"Wrong number of arguments." );
1335 std::vector<std::string> files;
1336 uint8_t priority = 0;
1339 for( uint32_t i = 1; i < args.size(); ++i )
1341 if( args[i] ==
"-p" )
1343 if( i < args.size()-1 )
1346 int32_t param = ::strtol( args[i+1].c_str(), &result, 0 );
1347 if( *result != 0 || param > 3 || param < 0 )
1349 log->
Error(
AppMsg,
"Size priotiry needs to be an integer between 0 "
1353 priority = (uint8_t)param;
1358 log->
Error(
AppMsg,
"Parameter '-p' requires an argument." );
1362 else if( args[i] ==
"-c" )
1364 else if( args[i] ==
"-f" )
1366 else if( args[i] ==
"-s" )
1368 else if( args[i] ==
"-w" )
1370 else if( args[i] ==
"-e" )
1372 else if( args[i] ==
"-a" )
1375 if( i < args.size()-1 )
1379 files.push_back( args[i+1] );
1384 log->
Error(
AppMsg,
"Parameter '-a' requires an argument." );
1389 files.push_back( args[i] );
1411 std::cout << response->
ToString() <<
'\n';
1435 JobProgress( jobNum, pBytesProcessed, pBytesTotal );
1436 std::cerr << std::endl;
1443 uint64_t bytesProcessed,
1444 uint64_t bytesTotal )
1446 pBytesProcessed = bytesProcessed;
1447 pBytesTotal = bytesTotal;
1449 time_t now = time(0);
1450 if( (now - pPrevious < 1) && (bytesProcessed != bytesTotal) )
1455 std::cerr <<
"Progress: ";
1459 std::cerr <<
"(" << bytesProcessed*100/bytesTotal <<
"%)";
1461 std::cerr << std::flush;
1465 uint64_t pBytesProcessed;
1466 uint64_t pBytesTotal;
1481 uint32_t argc = args.size();
1485 log->
Error(
AppMsg,
"Wrong number of arguments." );
1491 if( server.empty() )
1493 log->
Error(
AppMsg,
"Invalid address: \"%s\".", server.c_str() );
1497 std::vector<std::string> remotes;
1500 for( uint32_t i = 1; i < args.size(); ++i )
1502 if( args[i] ==
"-o" )
1504 if( i < args.size()-1 )
1511 log->
Error(
AppMsg,
"Parameter '-o' requires an argument." );
1516 remotes.emplace_back( args[i] );
1519 if( !local.empty() && remotes.size() > 1 )
1521 log->
Error(
AppMsg,
"If '-o' is used only can be used with only one remote file." );
1525 std::vector<URL> remoteUrls;
1526 remoteUrls.reserve( remotes.size() );
1527 for(
auto &remote : remotes )
1529 std::string remoteFile;
1530 if( !
BuildPath( remoteFile, env, remote ).IsOK() )
1536 remoteUrls.emplace_back( server );
1537 remoteUrls.back().SetPath( remoteFile );
1545 std::vector<PropertyList> props( remoteUrls.size() ), results( remoteUrls.size() );
1547 for(
size_t i = 0; i < remoteUrls.size(); ++i )
1549 props[i].Set(
"source", remoteUrls[i].GetURL() );
1550 if( !local.empty() )
1552 props[i].Set(
"target", std::string(
"file://" ) + local );
1556 props[i].Set(
"target",
"stdio://-" );
1558 props[i].Set(
"dynamicSource",
true );
1575 st = process.
Run(handler);
1596 uint32_t argc = args.size();
1598 if( argc < 2 || argc > 5 )
1600 log->
Error(
AppMsg,
"Wrong number of arguments." );
1606 if( server.empty() )
1608 log->
Error(
AppMsg,
"Invalid address: \"%s\".", server.c_str() );
1613 bool followMode =
false;
1614 uint32_t offset = 512;
1616 for( uint32_t i = 1; i < args.size(); ++i )
1618 if( args[i] ==
"-f" )
1620 else if( args[i] ==
"-c" )
1622 if( i < args.size()-1 )
1625 offset = ::strtol( args[i+1].c_str(), &result, 0 );
1628 log->
Error(
AppMsg,
"Offset from the end needs to be a number: %s",
1629 args[i+1].c_str() );
1636 log->
Error(
AppMsg,
"Parameter '-n' requires an argument." );
1644 std::string remoteFile;
1645 if( !
BuildPath( remoteFile, env, remote ).IsOK() )
1651 URL remoteUrl( server );
1652 remoteUrl.
SetPath( remoteFile );
1668 st = file.
Stat(
false, info );
1674 offset = size - offset;
1676 uint32_t chunkSize = 1*1024*1024;
1677 char *buffer =
new char[chunkSize];
1678 uint32_t bytesRead = 0;
1681 st = file.
Read( offset, chunkSize, buffer, bytesRead );
1690 offset += bytesRead;
1691 int ret =
write( 1, buffer, bytesRead );
1694 log->
Error(
AppMsg,
"Unable to write to stdout: %s",
1700 if( bytesRead < chunkSize )
1721 using namespace XrdCl;
1727 uint32_t argc = args.size();
1731 log->
Error(
AppMsg,
"Wrong number of arguments." );
1743 std::cerr <<
"[!] Some of the requests failed. The result may be ";
1744 std::cerr <<
"incomplete." << std::endl;
1747 std::cout <<
"Path: " << args[1] << std::endl;
1748 std::cout <<
"Total: " << i->
GetTotal() << std::endl;
1749 std::cout <<
"Free: " << i->
GetFree() << std::endl;
1750 std::cout <<
"Used: " << i->
GetUsed() << std::endl;
1768 uint32_t argc = args.size();
1772 log->
Error(
AppMsg,
"Wrong number of arguments." );
1777 if( args[2] ==
"set")
1779 else if( args[2] ==
"get" )
1781 else if( args[2] ==
"del" )
1783 else if( args[2] ==
"list" )
1792 if( !
BuildPath( path, env, args[1] ).IsOK() )
1808 log->
Error(
AppMsg,
"Wrong number of arguments." );
1812 std::string key_value = args[3];
1813 size_t pos = key_value.find(
'=' );
1814 std::string key = key_value.substr( 0, pos );
1815 std::string value = key_value.substr( pos + 1 );
1816 std::vector<xattr_t> attrs;
1817 attrs.push_back( std::make_tuple( key, value ) );
1819 std::vector<XAttrStatus> result;
1826 if( !status.
IsOK() )
1827 log->
Error(
AppMsg,
"Unable to xattr set %s %s: %s",
1828 key.c_str(), value.c_str(),
1829 status.
ToStr().c_str() );
1837 log->
Error(
AppMsg,
"Wrong number of arguments." );
1841 std::string key = args[3];
1842 std::vector<std::string> attrs;
1843 attrs.push_back( key );
1845 std::vector<XAttr> result;
1847 XAttr xattr = status.
IsOK() ? result.front() :
XAttr( key, status );
1852 if( !status.
IsOK() )
1853 log->
Error(
AppMsg,
"Unable to xattr get %s : %s",
1855 status.
ToStr().c_str() );
1858 std::cout <<
"# file: " << path <<
'\n';
1859 std::cout << xattr.
name <<
"=\"" << xattr.
value <<
"\"\n";
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<XAttrStatus> result ;
1884 if( !status.
IsOK() )
1885 log->
Error(
AppMsg,
"Unable to xattr del %s : %s",
1887 status.
ToStr().c_str() );
1895 log->
Error(
AppMsg,
"Wrong number of arguments." );
1899 std::vector<XAttr> result;
1902 if( !status.
IsOK() )
1904 status.
ToStr().c_str() );
1907 std::cout <<
"# file: " << path <<
'\n';
1908 auto itr = result.begin();
1909 for( ; itr != result.end(); ++itr )
1910 std::cout << itr->name <<
"=\"" << itr->value <<
"\"\n";
1927 printf(
"Usage:\n" );
1928 printf(
" xrdfs [--no-cwd] host[:port] - interactive mode\n" );
1929 printf(
" xrdfs host[:port] command args - batch mode\n\n" );
1931 printf(
"Available options:\n\n" );
1933 printf(
" --no-cwd no CWD is being preset\n\n" );
1935 printf(
"Available commands:\n\n" );
1937 printf(
" exit\n" );
1938 printf(
" Exits from the program.\n\n" );
1940 printf(
" help\n" );
1941 printf(
" This help screen.\n\n" );
1943 printf(
" cache {evict | fevict} <path>\n" );
1944 printf(
" Evict a file from a cache if not in use; while fevict\n" );
1945 printf(
" forcibly evicts the file causing any current uses of the\n" );
1946 printf(
" file to get read failures on a subsequent read\n\n" );
1948 printf(
" cd <path>\n" );
1949 printf(
" Change the current working directory\n\n" );
1951 printf(
" chmod <path> <user><group><other>\n" );
1952 printf(
" Modify permissions. Permission string example:\n" );
1953 printf(
" rwxr-x--x\n\n" );
1955 printf(
" ls [-l] [-u] [-R] [-D] [-Z] [-C] [dirname]\n" );
1956 printf(
" Get directory listing.\n" );
1957 printf(
" -l stat every entry and print long listing\n" );
1958 printf(
" -u print paths as URLs\n" );
1959 printf(
" -R list subdirectories recursively\n" );
1960 printf(
" -D show duplicate entries" );
1961 printf(
" -Z if a ZIP archive list its content\n" );
1962 printf(
" -C checksum every entry\n\n" );
1964 printf(
" locate [-n] [-r] [-d] [-m] [-i] [-p] <path>\n" );
1965 printf(
" Get the locations of the path.\n" );
1966 printf(
" -r refresh, don't use cached locations\n" );
1967 printf(
" -n make the server return the response immediately even\n" );
1968 printf(
" though it may be incomplete\n" );
1969 printf(
" -d do a recursive (deep) locate\n" );
1970 printf(
" -m|-h prefer host names to IP addresses\n" );
1971 printf(
" -i ignore network dependencies\n" );
1972 printf(
" -p be passive: ignore tried/triedrc cgi opaque info\n\n" );
1974 printf(
" mkdir [-p] [-m<user><group><other>] <dirname>\n" );
1975 printf(
" Creates a directory/tree of directories.\n\n" );
1977 printf(
" mv <path1> <path2>\n" );
1978 printf(
" Move path1 to path2 locally on the same server.\n\n" );
1980 printf(
" stat [-q query] <path>\n" );
1981 printf(
" Get info about the file or directory.\n" );
1982 printf(
" -q query optional flag query parameter that makes\n" );
1983 printf(
" xrdfs return error code to the shell if the\n" );
1984 printf(
" requested flag combination is not present;\n" );
1985 printf(
" flags may be combined together using '|' or '&'\n" );
1986 printf(
" Available flags:\n" );
1987 printf(
" XBitSet, IsDir, Other, Offline, POSCPending,\n" );
1988 printf(
" IsReadable, IsWritable\n\n" );
1990 printf(
" statvfs <path>\n" );
1991 printf(
" Get info about a virtual file system.\n\n" );
1993 printf(
" query <code> <parameters>\n" );
1994 printf(
" Obtain server information. Query codes:\n\n" );
1996 printf(
" config <what> Server configuration; <what> is\n" );
1997 printf(
" one of the following:\n" );
1998 printf(
" bind_max - the maximum number of parallel streams\n" );
1999 printf(
" chksum - the supported checksum\n" );
2000 printf(
" cms - the status of the cmsd\n" );
2001 printf(
" pio_max - maximum number of parallel I/O requests\n" );
2002 printf(
" readv_ior_max - maximum size of a readv element\n" );
2003 printf(
" readv_iov_max - maximum number of readv entries\n" );
2004 printf(
" role - the role in a cluster\n" );
2005 printf(
" sitename - the site name\n" );
2006 printf(
" tpc - support for third party copies\n" );
2007 printf(
" version - the version of the server\n" );
2008 printf(
" wan_port - the port to use for wan copies\n" );
2009 printf(
" wan_window - the wan_port window size\n" );
2010 printf(
" window - the tcp window size\n" );
2011 printf(
" checksumcancel <path> File checksum cancellation\n" );
2012 printf(
" checksum <path> File checksum\n" );
2013 printf(
" opaque <arg> Implementation dependent\n" );
2014 printf(
" opaquefile <arg> Implementation dependent\n" );
2015 printf(
" space <space> Logical space stats\n" );
2016 printf(
" stats <what> Server stats; <what> is a list\n" );
2017 printf(
" of letters indicating information\n");
2018 printf(
" to be returned:\n" );
2019 printf(
" a - all statistics\n" );
2020 printf(
" p - protocol statistics\n" );
2021 printf(
" b - buffer usage statistics\n" );
2022 printf(
" s - scheduling statistics\n" );
2023 printf(
" d - device polling statistics\n" );
2024 printf(
" u - usage statistics\n" );
2025 printf(
" i - server identification\n" );
2026 printf(
" z - synchronized statistics\n" );
2027 printf(
" l - connection statistics\n" );
2028 printf(
" xattr <path> Extended attributes\n" );
2029 printf(
" prepare <reqid> [filenames] Prepare request status\n\n" );
2031 printf(
" rm <filename>\n" );
2032 printf(
" Remove a file.\n\n" );
2034 printf(
" rmdir <dirname>\n" );
2035 printf(
" Remove a directory.\n\n" );
2037 printf(
" truncate <filename> <length>\n" );
2038 printf(
" Truncate a file.\n\n" );
2040 printf(
" prepare [-c] [-f] [-s] [-w] [-e] [-p priority] [-a requestid] filenames\n" );
2041 printf(
" Prepare one or more files for access.\n" );
2042 printf(
" -c co-locate staged files if possible\n" );
2043 printf(
" -f refresh file access time even if the location is known\n" );
2044 printf(
" -s stage the files to disk if they are not online\n" );
2045 printf(
" -w the files will be accessed for modification\n" );
2046 printf(
" -p priority of the request, 0 (lowest) - 3 (highest)\n" );
2047 printf(
" -a abort stage request\n" );
2048 printf(
" -e evict the file from disk cache\n\n" );
2050 printf(
" cat [-o local file] files\n" );
2051 printf(
" Print contents of one or more files to stdout.\n" );
2052 printf(
" -o print to the specified local file\n\n" );
2054 printf(
" tail [-c bytes] [-f] file\n" );
2055 printf(
" Output last part of files to stdout.\n" );
2056 printf(
" -c num_bytes out last num_bytes\n" );
2057 printf(
" -f output appended data as file grows\n\n" );
2059 printf(
" spaceinfo path\n" );
2060 printf(
" Get space statistics for given path.\n\n" );
2062 printf(
" xattr <path> <code> <params> \n" );
2063 printf(
" Operation on extended attributes. Codes:\n\n" );
2064 printf(
" set <attr> Set extended attribute; <attr> is\n" );
2065 printf(
" string of form name=value\n" );
2066 printf(
" get <name> Get extended attribute\n" );
2067 printf(
" del <name> Delete extended attribute\n" );
2068 printf(
" list List extended attributes\n\n" );
2109 std::vector<std::string> args;
2111 for (
int i = 0; i < argc; ++i)
2113 args.push_back(argv[i]);
2117 std::cerr << st.
ToStr() << std::endl;
2124 #ifndef HAVE_READLINE
2127 std::cout << prompt << std::flush;
2131 if( !std::cin.good() )
2134 char *linebuf = (
char *)malloc( input.size()+1 );
2135 strncpy( linebuf, input.c_str(), input.size()+1 );
2166 std::ostringstream prompt;
2167 std::string cwd =
"/";
2169 prompt <<
"[" << url.
GetHostId() <<
"] " << cwd <<
" > ";
2170 return prompt.str();
2180 bool getArguments (std::vector<std::string> & result,
const std::string &input)
2183 static const char delimiter =
' ';
2185 const char singleQuote =
'\'', doubleQuote =
'\"';
2189 char currentQuote =
'\0';
2192 for (std::string::const_iterator it = input.begin (); it != input.end (); ++it)
2195 if (*it == singleQuote || *it == doubleQuote)
2204 else if (currentQuote == *it)
2206 currentQuote =
'\0';
2211 if (currentQuote || *it != delimiter)
2221 result.push_back(tmp);
2229 result.push_back(tmp);
2232 return currentQuote ==
'\0';
2243 std::string historyFile = getenv(
"HOME" );
2244 historyFile +=
"/.xrdquery.history";
2255 std::string cmdline;
2263 if( !linebuf || !strncmp( linebuf,
"exit", 4 ) || !strncmp( linebuf,
"quit", 4 ) )
2265 std::cout <<
"Goodbye." << std::endl << std::endl;
2273 std::vector<std::string> args;
2282 std::cerr << st.
ToStr() << std::endl;
2302 std::string commandline;
2303 for(
int i = 0; i < argc; ++i )
2305 commandline += argv[i];
2331 if( !strcmp( argv[1],
"--help" ) ||
2332 !strcmp( argv[1],
"-h" ) )
2340 if( !strcmp( argv[1],
"--no-cwd") )
2346 URL url( argv[urlIndex] );
2353 if( argc == urlIndex + 1 )
2355 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)
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)
XRootDStatus DoTruncate(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
XRootDStatus PrintHelp(FileSystem *, Env *, const FSExecutor::CommandParams &)
ssize_t write(int fildes, const void *buf, size_t nbyte)
void getline(uchar *buff, int blen)
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)
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 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
StatImpl< false > Stat(Ctx< File > file, Arg< bool > force, uint16_t timeout=0)
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errResponseNegative
Query response was negative.
std::future< XRootDStatus > Async(Pipeline pipeline, uint16_t timeout=0)
XRootDStatus WaitFor(Pipeline pipeline, uint16_t timeout=0)
ParallelOperation< false > Parallel(Container &&container)
Factory function for creating parallel operation from a vector.
const uint16_t errInvalidArgs
@ 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.