XRootD
XrdClFS.cc File Reference
#include "XProtocol/XProtocol.hh"
#include "XrdCl/XrdClConstants.hh"
#include "XrdCl/XrdClCopyProcess.hh"
#include "XrdCl/XrdClDefaultEnv.hh"
#include "XrdCl/XrdClFSExecutor.hh"
#include "XrdCl/XrdClFile.hh"
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClFileSystemOperations.hh"
#include "XrdCl/XrdClFileSystemUtils.hh"
#include "XrdCl/XrdClLog.hh"
#include "XrdCl/XrdClParallelOperation.hh"
#include "XrdCl/XrdClStatus.hh"
#include "XrdCl/XrdClURL.hh"
#include "XrdCl/XrdClUtils.hh"
#include "XrdCl/XrdClXRootDResponses.hh"
#include "XrdOuc/XrdOucPrivateUtils.hh"
#include "XrdSys/XrdSysE2T.hh"
#include <algorithm>
#include <cctype>
#include <getopt.h>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <memory>
#include <unistd.h>
+ Include dependency graph for XrdClFS.cc:

Go to the source code of this file.

Classes

class  ProgressDisplay
 

Functions

void add_history (const char *)
 
XRootDStatus BuildPath (std::string &newPath, Env *env, const std::string &path, const char *op=nullptr)
 
std::string BuildPrompt (Env *env, const URL &url)
 
XRootDStatus ConvertMode (Access::Mode &mode, const std::string &modeStr)
 
FSExecutor * CreateExecutor (const URL &url)
 
XRootDStatus DoCache (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoCat (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoCD (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoChMod (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoLocate (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoLS (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoMkDir (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoMv (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoPrepare (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoQuery (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoRm (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoRmDir (FileSystem *query, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoSpaceInfo (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoStat (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoStatVFS (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoTail (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoTruncate (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
XRootDStatus DoXAttr (FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
 
int ExecuteCommand (const URL &url, const FSExecutor::CommandParams &args)
 
int ExecuteCommand (FSExecutor *ex, const FSExecutor::CommandParams &args)
 
int ExecuteInteractive (const URL &url, bool noCwd=false)
 
bool getArguments (std::vector< std::string > &result, const std::string &input)
 
std::string getSizeStr (uint64_t size, bool human, uint64_t base)
 
int main (int argc, char **argv)
 
uint32_t nbDigits (uint64_t nb)
 
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)
 
XRootDStatus PrintHelp (FileSystem *, Env *, const FSExecutor::CommandParams &)
 
XRootDStatus ProcessStatQuery (StatInfo &info, const std::string &query)
 
int read_history (const char *)
 
char * readline (const char *prompt)
 
void rl_bind_key (char, uint16_t)
 
int write_history (const char *)
 

Variables

uint16_t rl_insert = 0
 

Function Documentation

◆ add_history()

void add_history ( const char *  )

Definition at line 2282 of file XrdClFS.cc.

2283 {
2284 }

Referenced by ExecuteInteractive().

+ Here is the caller graph for this function:

◆ BuildPath()

XRootDStatus BuildPath ( std::string &  newPath,
Env *  env,
const std::string &  path,
const char *  op = nullptr 
)

Definition at line 166 of file XrdClFS.cc.

169 {
170  Log *log = DefaultEnv::GetLog();
171 
172  if( path.empty() )
173  {
174  const std::string msg = "A path is required.";
175  log->Error( AppMsg, "%s", msg.c_str() );
176  return XRootDStatus( stError, errInvalidArgs, 0, msg );
177  }
178 
179  int noCwd = 0;
180  env->GetInt( "NoCWD", noCwd );
181 
182  if( path[0] == '/' )
183  {
184  newPath = path;
185  return XRootDStatus();
186  }
187  else if( noCwd )
188  {
189  std::string msg;
190  if( op )
191  msg = std::string( op ) + " relative path '" + path + "' is disallowed.";
192  else
193  msg = "Relative path '" + path + "' is disallowed.";
194  log->Error( AppMsg, "%s", msg.c_str() );
195  return XRootDStatus( stError, errInvalidArgs, 0, msg );
196  }
197 
198  std::string cwd = "/";
199  env->GetString( "CWD", cwd );
200  newPath = cwd;
201  newPath += "/";
202  newPath += path;
203 
204  //----------------------------------------------------------------------------
205  // Collapse the dots
206  //----------------------------------------------------------------------------
207  std::list<std::string> pathComponents;
208  std::list<std::string>::iterator it;
209  XrdCl::Utils::splitString( pathComponents, newPath, "/" );
210  newPath = "/";
211  for( it = pathComponents.begin(); it != pathComponents.end(); )
212  {
213  if( *it == "." )
214  {
215  it = pathComponents.erase( it );
216  continue;
217  }
218 
219  if( *it == ".." )
220  {
221  if( it == pathComponents.begin() )
222  {
223  const std::string msg = "Path '" + path + "' escapes above root.";
224  log->Error( AppMsg, "%s", msg.c_str() );
225  return XRootDStatus( stError, errInvalidArgs, 0, msg );
226  }
227  std::list<std::string>::iterator it1 = it;
228  --it1;
229  it = pathComponents.erase( it1 );
230  it = pathComponents.erase( it );
231  continue;
232  }
233  ++it;
234  }
235 
236  newPath = "/";
237  for( it = pathComponents.begin(); it != pathComponents.end(); ++it )
238  {
239  newPath += *it;
240  newPath += "/";
241  }
242  if( newPath.length() > 1 )
243  newPath.erase( newPath.length()-1, 1 );
244 
245  return XRootDStatus();
246 }
bool GetString(const std::string &key, std::string &value)
Definition: XrdClEnv.cc:31
bool GetInt(const std::string &key, int &value)
Definition: XrdClEnv.cc:115
Handle diagnostics.
Definition: XrdClLog.hh:101
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition: XrdClLog.cc:231
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
Definition: XrdClUtils.hh:56
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint64_t AppMsg
const uint16_t errInvalidArgs
Definition: XrdClStatus.hh:58

References XrdCl::AppMsg, XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::Env::GetInt(), XrdCl::DefaultEnv::GetLog(), XrdCl::Env::GetString(), XrdCl::Utils::splitString(), and XrdCl::stError.

Referenced by XrdOssArcConfig::Configure(), DoCache(), DoCat(), DoCD(), DoChMod(), DoLocate(), DoLS(), DoMkDir(), DoMv(), DoQuery(), DoRm(), DoRmDir(), DoStat(), DoStatVFS(), DoTail(), DoTruncate(), and DoXAttr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ BuildPrompt()

std::string BuildPrompt ( Env *  env,
const URL &  url 
)

Definition at line 2306 of file XrdClFS.cc.

2307 {
2308  std::ostringstream prompt;
2309  std::string cwd = "/";
2310  env->GetString( "CWD", cwd );
2311  prompt << "[" << url.GetHostId() << "] " << cwd << " > ";
2312  return prompt.str();
2313 }
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:99

References XrdCl::URL::GetHostId(), and XrdCl::Env::GetString().

Referenced by ExecuteInteractive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConvertMode()

XRootDStatus ConvertMode ( Access::Mode &  mode,
const std::string &  modeStr 
)

Definition at line 251 of file XrdClFS.cc.

252 {
253  if( modeStr.length() != 9 )
255 
256  mode = Access::None;
257  for( int i = 0; i < 3; ++i )
258  {
259  if( modeStr[i] == 'r' )
260  mode |= Access::UR;
261  else if( modeStr[i] == 'w' )
262  mode |= Access::UW;
263  else if( modeStr[i] == 'x' )
264  mode |= Access::UX;
265  else if( modeStr[i] != '-' )
267  }
268  for( int i = 3; i < 6; ++i )
269  {
270  if( modeStr[i] == 'r' )
271  mode |= Access::GR;
272  else if( modeStr[i] == 'w' )
273  mode |= Access::GW;
274  else if( modeStr[i] == 'x' )
275  mode |= Access::GX;
276  else if( modeStr[i] != '-' )
278  }
279  for( int i = 6; i < 9; ++i )
280  {
281  if( modeStr[i] == 'r' )
282  mode |= Access::OR;
283  else if( modeStr[i] == 'w' )
284  mode |= Access::OW;
285  else if( modeStr[i] == 'x' )
286  mode |= Access::OX;
287  else if( modeStr[i] != '-' )
289  }
290  return XRootDStatus();
291 }

References XrdCl::errInvalidArgs, XrdCl::Access::GR, XrdCl::Access::GW, XrdCl::Access::GX, XrdCl::Access::None, XrdCl::Access::OR, XrdCl::Access::OW, XrdCl::Access::OX, XrdCl::stError, XrdCl::Access::UR, XrdCl::Access::UW, and XrdCl::Access::UX.

Referenced by DoChMod(), and DoMkDir().

+ Here is the caller graph for this function:

◆ CreateExecutor()

FSExecutor* CreateExecutor ( const URL &  url)

Definition at line 2225 of file XrdClFS.cc.

2226 {
2227  Env *env = new Env();
2228  env->PutString( "CWD", "/" );
2229  FSExecutor *executor = new FSExecutor( url, env );
2230  executor->AddCommand( "cache", DoCache );
2231  executor->AddCommand( "cd", DoCD );
2232  executor->AddCommand( "chmod", DoChMod );
2233  executor->AddCommand( "ls", DoLS );
2234  executor->AddCommand( "help", PrintHelp );
2235  executor->AddCommand( "stat", DoStat );
2236  executor->AddCommand( "statvfs", DoStatVFS );
2237  executor->AddCommand( "locate", DoLocate );
2238  executor->AddCommand( "mv", DoMv );
2239  executor->AddCommand( "mkdir", DoMkDir );
2240  executor->AddCommand( "rm", DoRm );
2241  executor->AddCommand( "rmdir", DoRmDir );
2242  executor->AddCommand( "query", DoQuery );
2243  executor->AddCommand( "truncate", DoTruncate );
2244  executor->AddCommand( "prepare", DoPrepare );
2245  executor->AddCommand( "cat", DoCat );
2246  executor->AddCommand( "tail", DoTail );
2247  executor->AddCommand( "spaceinfo", DoSpaceInfo );
2248  executor->AddCommand( "xattr", DoXAttr );
2249  return executor;
2250 }
XRootDStatus DoQuery(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:1348
XRootDStatus DoLocate(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:960
XRootDStatus DoMkDir(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:649
XRootDStatus DoRmDir(FileSystem *query, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:710
XRootDStatus DoRm(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:797
XRootDStatus DoTail(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:1733
XRootDStatus DoStat(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:1154
XRootDStatus DoCat(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:1606
XRootDStatus DoMv(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:749
XRootDStatus DoPrepare(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:1451
XRootDStatus DoChMod(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:913
XRootDStatus DoLS(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:475
XRootDStatus DoCD(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:356
XRootDStatus DoXAttr(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:1903
XRootDStatus DoStatVFS(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:1288
XRootDStatus DoCache(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:296
XRootDStatus DoSpaceInfo(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:1860
XRootDStatus DoTruncate(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:866
XRootDStatus PrintHelp(FileSystem *, Env *, const FSExecutor::CommandParams &)
Definition: XrdClFS.cc:2065
bool PutString(const std::string &key, const std::string &value)
Definition: XrdClEnv.cc:52
Execute queries given as a commandline.
bool AddCommand(const std::string &name, Command command)

References XrdCl::FSExecutor::AddCommand(), DoCache(), DoCat(), DoCD(), DoChMod(), DoLocate(), DoLS(), DoMkDir(), DoMv(), DoPrepare(), DoQuery(), DoRm(), DoRmDir(), DoSpaceInfo(), DoStat(), DoStatVFS(), DoTail(), DoTruncate(), DoXAttr(), PrintHelp(), and XrdCl::Env::PutString().

Referenced by ExecuteCommand(), and ExecuteInteractive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoCache()

XRootDStatus DoCache ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 296 of file XrdClFS.cc.

299 {
300  //----------------------------------------------------------------------------
301  // Check up the args
302  //----------------------------------------------------------------------------
303  Log *log = DefaultEnv::GetLog();
304  uint32_t argc = args.size();
305 
306  if( argc != 3 )
307  {
308  log->Error( AppMsg, "Wrong number of arguments." );
309  return XRootDStatus( stError, errInvalidArgs, 0,
310  "Wrong number of arguments." );
311  }
312 
313  if( args[1] != "evict" && args[1] != "fevict")
314  {
315  log->Error( AppMsg, "Invalid cache operation." );
316  return XRootDStatus( stError, errInvalidArgs, 0, "Invalid cache operation." );
317  }
318 
319  std::string fullPath;
320  XRootDStatus pathSt = BuildPath( fullPath, env, args[2], "Caching" );
321  if( !pathSt.IsOK() )
322  return pathSt;
323 
324  //----------------------------------------------------------------------------
325  // Create the command
326  //----------------------------------------------------------------------------
327  std::string cmd = args[1];
328  cmd.append(" ");
329  cmd.append(fullPath);
330 
331  //----------------------------------------------------------------------------
332  // Run the operation
333  //----------------------------------------------------------------------------
334  Buffer *response = 0;
335  XRootDStatus st = fs->SendCache( cmd, response );
336  if( !st.IsOK() )
337  {
338  log->Error( AppMsg, "Unable set cache %s: %s",
339  fullPath.c_str(),
340  st.ToStr().c_str() );
341  return st;
342  }
343 
344  if( response )
345  {
346  std::cout << response->ToString() << '\n';
347  }
348 
349  delete response;
350 
351  return XRootDStatus();
352 }
XRootDStatus BuildPath(std::string &newPath, Env *env, const std::string &path, const char *op=nullptr)
Definition: XrdClFS.cc:166
Binary blob representation.
Definition: XrdClBuffer.hh:34
std::string ToString() const
Convert the buffer to a string.
Definition: XrdClBuffer.hh:215
XRootDStatus SendCache(const std::string &info, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
std::string ToStr() const
Convert to string.
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124

References XrdCl::AppMsg, BuildPath(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), XrdCl::FileSystem::SendCache(), XrdCl::stError, XrdCl::XRootDStatus::ToStr(), and XrdCl::Buffer::ToString().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoCat()

XRootDStatus DoCat ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 1606 of file XrdClFS.cc.

1609 {
1610  //----------------------------------------------------------------------------
1611  // Check up the args
1612  //----------------------------------------------------------------------------
1613  Log *log = DefaultEnv::GetLog();
1614  uint32_t argc = args.size();
1615 
1616  if( argc < 2 )
1617  {
1618  log->Error( AppMsg, "Wrong number of arguments." );
1619  return XRootDStatus( stError, errInvalidArgs );
1620  }
1621 
1622  std::string server;
1623  env->GetString( "ServerURL", server );
1624  if( server.empty() )
1625  {
1626  log->Error( AppMsg, "Invalid address: \"%s\".", server.c_str() );
1627  return XRootDStatus( stError, errInvalidAddr );
1628  }
1629 
1630  std::vector<std::string> remotes;
1631  std::string local;
1632 
1633  for( uint32_t i = 1; i < args.size(); ++i )
1634  {
1635  if( args[i] == "-o" )
1636  {
1637  if( i < args.size()-1 )
1638  {
1639  local = args[i+1];
1640  ++i;
1641  }
1642  else
1643  {
1644  log->Error( AppMsg, "Parameter '-o' requires an argument." );
1645  return XRootDStatus( stError, errInvalidArgs );
1646  }
1647  }
1648  else
1649  remotes.emplace_back( args[i] );
1650  }
1651 
1652  if( !local.empty() && remotes.size() > 1 )
1653  {
1654  log->Error( AppMsg, "If '-o' is used only can be used with only one remote file." );
1655  return XRootDStatus( stError, errInvalidArgs );
1656  }
1657 
1658  // a file URL needs an absolute path, else the path becomes its host
1659  if( !local.empty() && local[0] != '/' )
1660  {
1661  std::unique_ptr<char, decltype( &free )> cwd( getcwd( nullptr, 0 ), free );
1662  if( !cwd )
1663  {
1664  int err = errno;
1665  log->Error( AppMsg, "Unable to get the current directory: %s",
1666  XrdSysE2T( err ) );
1667  return XRootDStatus( stError, errOSError, err );
1668  }
1669  local = std::string( cwd.get() ) + "/" + local;
1670  }
1671 
1672  std::vector<URL> remoteUrls;
1673  remoteUrls.reserve( remotes.size() );
1674  for( auto &remote : remotes )
1675  {
1676  std::string remoteFile;
1677  XRootDStatus pathSt = BuildPath( remoteFile, env, remote, "Opening" );
1678  if( !pathSt.IsOK() )
1679  return pathSt;
1680 
1681  remoteUrls.emplace_back( server );
1682  remoteUrls.back().SetPath( remoteFile );
1683  }
1684 
1685  //----------------------------------------------------------------------------
1686  // Fetch the data
1687  //----------------------------------------------------------------------------
1688  CopyProgressHandler *handler = 0; ProgressDisplay d;
1689  CopyProcess process;
1690  std::vector<PropertyList> props( remoteUrls.size() ), results( remoteUrls.size() );
1691 
1692  for( size_t i = 0; i < remoteUrls.size(); ++i )
1693  {
1694  props[i].Set( "source", remoteUrls[i].GetURL() );
1695  if( !local.empty() )
1696  {
1697  props[i].Set( "target", std::string( "file://" ) + local );
1698  handler = &d;
1699  }
1700  else
1701  props[i].Set( "target", "stdio://-" );
1702 
1703  props[i].Set( "dynamicSource", true );
1704 
1705  XRootDStatus st = process.AddJob( props[i], &results[i] );
1706  if( !st.IsOK() )
1707  {
1708  log->Error( AppMsg, "Job adding failed: %s.", st.ToStr().c_str() );
1709  return st;
1710  }
1711  }
1712 
1713  XRootDStatus st = process.Prepare();
1714  if( !st.IsOK() )
1715  {
1716  log->Error( AppMsg, "Copy preparation failed: %s.", st.ToStr().c_str() );
1717  return st;
1718  }
1719 
1720  st = process.Run(handler);
1721  if( !st.IsOK() )
1722  {
1723  log->Error( AppMsg, "Cope process failed: %s.", st.ToStr().c_str() );
1724  return st;
1725  }
1726 
1727  return XRootDStatus();
1728 }
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:101
Copy the data from one point to another.
XRootDStatus Run(CopyProgressHandler *handler)
Run the copy jobs.
XRootDStatus Prepare()
XRootDStatus AddJob(const PropertyList &properties, PropertyList *results)
Interface for copy progress notification.
const uint16_t errInvalidAddr
Definition: XrdClStatus.hh:71
const uint16_t errOSError
Definition: XrdClStatus.hh:61

References XrdCl::CopyProcess::AddJob(), XrdCl::AppMsg, BuildPath(), XrdCl::errInvalidAddr, XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::errOSError, XrdCl::DefaultEnv::GetLog(), XrdCl::Env::GetString(), XrdCl::Status::IsOK(), XrdCl::CopyProcess::Prepare(), XrdCl::CopyProcess::Run(), XrdCl::stError, XrdCl::XRootDStatus::ToStr(), and XrdSysE2T().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoCD()

XRootDStatus DoCD ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 356 of file XrdClFS.cc.

359 {
360  //----------------------------------------------------------------------------
361  // Check up the args
362  //----------------------------------------------------------------------------
363  Log *log = DefaultEnv::GetLog();
364  if( args.size() != 2 )
365  {
366  log->Error( AppMsg, "Invalid arguments. Expected a path." );
368  }
369 
370  //----------------------------------------------------------------------------
371  // cd excludes NoCWD
372  //----------------------------------------------------------------------------
373  env->PutInt( "NoCWD", 0 );
374 
375  std::string newPath;
376  XRootDStatus pathSt = BuildPath( newPath, env, args[1], "Changing" );
377  if( !pathSt.IsOK() )
378  return pathSt;
379 
380  //----------------------------------------------------------------------------
381  // Check if the path exist and is not a directory
382  //----------------------------------------------------------------------------
383  StatInfo *info;
384  XRootDStatus st = fs->Stat( newPath, info );
385  if( !st.IsOK() )
386  {
387  log->Error( AppMsg, "Unable to stat the path: %s", st.ToStr().c_str() );
388  return st;
389  }
390 
391  if( !info->TestFlags( StatInfo::IsDir ) )
392  {
393  log->Error( AppMsg, "%s is not a directory.", newPath.c_str() );
395  }
396 
397  env->PutString( "CWD", newPath );
398  delete info;
399  return XRootDStatus();
400 }
bool PutInt(const std::string &key, int value)
Definition: XrdClEnv.cc:136
XRootDStatus Stat(const std::string &path, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Object stat info.
bool TestFlags(uint32_t flags) const
Test flags.

References XrdCl::AppMsg, BuildPath(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::StatInfo::IsDir, XrdCl::Status::IsOK(), XrdCl::Env::PutInt(), XrdCl::Env::PutString(), XrdCl::FileSystem::Stat(), XrdCl::stError, XrdCl::StatInfo::TestFlags(), and XrdCl::XRootDStatus::ToStr().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoChMod()

XRootDStatus DoChMod ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 913 of file XrdClFS.cc.

916 {
917  //----------------------------------------------------------------------------
918  // Check up the args
919  //----------------------------------------------------------------------------
920  Log *log = DefaultEnv::GetLog();
921  uint32_t argc = args.size();
922 
923  if( argc != 3 )
924  {
925  log->Error( AppMsg, "Wrong number of arguments." );
927  }
928 
929  std::string fullPath;
930  XRootDStatus pathSt = BuildPath( fullPath, env, args[1], "Modifying" );
931  if( !pathSt.IsOK() )
932  return pathSt;
933 
934  Access::Mode mode = Access::None;
935  XRootDStatus st = ConvertMode( mode, args[2] );
936  if( !st.IsOK() )
937  {
938  log->Error( AppMsg, "Invalid mode string." );
939  return st;
940  }
941 
942  //----------------------------------------------------------------------------
943  // Run the query
944  //----------------------------------------------------------------------------
945  st = fs->ChMod( fullPath, mode );
946  if( !st.IsOK() )
947  {
948  log->Error( AppMsg, "Unable change mode of %s: %s",
949  fullPath.c_str(),
950  st.ToStr().c_str() );
951  return st;
952  }
953 
954  return XRootDStatus();
955 }
XRootDStatus ConvertMode(Access::Mode &mode, const std::string &modeStr)
Definition: XrdClFS.cc:251
XRootDStatus ChMod(const std::string &path, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Mode
Access mode.

References XrdCl::AppMsg, BuildPath(), XrdCl::FileSystem::ChMod(), ConvertMode(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), XrdCl::Access::None, XrdCl::stError, and XrdCl::XRootDStatus::ToStr().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoLocate()

XRootDStatus DoLocate ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 960 of file XrdClFS.cc.

963 {
964  //----------------------------------------------------------------------------
965  // Check up the args
966  //----------------------------------------------------------------------------
967  Log *log = DefaultEnv::GetLog();
968  uint32_t argc = args.size();
969 
970  if( argc > 4 )
971  {
972  log->Error( AppMsg, "Wrong number of arguments." );
974  }
975 
976  OpenFlags::Flags flags = OpenFlags::None;
977  std::string path;
978  bool hasPath = false;
979  bool doDeepLocate = false;
980  for( uint32_t i = 1; i < argc; ++i )
981  {
982  if( args[i] == "-n" )
983  flags |= OpenFlags::NoWait;
984  else if( args[i] == "-r" )
985  flags |= OpenFlags::Refresh;
986  else if( args[i] == "-m" || args[i] == "-h" )
987  flags |= OpenFlags::PrefName;
988  else if( args[i] == "-i" )
989  flags |= OpenFlags::Force;
990  else if( args[i] == "-d" )
991  doDeepLocate = true;
992  else if( args[i] == "-p" )
993  {
994  Env *env = DefaultEnv::GetEnv();
995  env->PutInt( "PreserveLocateTried", 0 );
996  }
997  else if( !hasPath )
998  {
999  path = args[i];
1000  hasPath = true;
1001  }
1002  else
1003  {
1004  log->Error( AppMsg, "Invalid argument: %s.", args[i].c_str() );
1005  return XRootDStatus( stError, errInvalidArgs );
1006  }
1007  }
1008 
1009  std::string fullPath;
1010  if( path[0] == '*' )
1011  fullPath = path;
1012  else
1013  {
1014  XRootDStatus pathSt = BuildPath( fullPath, env, path, "Locating" );
1015  if( !pathSt.IsOK() )
1016  return pathSt;
1017  }
1018 
1019  //----------------------------------------------------------------------------
1020  // Run the query
1021  //----------------------------------------------------------------------------
1022  LocationInfo *info = 0;
1023  XRootDStatus st;
1024  if( doDeepLocate )
1025  st = fs->DeepLocate( fullPath, flags, info );
1026  else
1027  st = fs->Locate( fullPath, flags, info );
1028 
1029  if( !st.IsOK() )
1030  {
1031  log->Error( AppMsg, "Unable locate %s: %s",
1032  fullPath.c_str(),
1033  st.ToStr().c_str() );
1034  return st;
1035  }
1036 
1037  //----------------------------------------------------------------------------
1038  // Print the result
1039  //----------------------------------------------------------------------------
1040  if( st.code == suPartial )
1041  {
1042  std::cerr << "[!] Some of the requests failed. The result may be ";
1043  std::cerr << "incomplete." << std::endl;
1044  }
1045 
1047  for( it = info->Begin(); it != info->End(); ++it )
1048  {
1049  std::cout << it->GetAddress() << " ";
1050  switch( it->GetType() )
1051  {
1052  case LocationInfo::ManagerOnline:
1053  std::cout << "Manager ";
1054  break;
1055  case LocationInfo::ManagerPending:
1056  std::cout << "ManagerPending ";
1057  break;
1058  case LocationInfo::ServerOnline:
1059  std::cout << "Server ";
1060  break;
1061  case LocationInfo::ServerPending:
1062  std::cout << "ServerPending ";
1063  break;
1064  default:
1065  std::cout << "Unknown ";
1066  };
1067 
1068  switch( it->GetAccessType() )
1069  {
1070  case LocationInfo::Read:
1071  std::cout << "Read";
1072  break;
1074  std::cout << "ReadWrite ";
1075  break;
1076  default:
1077  std::cout << "Unknown ";
1078  };
1079  std::cout << std::endl;
1080  }
1081 
1082  delete info;
1083  return XRootDStatus();
1084 }
bool Force
XRootDStatus Locate(const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus DeepLocate(const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Path location info.
Iterator Begin()
Get the location begin iterator.
LocationList::iterator Iterator
Iterator over locations.
Iterator End()
Get the location end iterator.
const uint16_t suPartial
Definition: XrdClStatus.hh:41
@ ReadWrite
reading & writing
Definition: XrdSsiShMap.hh:51
void * Refresh(void *parg)
Flags
Open flags, may be or'd when appropriate.
uint16_t code
Error type, or additional hints on what to do.
Definition: XrdClStatus.hh:147

References XrdCl::AppMsg, XrdCl::LocationInfo::Begin(), BuildPath(), XrdCl::Status::code, XrdCl::FileSystem::DeepLocate(), XrdCl::LocationInfo::End(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::OpenFlags::Force, XrdCl::DefaultEnv::GetEnv(), XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), XrdCl::FileSystem::Locate(), XrdCl::LocationInfo::ManagerOnline, XrdCl::LocationInfo::ManagerPending, XrdCl::OpenFlags::None, XrdCl::OpenFlags::NoWait, XrdCl::OpenFlags::PrefName, XrdCl::Env::PutInt(), XrdCl::LocationInfo::Read, XrdCl::LocationInfo::ReadWrite, XrdCl::OpenFlags::Refresh, XrdCl::LocationInfo::ServerOnline, XrdCl::LocationInfo::ServerPending, XrdCl::stError, XrdCl::suPartial, and XrdCl::XRootDStatus::ToStr().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoLS()

XRootDStatus DoLS ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 475 of file XrdClFS.cc.

478 {
479  //----------------------------------------------------------------------------
480  // Check up the args
481  //----------------------------------------------------------------------------
482  Log *log = DefaultEnv::GetLog();
483  uint32_t argc = args.size();
484  bool stats = false;
485  bool showUrls = false;
486  bool hascks = false;
487  bool human = false;
488  uint64_t base = 1024;
489  std::string path;
490  DirListFlags::Flags flags = DirListFlags::Locate | DirListFlags::Merge;
491 
492  if( argc > 6 )
493  {
494  log->Error( AppMsg, "Too many arguments." );
496  }
497 
498  for( uint32_t i = 1; i < args.size(); ++i )
499  {
500  if( args[i] == "-l" )
501  {
502  stats = true;
503  flags |= DirListFlags::Stat;
504  }
505  else if( args[i] == "-u" )
506  showUrls = true;
507  else if( args[i] == "-R" )
508  {
509  flags |= DirListFlags::Recursive;
510  }
511  else if( args[i] == "-D" )
512  {
513  // show duplicates
514  flags &= ~DirListFlags::Merge;
515  }
516  else if( args[i] == "-Z" )
517  {
518  // check if file is a ZIP archive if yes list content
519  flags |= DirListFlags::Zip;
520  }
521  else if( args[i] == "-C" )
522  {
523  // query checksum for each entry in the directory
524  hascks = true;
525  stats = true;
526  flags |= DirListFlags::Cksm;
527  }
528  else if ( args [i] == "-h" )
529  {
530  human = true;
531  }
532  else
533  path = args[i];
534  }
535 
536  if( showUrls )
537  // we don't merge the duplicate entries
538  // in case we print the full URL
539  flags &= ~DirListFlags::Merge;
540 
541  std::string newPath = "/";
542  if( path.empty() )
543  env->GetString( "CWD", newPath );
544  else
545  {
546  XRootDStatus pathSt = BuildPath( newPath, env, path, "Listing" );
547  if( !pathSt.IsOK() )
548  return pathSt;
549  }
550 
551  //----------------------------------------------------------------------------
552  // Stat the entry so we know if it is a file or a directory
553  //----------------------------------------------------------------------------
554  log->Debug( AppMsg, "Attempting to stat: %s", newPath.c_str() );
555 
556  StatInfo *info = 0;
557  XRootDStatus st = fs->Stat( newPath, info );
558  std::unique_ptr<StatInfo> ptr( info );
559  if( !st.IsOK() )
560  {
561  log->Error( AppMsg, "Unable to stat the path: %s", st.ToStr().c_str() );
562  return st;
563  }
564 
565  if( !info->TestFlags( StatInfo::IsDir ) &&
566  !( flags & DirListFlags::Zip ) )
567  {
568  if( stats )
569  PrintDirListStatInfo( info, false, 0, 0, 0, human, base );
570 
571  if( showUrls )
572  {
573  std::string url;
574  fs->GetProperty( "LastURL", url );
575  std::cout << url;
576  }
577  std::cout << newPath << std::endl;
578  return XRootDStatus();
579  }
580 
581 
582  //----------------------------------------------------------------------------
583  // Ask for the list
584  //----------------------------------------------------------------------------
585  log->Debug( AppMsg, "Attempting to list: %s", newPath.c_str() );
586 
587  DirectoryList *list;
588  st = fs->DirList( newPath, flags, list );
589  if( !st.IsOK() )
590  {
591  log->Error( AppMsg, "Unable to list the path: %s", st.ToStr().c_str() );
592  return st;
593  }
594 
595  if( st.code == suPartial )
596  {
597  std::cerr << "[!] Some of the requests failed. The result may be ";
598  std::cerr << "incomplete." << std::endl;
599  }
600 
601  uint32_t ownerwidth = 0, groupwidth = 0, sizewidth = 0, ckswidth = 0;
603  for( it = list->Begin(); it != list->End() && stats; ++it )
604  {
605  StatInfo *info = (*it)->GetStatInfo();
606 
607  std::string size = getSizeStr(info->GetSize(),human,base);
608  uint32_t sizeWidthComp;
609  if (human) {
610  sizeWidthComp = size.size();
611  } else {
612  sizeWidthComp = nbDigits( info->GetSize());
613  }
614 
615  if( ownerwidth < info->GetOwner().size() )
616  ownerwidth = info->GetOwner().size();
617  if( groupwidth < info->GetGroup().size() )
618  groupwidth = info->GetGroup().size();
619  if( sizewidth < sizeWidthComp )
620  sizewidth = sizeWidthComp;
621  if( ckswidth < info->GetChecksum().size() )
622  ckswidth = info->GetChecksum().size();
623  }
624 
625  //----------------------------------------------------------------------------
626  // Print the results
627  //----------------------------------------------------------------------------
628  for( it = list->Begin(); it != list->End(); ++it )
629  {
630  if( stats )
631  {
632  StatInfo *info = (*it)->GetStatInfo();
633  if( !info )
634  std::cout << "---- 0000-00-00 00:00:00 ? ";
635  else
636  PrintDirListStatInfo( info, hascks, ownerwidth, groupwidth, sizewidth, human, base );
637  }
638  if( showUrls )
639  std::cout << "root://" << (*it)->GetHostAddress() << "/";
640  std::cout << list->GetParentName() << (*it)->GetName() << std::endl;
641  }
642  delete list;
643  return XRootDStatus();
644 }
struct stat Stat
Definition: XrdCks.cc:49
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)
Definition: XrdClFS.cc:421
uint32_t nbDigits(uint64_t nb)
Definition: XrdClFS.cc:405
std::string getSizeStr(uint64_t size, bool human, uint64_t base)
Definition: XrdClFS.cc:411
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.
XRootDStatus DirList(const std::string &path, DirListFlags::Flags flags, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
bool GetProperty(const std::string &name, std::string &value) const
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition: XrdClLog.cc:282
uint64_t GetSize() const
Get size (in bytes)
const std::string & GetOwner() const
Get owner.
const std::string & GetGroup() const
Get group.
const std::string & GetChecksum() const
Get checksum.
LocateImpl< false > Locate

References XrdCl::AppMsg, XrdCl::DirectoryList::Begin(), BuildPath(), XrdCl::DirListFlags::Cksm, XrdCl::Status::code, XrdCl::Log::Debug(), XrdCl::FileSystem::DirList(), XrdCl::DirectoryList::End(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::StatInfo::GetChecksum(), XrdCl::StatInfo::GetGroup(), XrdCl::DefaultEnv::GetLog(), XrdCl::StatInfo::GetOwner(), XrdCl::DirectoryList::GetParentName(), XrdCl::FileSystem::GetProperty(), XrdCl::StatInfo::GetSize(), getSizeStr(), XrdCl::Env::GetString(), XrdCl::StatInfo::IsDir, XrdCl::Status::IsOK(), XrdCl::DirListFlags::Locate, XrdCl::DirListFlags::Merge, nbDigits(), PrintDirListStatInfo(), XrdCl::DirListFlags::Recursive, XrdCl::DirListFlags::Stat, XrdCl::FileSystem::Stat(), XrdCl::stError, XrdCl::suPartial, XrdCl::StatInfo::TestFlags(), XrdCl::XRootDStatus::ToStr(), and XrdCl::DirListFlags::Zip.

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoMkDir()

XRootDStatus DoMkDir ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 649 of file XrdClFS.cc.

652 {
653  //----------------------------------------------------------------------------
654  // Check up the args
655  //----------------------------------------------------------------------------
656  Log *log = DefaultEnv::GetLog();
657  uint32_t argc = args.size();
658 
659  if( argc < 2 || argc > 4 )
660  {
661  log->Error( AppMsg, "Too few arguments." );
663  }
664 
665  MkDirFlags::Flags flags = MkDirFlags::None;
666  Access::Mode mode = Access::None;
667  std::string modeStr = "rwxr-x---";
668  std::string path = "";
669 
670  for( uint32_t i = 1; i < args.size(); ++i )
671  {
672  if( args[i] == "-p" )
673  flags |= MkDirFlags::MakePath;
674  else if( !args[i].compare( 0, 2, "-m" ) )
675  modeStr = args[i].substr( 2, 9 );
676  else
677  path = args[i];
678  }
679 
680  XRootDStatus st = ConvertMode( mode, modeStr );
681  if( !st.IsOK() )
682  {
683  log->Error( AppMsg, "Invalid mode string." );
684  return st;
685  }
686 
687  std::string newPath;
688  XRootDStatus pathSt = BuildPath( newPath, env, path, "Creating" );
689  if( !pathSt.IsOK() )
690  return pathSt;
691 
692  //----------------------------------------------------------------------------
693  // Run the query
694  //----------------------------------------------------------------------------
695  st = fs->MkDir( newPath, flags, mode );
696  if( !st.IsOK() )
697  {
698  log->Error( AppMsg, "Unable create directory %s: %s",
699  newPath.c_str(),
700  st.ToStr().c_str() );
701  return st;
702  }
703 
704  return XRootDStatus();
705 }
XRootDStatus MkDir(const std::string &path, MkDirFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT

References XrdCl::AppMsg, BuildPath(), ConvertMode(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), XrdCl::MkDirFlags::MakePath, XrdCl::FileSystem::MkDir(), XrdCl::Access::None, XrdCl::MkDirFlags::None, XrdCl::stError, and XrdCl::XRootDStatus::ToStr().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoMv()

XRootDStatus DoMv ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 749 of file XrdClFS.cc.

752 {
753  //----------------------------------------------------------------------------
754  // Check up the args
755  //----------------------------------------------------------------------------
756  Log *log = DefaultEnv::GetLog();
757  uint32_t argc = args.size();
758 
759  if( argc != 3 )
760  {
761  log->Error( AppMsg, "Wrong number of arguments." );
763  }
764 
765  std::string fullPath1;
766  XRootDStatus pathSt = BuildPath( fullPath1, env, args[1], "Renaming" );
767  if( !pathSt.IsOK() )
768  return pathSt;
769 
770  std::string fullPath2;
771  pathSt = BuildPath( fullPath2, env, args[2], "Renaming to" );
772  if( !pathSt.IsOK() )
773  return pathSt;
774 
775  if( is_subdirectory(fullPath1, fullPath2) )
776  return XRootDStatus( stError, errInvalidArgs, 0,
777  "cannot move directory to a subdirectory of itself." );
778 
779  //----------------------------------------------------------------------------
780  // Run the query
781  //----------------------------------------------------------------------------
782  XRootDStatus st = fs->Mv( fullPath1, fullPath2 );
783  if( !st.IsOK() )
784  {
785  log->Error( AppMsg, "Unable move %s to %s: %s",
786  fullPath1.c_str(), fullPath2.c_str(),
787  st.ToStr().c_str() );
788  return st;
789  }
790 
791  return XRootDStatus();
792 }
static bool is_subdirectory(const std::string_view dir, const std::string_view subdir)
XRootDStatus Mv(const std::string &source, const std::string &dest, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT

References XrdCl::AppMsg, BuildPath(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), is_subdirectory(), XrdCl::Status::IsOK(), XrdCl::FileSystem::Mv(), XrdCl::stError, and XrdCl::XRootDStatus::ToStr().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoPrepare()

XRootDStatus DoPrepare ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 1451 of file XrdClFS.cc.

1454 {
1455  //----------------------------------------------------------------------------
1456  // Check up the args
1457  //----------------------------------------------------------------------------
1458  Log *log = DefaultEnv::GetLog();
1459  uint32_t argc = args.size();
1460 
1461  if( argc < 2 )
1462  {
1463  log->Error( AppMsg, "Wrong number of arguments." );
1464  return XRootDStatus( stError, errInvalidArgs );
1465  }
1466 
1467  PrepareFlags::Flags flags = PrepareFlags::None;
1468  std::vector<std::string> files;
1469  uint8_t priority = 0;
1470  std::string reqid;
1471 
1472  for( uint32_t i = 1; i < args.size(); ++i )
1473  {
1474  if( args[i] == "-p" )
1475  {
1476  if( i < args.size()-1 )
1477  {
1478  char *result;
1479  int32_t param = ::strtol( args[i+1].c_str(), &result, 0 );
1480  if( *result != 0 || param > 3 || param < 0 )
1481  {
1482  log->Error( AppMsg, "Size priotiry needs to be an integer between 0 "
1483  "and 3" );
1484  return XRootDStatus( stError, errInvalidArgs );
1485  }
1486  priority = (uint8_t)param;
1487  ++i;
1488  }
1489  else
1490  {
1491  log->Error( AppMsg, "Parameter '-p' requires an argument." );
1492  return XRootDStatus( stError, errInvalidArgs );
1493  }
1494  }
1495  else if( args[i] == "-c" )
1496  flags |= PrepareFlags::Colocate;
1497  else if( args[i] == "-f" )
1498  flags |= PrepareFlags::Fresh;
1499  else if( args[i] == "-s" )
1500  flags |= PrepareFlags::Stage;
1501  else if( args[i] == "-w" )
1502  flags |= PrepareFlags::WriteMode;
1503  else if( args[i] == "-e" )
1504  flags |= PrepareFlags::Evict;
1505  else if( args[i] == "-a" )
1506  {
1507  flags |= PrepareFlags::Cancel;
1508  if( i < args.size()-1 )
1509  {
1510  // by convention the request ID appears as the the first token
1511  // in the list of files
1512  files.push_back( args[i+1] );
1513  ++i;
1514  }
1515  else
1516  {
1517  log->Error( AppMsg, "Parameter '-a' requires an argument." );
1518  return XRootDStatus( stError, errInvalidArgs );
1519  }
1520  }
1521  else
1522  files.push_back( args[i] );
1523  }
1524 
1525  if( files.empty() )
1526  {
1527  log->Error( AppMsg, "Filename missing." );
1528  return XRootDStatus( stError, errInvalidArgs );
1529  }
1530 
1531  //----------------------------------------------------------------------------
1532  // Run the command
1533  //----------------------------------------------------------------------------
1534  Buffer *response = 0;
1535  XRootDStatus st = fs->Prepare( files, flags, priority, response );
1536  if( !st.IsOK() )
1537  {
1538  log->Error( AppMsg, "Prepare request failed: %s", st.ToStr().c_str() );
1539  return st;
1540  }
1541 
1542  if( ( flags & PrepareFlags::Stage ) && response )
1543  {
1544  std::cout << response->ToString() << '\n';
1545  }
1546 
1547  delete response;
1548  return XRootDStatus();
1549 }
XRootDStatus Prepare(const std::vector< std::string > &fileList, PrepareFlags::Flags flags, uint8_t priority, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT

References XrdCl::AppMsg, XrdCl::PrepareFlags::Cancel, XrdCl::PrepareFlags::Colocate, XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::PrepareFlags::Evict, XrdCl::PrepareFlags::Fresh, XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), XrdCl::PrepareFlags::None, XrdCl::FileSystem::Prepare(), XrdCl::PrepareFlags::Stage, XrdCl::stError, XrdCl::XRootDStatus::ToStr(), XrdCl::Buffer::ToString(), and XrdCl::PrepareFlags::WriteMode.

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoQuery()

XRootDStatus DoQuery ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 1348 of file XrdClFS.cc.

1351 {
1352  //----------------------------------------------------------------------------
1353  // Check up the args
1354  //----------------------------------------------------------------------------
1355  Log *log = DefaultEnv::GetLog();
1356  uint32_t argc = args.size();
1357 
1358  if( !( argc >= 3 ) )
1359  {
1360  log->Error( AppMsg, "Wrong number of arguments." );
1361  return XRootDStatus( stError, errInvalidArgs );
1362  }
1363 
1364  QueryCode::Code qCode;
1365  if( args[1] == "config" )
1366  qCode = QueryCode::Config;
1367  else if( args[1] == "checksumcancel" )
1368  qCode = QueryCode::ChecksumCancel;
1369  else if( args[1] == "checksum" )
1370  qCode = QueryCode::Checksum;
1371  else if( args[1] == "opaque" )
1372  qCode = QueryCode::Opaque;
1373  else if( args[1] == "opaquefile" )
1374  qCode = QueryCode::OpaqueFile;
1375  else if( args[1] == "prepare" )
1376  qCode = QueryCode::Prepare;
1377  else if( args[1] == "space" )
1378  qCode = QueryCode::Space;
1379  else if( args[1] == "stats" )
1380  qCode = QueryCode::Stats;
1381  else if( args[1] == "xattr" )
1382  qCode = QueryCode::XAttr;
1383  else
1384  {
1385  log->Error( AppMsg, "Invalid query code." );
1386  return XRootDStatus( stError, errInvalidArgs );
1387  }
1388 
1389  if( !( qCode & QueryCode::Prepare ) && argc != 3 )
1390  {
1391  log->Error( AppMsg, "Wrong number of arguments." );
1392  return XRootDStatus( stError, errInvalidArgs );
1393  }
1394 
1395  std::string strArg = args[2];
1396  if( qCode & QueryCode::Prepare )
1397  {
1398  // strArg is supposed to contain already the request ID
1399 
1400  for( size_t i = 3; i < args.size(); ++i )
1401  {
1402  std::string path = args[i];
1403  XRootDStatus pathSt = BuildPath( path, env, path, "Preparing" );
1404  if( !pathSt.IsOK() )
1405  return pathSt;
1406  // we use new line character as delimiter
1407  strArg += '\n';
1408  strArg += path;
1409  }
1410  }
1411  else
1412  {
1413  std::string strArg = args[2];
1414  if( qCode == QueryCode::ChecksumCancel ||
1415  qCode == QueryCode::Checksum ||
1416  qCode == QueryCode::XAttr )
1417  {
1418  XRootDStatus pathSt = BuildPath( strArg, env, args[2], "Querying" );
1419  if( !pathSt.IsOK() )
1420  return pathSt;
1421  }
1422  }
1423 
1424  //----------------------------------------------------------------------------
1425  // Run the query
1426  //----------------------------------------------------------------------------
1427  Buffer arg( strArg.size() );
1428  arg.FromString( strArg );
1429  Buffer *response = 0;
1430  XRootDStatus st = fs->Query( qCode, arg, response );
1431 
1432  if( !st.IsOK() )
1433  {
1434  log->Error( AppMsg, "Unable run query %s: %s",
1435  args[1].c_str(),
1436  st.ToStr().c_str() );
1437  return st;
1438  }
1439 
1440  //----------------------------------------------------------------------------
1441  // Print the result
1442  //----------------------------------------------------------------------------
1443  std::cout << response->ToString() << std::endl;
1444  delete response;
1445  return XRootDStatus();
1446 }
XRootDStatus Query(QueryCode::Code queryCode, const Buffer &arg, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
PrepareImpl< false > Prepare
XrdCmsConfig Config
XrdPosixStats Stats
Definition: XrdPosixFile.cc:64
Code
XRootD query request codes.

References XrdCl::AppMsg, BuildPath(), XrdCl::QueryCode::Checksum, XrdCl::QueryCode::ChecksumCancel, XrdCl::QueryCode::Config, XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::Buffer::FromString(), XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), XrdCl::QueryCode::Opaque, XrdCl::QueryCode::OpaqueFile, XrdCl::QueryCode::Prepare, XrdCl::FileSystem::Query(), XrdCl::QueryCode::Space, XrdCl::QueryCode::Stats, XrdCl::stError, XrdCl::XRootDStatus::ToStr(), XrdCl::Buffer::ToString(), and XrdCl::QueryCode::XAttr.

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoRm()

XRootDStatus DoRm ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 797 of file XrdClFS.cc.

800 {
801  //----------------------------------------------------------------------------
802  // Check up the args
803  //----------------------------------------------------------------------------
804  Log *log = DefaultEnv::GetLog();
805  uint32_t argc = args.size();
806 
807  if( argc < 2 )
808  {
809  log->Error( AppMsg, "Wrong number of arguments." );
811  }
812 
813  struct print_t
814  {
815  void print( const std::string &msg )
816  {
817  std::unique_lock<std::mutex> lck( mtx );
818  std::cout << msg << '\n';
819  }
820  std::mutex mtx;
821  };
822  std::shared_ptr<print_t> print;
823  if( argc - 1 > 0 )
824  print = std::make_shared<print_t>();
825 
826  std::vector<Pipeline> rms;
827  rms.reserve( argc - 1 );
828  for( size_t i = 1; i < argc; ++i )
829  {
830  std::string fullPath;
831  XRootDStatus pathSt = BuildPath( fullPath, env, args[i], "Removing" );
832  if( !pathSt.IsOK() )
833  return pathSt;
834  rms.emplace_back( Rm( fs, fullPath ) >>
835  [log, fullPath, print]( XRootDStatus &st )
836  {
837  if( !st.IsOK() )
838  {
839  log->Error( AppMsg, "Unable remove %s: %s",
840  fullPath.c_str(),
841  st.ToStr().c_str() );
842  }
843  if( print )
844  {
845  print->print( "rm " + fullPath + " : " + st.ToString() );
846  }
847  } );
848  }
849 
850  //----------------------------------------------------------------------------
851  // Run the query:
852  // Parallel() will take the vector of Pipeline by reference and empty the
853  // vector, so rms.size() will change after the call.
854  //----------------------------------------------------------------------------
855  const size_t rs = rms.size();
856  XRootDStatus st = WaitFor( Parallel( rms ).AtLeast( rs ) );
857  if( !st.IsOK() )
858  return st;
859 
860  return XRootDStatus();
861 }
RmImpl< false > Rm
ParallelOperation< false > Parallel(Container &&container)
Factory function for creating parallel operation from a vector.
XRootDStatus WaitFor(Pipeline pipeline, time_t timeout=0)

References XrdCl::AppMsg, BuildPath(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), XrdCl::Parallel(), XrdCl::stError, and XrdCl::WaitFor().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoRmDir()

XRootDStatus DoRmDir ( FileSystem *  query,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 710 of file XrdClFS.cc.

713 {
714  //----------------------------------------------------------------------------
715  // Check up the args
716  //----------------------------------------------------------------------------
717  Log *log = DefaultEnv::GetLog();
718  uint32_t argc = args.size();
719 
720  if( argc != 2 )
721  {
722  log->Error( AppMsg, "Wrong number of arguments." );
724  }
725 
726  std::string fullPath;
727  XRootDStatus pathSt = BuildPath( fullPath, env, args[1], "Removing" );
728  if( !pathSt.IsOK() )
729  return pathSt;
730 
731  //----------------------------------------------------------------------------
732  // Run the query
733  //----------------------------------------------------------------------------
734  XRootDStatus st = query->RmDir( fullPath );
735  if( !st.IsOK() )
736  {
737  log->Error( AppMsg, "Unable remove directory %s: %s",
738  fullPath.c_str(),
739  st.ToStr().c_str() );
740  return st;
741  }
742 
743  return XRootDStatus();
744 }
XRootDStatus RmDir(const std::string &path, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT

References XrdCl::AppMsg, BuildPath(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), XrdCl::FileSystem::RmDir(), XrdCl::stError, and XrdCl::XRootDStatus::ToStr().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoSpaceInfo()

XRootDStatus DoSpaceInfo ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 1860 of file XrdClFS.cc.

1863 {
1864  using namespace XrdCl;
1865 
1866  //----------------------------------------------------------------------------
1867  // Check up the args
1868  //----------------------------------------------------------------------------
1869  Log *log = DefaultEnv::GetLog();
1870  uint32_t argc = args.size();
1871 
1872  if( argc != 2 )
1873  {
1874  log->Error( AppMsg, "Wrong number of arguments." );
1875  return XRootDStatus( stError, errInvalidArgs );
1876  }
1877 
1879 
1880  XRootDStatus st = FileSystemUtils::GetSpaceInfo( i, fs, args[1] );
1881  if( !st.IsOK() )
1882  return st;
1883 
1884  if( st.code == suPartial )
1885  {
1886  std::cerr << "[!] Some of the requests failed. The result may be ";
1887  std::cerr << "incomplete." << std::endl;
1888  }
1889 
1890  std::cout << "Path: " << args[1] << std::endl;
1891  std::cout << "Total: " << i->GetTotal() << std::endl;
1892  std::cout << "Free: " << i->GetFree() << std::endl;
1893  std::cout << "Used: " << i->GetUsed() << std::endl;
1894  std::cout << "Largest free chunk: " << i->GetLargestFreeChunk() << std::endl;
1895 
1896  delete i;
1897  return XRootDStatus();
1898 }
static Log * GetLog()
Get default log.
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.

References XrdCl::AppMsg, XrdCl::Status::code, XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::FileSystemUtils::SpaceInfo::GetFree(), XrdCl::FileSystemUtils::SpaceInfo::GetLargestFreeChunk(), XrdCl::DefaultEnv::GetLog(), XrdCl::FileSystemUtils::GetSpaceInfo(), XrdCl::FileSystemUtils::SpaceInfo::GetTotal(), XrdCl::FileSystemUtils::SpaceInfo::GetUsed(), XrdCl::Status::IsOK(), XrdCl::stError, and XrdCl::suPartial.

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoStat()

XRootDStatus DoStat ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 1154 of file XrdClFS.cc.

1157 {
1158  //----------------------------------------------------------------------------
1159  // Check up the args
1160  //----------------------------------------------------------------------------
1161  Log *log = DefaultEnv::GetLog();
1162  uint32_t argc = args.size();
1163 
1164  if( argc < 2 )
1165  {
1166  log->Error( AppMsg, "Wrong number of arguments." );
1167  return XRootDStatus( stError, errInvalidArgs );
1168  }
1169 
1170  std::vector<std::string> paths;
1171  std::string query;
1172 
1173  for( uint32_t i = 1; i < args.size(); ++i )
1174  {
1175  if( args[i] == "-q" )
1176  {
1177  if( i < args.size()-1 )
1178  {
1179  query = args[i+1];
1180  ++i;
1181  }
1182  else
1183  {
1184  log->Error( AppMsg, "Parameter '-q' requires an argument." );
1185  return XRootDStatus( stError, errInvalidArgs );
1186  }
1187  }
1188  else
1189  paths.emplace_back( args[i] );
1190  }
1191 
1192  std::vector<XrdCl::Pipeline> stats;
1193  std::vector<std::tuple<std::future<StatInfo>, std::string>> results;
1194  for( auto &path : paths )
1195  {
1196  std::string fullPath;
1197  XRootDStatus pathSt = BuildPath( fullPath, env, path, "Stating" );
1198  if( !pathSt.IsOK() )
1199  return pathSt;
1200  std::future<XrdCl::StatInfo> ftr;
1201  stats.emplace_back( XrdCl::Stat( fs, fullPath ) >> ftr );
1202  results.emplace_back( std::move( ftr ), std::move( fullPath ) );
1203  }
1204 
1205  //----------------------------------------------------------------------------
1206  // Run the query
1207  //----------------------------------------------------------------------------
1208  XrdCl::Async( XrdCl::Parallel( stats ) );
1209 
1210  //----------------------------------------------------------------------------
1211  // Print the result
1212  //----------------------------------------------------------------------------
1214  for( auto &tpl : results )
1215  {
1216  auto &ftr = std::get<0>( tpl );
1217  auto &fullPath = std::get<1>( tpl );
1218  std::cout << std::endl;
1219  try
1220  {
1221  XrdCl::StatInfo info( ftr.get() );
1222  std::string flags;
1223 
1224  if( info.TestFlags( StatInfo::XBitSet ) )
1225  flags += "XBitSet|";
1226  if( info.TestFlags( StatInfo::IsDir ) )
1227  flags += "IsDir|";
1228  if( info.TestFlags( StatInfo::Other ) )
1229  flags += "Other|";
1230  if( info.TestFlags( StatInfo::Offline ) )
1231  flags += "Offline|";
1232  if( info.TestFlags( StatInfo::POSCPending ) )
1233  flags += "POSCPending|";
1234  if( info.TestFlags( StatInfo::IsReadable ) )
1235  flags += "IsReadable|";
1236  if( info.TestFlags( StatInfo::IsWritable ) )
1237  flags += "IsWritable|";
1238  if( info.TestFlags( StatInfo::BackUpExists ) )
1239  flags += "BackUpExists|";
1240 
1241  if( !flags.empty() )
1242  flags.erase( flags.length()-1, 1 );
1243 
1244  std::cout << "Path: " << fullPath << std::endl;
1245  std::cout << "Id: " << info.GetId() << std::endl;
1246  std::cout << "Size: " << info.GetSize() << std::endl;
1247  std::cout << "MTime: " << info.GetModTimeAsString() << std::endl;
1248  // if extended stat information is available we can print also
1249  // change time and access time
1250  if( info.ExtendedFormat() )
1251  {
1252  std::cout << "CTime: " << info.GetChangeTimeAsString() << std::endl;
1253  std::cout << "ATime: " << info.GetAccessTimeAsString() << std::endl;
1254  }
1255  std::cout << "Flags: " << info.GetFlags() << " (" << flags << ")";
1256 
1257  // check if extended stat information is available
1258  if( info.ExtendedFormat() )
1259  {
1260  std::cout << "\nMode: " << info.GetModeAsString() << std::endl;
1261  std::cout << "Owner: " << info.GetOwner() << std::endl;
1262  std::cout << "Group: " << info.GetGroup();
1263  }
1264 
1265  std::cout << std::endl;
1266 
1267  if( query.length() != 0 )
1268  {
1269  XRootDStatus s = ProcessStatQuery( info, query );
1270  if( !s.IsOK() )
1271  st = s;
1272  std::cout << "Query: " << query << " " << std::endl;
1273  }
1274  }
1275  catch( XrdCl::PipelineException &ex )
1276  {
1277  st = ex.GetError();
1278  log->Error( AppMsg, "Unable stat %s: %s", fullPath.c_str(), st.ToStr().c_str() );
1279  }
1280  }
1281 
1282  return st;
1283 }
XRootDStatus ProcessStatQuery(StatInfo &info, const std::string &query)
Definition: XrdClFS.cc:1089
Pipeline exception, wrapps an XRootDStatus.
const XRootDStatus & GetError() const
StatImpl< false > Stat(Ctx< File > file, Arg< bool > force, time_t timeout=0)
std::future< XRootDStatus > Async(Pipeline pipeline, time_t timeout=0)

References XrdCl::AppMsg, XrdCl::Async(), XrdCl::StatInfo::BackUpExists, BuildPath(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::StatInfo::ExtendedFormat(), XrdCl::StatInfo::GetAccessTimeAsString(), XrdCl::StatInfo::GetChangeTimeAsString(), XrdCl::PipelineException::GetError(), XrdCl::StatInfo::GetFlags(), XrdCl::StatInfo::GetGroup(), XrdCl::StatInfo::GetId(), XrdCl::DefaultEnv::GetLog(), XrdCl::StatInfo::GetModeAsString(), XrdCl::StatInfo::GetModTimeAsString(), XrdCl::StatInfo::GetOwner(), XrdCl::StatInfo::GetSize(), XrdCl::StatInfo::IsDir, XrdCl::Status::IsOK(), XrdCl::StatInfo::IsReadable, XrdCl::StatInfo::IsWritable, XrdCl::StatInfo::Offline, XrdCl::StatInfo::Other, XrdCl::Parallel(), XrdCl::StatInfo::POSCPending, ProcessStatQuery(), XrdCl::Stat(), XrdCl::stError, XrdCl::StatInfo::TestFlags(), XrdCl::XRootDStatus::ToStr(), and XrdCl::StatInfo::XBitSet.

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoStatVFS()

XRootDStatus DoStatVFS ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 1288 of file XrdClFS.cc.

1291 {
1292  //----------------------------------------------------------------------------
1293  // Check up the args
1294  //----------------------------------------------------------------------------
1295  Log *log = DefaultEnv::GetLog();
1296  uint32_t argc = args.size();
1297 
1298  if( argc != 2 )
1299  {
1300  log->Error( AppMsg, "Wrong number of arguments." );
1301  return XRootDStatus( stError, errInvalidArgs );
1302  }
1303 
1304  std::string fullPath;
1305  XRootDStatus pathSt = BuildPath( fullPath, env, args[1], "Stating" );
1306  if( !pathSt.IsOK() )
1307  return pathSt;
1308 
1309  //----------------------------------------------------------------------------
1310  // Run the query
1311  //----------------------------------------------------------------------------
1312  StatInfoVFS *info = 0;
1313  XRootDStatus st = fs->StatVFS( fullPath, info );
1314 
1315  if( !st.IsOK() )
1316  {
1317  log->Error( AppMsg, "Unable stat VFS at %s: %s",
1318  fullPath.c_str(),
1319  st.ToStr().c_str() );
1320  return st;
1321  }
1322 
1323  //----------------------------------------------------------------------------
1324  // Print the result
1325  //----------------------------------------------------------------------------
1326  std::cout << "Path: ";
1327  std::cout << fullPath << std::endl;
1328  std::cout << "Nodes with RW space: ";
1329  std::cout << info->GetNodesRW() << std::endl;
1330  std::cout << "Size of largest RW space (MB): ";
1331  std::cout << info->GetFreeRW() << std::endl;
1332  std::cout << "Utilization of RW space (%): ";
1333  std::cout << (uint16_t)info->GetUtilizationRW() << std::endl;
1334  std::cout << "Nodes with staging space: ";
1335  std::cout << info->GetNodesStaging() << std::endl;
1336  std::cout << "Size of largest staging space (MB): ";
1337  std::cout << info->GetFreeStaging() << std::endl;
1338  std::cout << "Utilization of staging space (%): ";
1339  std::cout << (uint16_t)info->GetUtilizationStaging() << std::endl;
1340 
1341  delete info;
1342  return XRootDStatus();
1343 }
XRootDStatus StatVFS(const std::string &path, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
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.

References XrdCl::AppMsg, BuildPath(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::StatInfoVFS::GetFreeRW(), XrdCl::StatInfoVFS::GetFreeStaging(), XrdCl::DefaultEnv::GetLog(), XrdCl::StatInfoVFS::GetNodesRW(), XrdCl::StatInfoVFS::GetNodesStaging(), XrdCl::StatInfoVFS::GetUtilizationRW(), XrdCl::StatInfoVFS::GetUtilizationStaging(), XrdCl::Status::IsOK(), XrdCl::FileSystem::StatVFS(), XrdCl::stError, and XrdCl::XRootDStatus::ToStr().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoTail()

XRootDStatus DoTail ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 1733 of file XrdClFS.cc.

1736 {
1737  //----------------------------------------------------------------------------
1738  // Check up the args
1739  //----------------------------------------------------------------------------
1740  Log *log = DefaultEnv::GetLog();
1741  uint32_t argc = args.size();
1742 
1743  if( argc < 2 || argc > 5 )
1744  {
1745  log->Error( AppMsg, "Wrong number of arguments." );
1746  return XRootDStatus( stError, errInvalidArgs );
1747  }
1748 
1749  std::string server;
1750  env->GetString( "ServerURL", server );
1751  if( server.empty() )
1752  {
1753  log->Error( AppMsg, "Invalid address: \"%s\".", server.c_str() );
1754  return XRootDStatus( stError, errInvalidAddr );
1755  }
1756 
1757  std::string remote;
1758  bool followMode = false;
1759  uint32_t offset = 512;
1760 
1761  for( uint32_t i = 1; i < args.size(); ++i )
1762  {
1763  if( args[i] == "-f" )
1764  followMode = true;
1765  else if( args[i] == "-c" )
1766  {
1767  if( i < args.size()-1 )
1768  {
1769  char *result;
1770  offset = ::strtol( args[i+1].c_str(), &result, 0 );
1771  if( *result != 0 )
1772  {
1773  log->Error( AppMsg, "Offset from the end needs to be a number: %s",
1774  args[i+1].c_str() );
1775  return XRootDStatus( stError, errInvalidArgs );
1776  }
1777  ++i;
1778  }
1779  else
1780  {
1781  log->Error( AppMsg, "Parameter '-n' requires an argument." );
1782  return XRootDStatus( stError, errInvalidArgs );
1783  }
1784  }
1785  else
1786  remote = args[i];
1787  }
1788 
1789  std::string remoteFile;
1790  XRootDStatus pathSt = BuildPath( remoteFile, env, remote, "Opening" );
1791  if( !pathSt.IsOK() )
1792  return pathSt;
1793 
1794  URL remoteUrl( server );
1795  remoteUrl.SetPath( remoteFile );
1796 
1797  //----------------------------------------------------------------------------
1798  // Fetch the data
1799  //----------------------------------------------------------------------------
1800  File file;
1801  XRootDStatus st = file.Open( remoteUrl.GetURL(), OpenFlags::Read );
1802  if( !st.IsOK() )
1803  {
1804  log->Error( AppMsg, "Unable to open file %s: %s",
1805  remoteUrl.GetObfuscatedURL().c_str(), st.ToStr().c_str() );
1806  return st;
1807  }
1808 
1809  StatInfo *info = 0;
1810  uint64_t size = 0;
1811  st = file.Stat( false, info );
1812  if (st.IsOK()) size = info->GetSize();
1813 
1814  if( size < offset )
1815  offset = 0;
1816  else
1817  offset = size - offset;
1818 
1819  uint32_t chunkSize = 1*1024*1024;
1820  char *buffer = new char[chunkSize];
1821  uint32_t bytesRead = 0;
1822  while(1)
1823  {
1824  st = file.Read( offset, chunkSize, buffer, bytesRead );
1825  if( !st.IsOK() )
1826  {
1827  log->Error( AppMsg, "Unable to read from %s: %s",
1828  remoteUrl.GetObfuscatedURL().c_str(), st.ToStr().c_str() );
1829  delete [] buffer;
1830  return st;
1831  }
1832 
1833  offset += bytesRead;
1834  int ret = write( 1, buffer, bytesRead );
1835  if( ret == -1 )
1836  {
1837  log->Error( AppMsg, "Unable to write to stdout: %s",
1838  XrdSysE2T(errno) );
1839  delete [] buffer;
1840  return st;
1841  }
1842 
1843  if( bytesRead < chunkSize )
1844  {
1845  if( !followMode )
1846  break;
1847  sleep(1);
1848  }
1849  }
1850  delete [] buffer;
1851 
1852  XRootDStatus stC = file.Close();
1853 
1854  return XRootDStatus();
1855 }
#define write(a, b, c)
Definition: XrdPosix.hh:121
A file.
Definition: XrdClFile.hh:52
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:125
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:265
XRootDStatus Close(ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:210
XRootDStatus Stat(bool force, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:236
URL representation.
Definition: XrdClURL.hh:31

References XrdCl::AppMsg, BuildPath(), XrdCl::File::Close(), XrdCl::errInvalidAddr, XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::URL::GetObfuscatedURL(), XrdCl::StatInfo::GetSize(), XrdCl::Env::GetString(), XrdCl::URL::GetURL(), XrdCl::Status::IsOK(), XrdCl::File::Open(), XrdCl::File::Read(), XrdCl::OpenFlags::Read, XrdCl::URL::SetPath(), XrdCl::File::Stat(), XrdCl::stError, XrdCl::XRootDStatus::ToStr(), write, and XrdSysE2T().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoTruncate()

XRootDStatus DoTruncate ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 866 of file XrdClFS.cc.

869 {
870  //----------------------------------------------------------------------------
871  // Check up the args
872  //----------------------------------------------------------------------------
873  Log *log = DefaultEnv::GetLog();
874  uint32_t argc = args.size();
875 
876  if( argc != 3 )
877  {
878  log->Error( AppMsg, "Wrong number of arguments." );
880  }
881 
882  std::string fullPath;
883  XRootDStatus pathSt = BuildPath( fullPath, env, args[1], "Truncating" );
884  if( !pathSt.IsOK() )
885  return pathSt;
886 
887  char *result;
888  uint64_t size = ::strtoll( args[2].c_str(), &result, 0 );
889  if( *result != 0 )
890  {
891  log->Error( AppMsg, "Size parameter needs to be an integer" );
893  }
894 
895  //----------------------------------------------------------------------------
896  // Run the query
897  //----------------------------------------------------------------------------
898  XRootDStatus st = fs->Truncate( fullPath, size );
899  if( !st.IsOK() )
900  {
901  log->Error( AppMsg, "Unable truncate %s: %s",
902  fullPath.c_str(),
903  st.ToStr().c_str() );
904  return st;
905  }
906 
907  return XRootDStatus();
908 }
XRootDStatus Truncate(const std::string &path, uint64_t size, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT

References XrdCl::AppMsg, BuildPath(), XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), XrdCl::stError, XrdCl::XRootDStatus::ToStr(), and XrdCl::FileSystem::Truncate().

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoXAttr()

XRootDStatus DoXAttr ( FileSystem *  fs,
Env *  env,
const FSExecutor::CommandParams &  args 
)

Definition at line 1903 of file XrdClFS.cc.

1906 {
1907  //----------------------------------------------------------------------------
1908  // Check up the args
1909  //----------------------------------------------------------------------------
1910  Log *log = DefaultEnv::GetLog();
1911  uint32_t argc = args.size();
1912 
1913  if( argc < 3 )
1914  {
1915  log->Error( AppMsg, "Wrong number of arguments." );
1916  return XRootDStatus( stError, errInvalidArgs );
1917  }
1918 
1919  kXR_char code = 0;
1920  if( args[2] == "set")
1921  code = kXR_fattrSet;
1922  else if( args[2] == "get" )
1923  code = kXR_fattrGet;
1924  else if( args[2] == "del" )
1925  code = kXR_fattrDel;
1926  else if( args[2] == "list" )
1927  code = kXR_fattrList;
1928  else
1929  {
1930  log->Error( AppMsg, "Invalid xattr code." );
1931  return XRootDStatus( stError, errInvalidArgs );
1932  }
1933 
1934  std::string path;
1935  XRootDStatus pathSt = BuildPath( path, env, args[1], "Accessing" );
1936  if( !pathSt.IsOK() )
1937  return pathSt;
1938 
1939  //----------------------------------------------------------------------------
1940  // Issue the xattr operation
1941  //----------------------------------------------------------------------------
1942  XRootDStatus status;
1943  switch( code )
1944  {
1945  case kXR_fattrSet:
1946  {
1947  if( argc != 4 )
1948  {
1949  log->Error( AppMsg, "Wrong number of arguments." );
1950  return XRootDStatus( stError, errInvalidArgs );
1951  }
1952 
1953  std::string key_value = args[3];
1954  size_t pos = key_value.find( '=' );
1955  std::string key = key_value.substr( 0, pos );
1956  std::string value = key_value.substr( pos + 1 );
1957  std::vector<xattr_t> attrs;
1958  attrs.push_back( std::make_tuple( key, value ) );
1959 
1960  std::vector<XAttrStatus> result;
1961  XRootDStatus status = fs->SetXAttr( path, attrs, result );
1962  XAttrStatus xst = status.IsOK() ? result.front() : XAttrStatus( key, status );
1963 
1964  if( !xst.status.IsOK() )
1965  status = xst.status;
1966 
1967  if( !status.IsOK() )
1968  log->Error( AppMsg, "Unable to xattr set %s %s: %s",
1969  key.c_str(), value.c_str(),
1970  status.ToStr().c_str() );
1971  return status;
1972  }
1973 
1974  case kXR_fattrGet:
1975  {
1976  if( argc != 4 )
1977  {
1978  log->Error( AppMsg, "Wrong number of arguments." );
1979  return XRootDStatus( stError, errInvalidArgs );
1980  }
1981 
1982  std::string key = args[3];
1983  std::vector<std::string> attrs;
1984  attrs.push_back( key );
1985 
1986  std::vector<XAttr> result;
1987  XRootDStatus status = fs->GetXAttr( path, attrs, result );
1988  XAttr xattr = status.IsOK() ? result.front() : XAttr( key, status );
1989 
1990  if( !xattr.status.IsOK() )
1991  status = xattr.status;
1992 
1993  if( !status.IsOK() )
1994  log->Error( AppMsg, "Unable to xattr get %s : %s",
1995  key.c_str(),
1996  status.ToStr().c_str() );
1997  else
1998  {
1999  std::cout << "# file: " << path << '\n';
2000  std::cout << xattr.name << "=\"" << xattr.value << "\"\n";
2001  }
2002 
2003  return status;
2004  }
2005 
2006  case kXR_fattrDel:
2007  {
2008  if( argc != 4 )
2009  {
2010  log->Error( AppMsg, "Wrong number of arguments." );
2011  return XRootDStatus( stError, errInvalidArgs );
2012  }
2013 
2014  std::string key = args[3];
2015  std::vector<std::string> attrs;
2016  attrs.push_back( key );
2017 
2018  std::vector<XAttrStatus> result ;
2019  XRootDStatus status = fs->DelXAttr( path, attrs, result );
2020  XAttrStatus xst = status.IsOK() ? result.front() : XAttrStatus( key, status );
2021 
2022  if( !xst.status.IsOK() )
2023  status = xst.status;
2024 
2025  if( !status.IsOK() )
2026  log->Error( AppMsg, "Unable to xattr del %s : %s",
2027  key.c_str(),
2028  status.ToStr().c_str() );
2029  return status;
2030  }
2031 
2032  case kXR_fattrList:
2033  {
2034  if( argc != 3 )
2035  {
2036  log->Error( AppMsg, "Wrong number of arguments." );
2037  return XRootDStatus( stError, errInvalidArgs );
2038  }
2039 
2040  std::vector<XAttr> result;
2041  XRootDStatus status = fs->ListXAttr( path, result );
2042 
2043  if( !status.IsOK() )
2044  log->Error( AppMsg, "Unable to xattr list : %s",
2045  status.ToStr().c_str() );
2046  else
2047  {
2048  std::cout << "# file: " << path << '\n';
2049  auto itr = result.begin();
2050  for( ; itr != result.end(); ++itr )
2051  std::cout << itr->name << "=\"" << itr->value << "\"\n";
2052  }
2053 
2054  return status;
2055  }
2056 
2057  default:
2058  return XRootDStatus( stError, errInvalidAddr );
2059  }
2060 }
@ kXR_fattrDel
Definition: XProtocol.hh:300
@ kXR_fattrSet
Definition: XProtocol.hh:303
@ kXR_fattrList
Definition: XProtocol.hh:302
@ kXR_fattrGet
Definition: XProtocol.hh:301
unsigned char kXR_char
Definition: XPtypes.hh:65
XRootDStatus ListXAttr(const std::string &path, ResponseHandler *handler, time_t timeout=0)
XRootDStatus GetXAttr(const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
XRootDStatus DelXAttr(const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
XRootDStatus SetXAttr(const std::string &path, const std::vector< xattr_t > &attrs, ResponseHandler *handler, time_t timeout=0)
Extended attribute operation status.
Extended attributes with status.

References XrdCl::AppMsg, BuildPath(), XrdCl::FileSystem::DelXAttr(), XrdCl::errInvalidAddr, XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::FileSystem::GetXAttr(), XrdCl::Status::IsOK(), kXR_fattrDel, kXR_fattrGet, kXR_fattrList, kXR_fattrSet, XrdCl::FileSystem::ListXAttr(), XrdCl::XAttrStatus::name, XrdCl::FileSystem::SetXAttr(), XrdCl::XAttrStatus::status, XrdCl::stError, XrdCl::XRootDStatus::ToStr(), and XrdCl::XAttr::value.

Referenced by CreateExecutor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExecuteCommand() [1/2]

int ExecuteCommand ( const URL &  url,
const FSExecutor::CommandParams &  args 
)

Definition at line 2439 of file XrdClFS.cc.

2440 {
2441  FSExecutor *ex = CreateExecutor( url );
2442  ex->GetEnv()->PutInt( "NoCWD", 1 );
2443  int st = ExecuteCommand( ex, args );
2444  delete ex;
2445  return st;
2446 }
FSExecutor * CreateExecutor(const URL &url)
Definition: XrdClFS.cc:2225
int ExecuteCommand(FSExecutor *ex, const FSExecutor::CommandParams &args)
Definition: XrdClFS.cc:2255
Env * GetEnv()
Get the environment.

References CreateExecutor(), ExecuteCommand(), XrdCl::FSExecutor::GetEnv(), and XrdCl::Env::PutInt().

+ Here is the call graph for this function:

◆ ExecuteCommand() [2/2]

int ExecuteCommand ( FSExecutor *  ex,
const FSExecutor::CommandParams &  args 
)

Definition at line 2255 of file XrdClFS.cc.

2256 {
2257  XRootDStatus st = ex->Execute( args );
2258  if( !st.IsOK() )
2259  std::cerr << st.ToStr() << std::endl;
2260  return st.GetShellCode();
2261 }
XRootDStatus Execute(const CommandParams &args)
int GetShellCode() const
Get the status code that may be returned to the shell.
Definition: XrdClStatus.hh:129

References XrdCl::FSExecutor::Execute(), XrdCl::Status::GetShellCode(), XrdCl::Status::IsOK(), and XrdCl::XRootDStatus::ToStr().

Referenced by ExecuteCommand(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExecuteInteractive()

int ExecuteInteractive ( const URL &  url,
bool  noCwd = false 
)

Definition at line 2380 of file XrdClFS.cc.

2381 {
2382  //----------------------------------------------------------------------------
2383  // Set up the environment
2384  //----------------------------------------------------------------------------
2385  std::string historyFile = getenv( "HOME" );
2386  historyFile += "/.xrdquery.history";
2387  rl_bind_key( '\t', rl_insert );
2388  read_history( historyFile.c_str() );
2389  FSExecutor *ex = CreateExecutor( url );
2390 
2391  if( noCwd )
2392  ex->GetEnv()->PutInt( "NoCWD", 1 );
2393 
2394  //----------------------------------------------------------------------------
2395  // Execute the commands
2396  //----------------------------------------------------------------------------
2397  std::string cmdline;
2398  while(1)
2399  {
2400  char *linebuf = 0;
2401  // print new prompt only if the previous line was complete
2402  // (a line is considered not to be complete if a quote has
2403  // been opened but it has not been closed)
2404  linebuf = readline( cmdline.empty() ? BuildPrompt( ex->GetEnv(), url ).c_str() : "> " );
2405  if( !linebuf || !strncmp( linebuf, "exit", 4 ) || !strncmp( linebuf, "quit", 4 ) )
2406  {
2407  std::cout << "Goodbye." << std::endl << std::endl;
2408  break;
2409  }
2410  if( !*linebuf)
2411  {
2412  free( linebuf );
2413  continue;
2414  }
2415  std::vector<std::string> args;
2416  cmdline += linebuf;
2417  free( linebuf );
2418  if (getArguments( args, cmdline ))
2419  {
2420  XRootDStatus st = ex->Execute( args );
2421  add_history( cmdline.c_str() );
2422  cmdline.erase();
2423  if( !st.IsOK() )
2424  std::cerr << st.ToStr() << std::endl;
2425  }
2426  }
2427 
2428  //----------------------------------------------------------------------------
2429  // Cleanup
2430  //----------------------------------------------------------------------------
2431  delete ex;
2432  write_history( historyFile.c_str() );
2433  return 0;
2434 }
int write_history(const char *)
Definition: XrdClFS.cc:2297
void add_history(const char *)
Definition: XrdClFS.cc:2282
void rl_bind_key(char, uint16_t)
Definition: XrdClFS.cc:2286
std::string BuildPrompt(Env *env, const URL &url)
Definition: XrdClFS.cc:2306
bool getArguments(std::vector< std::string > &result, const std::string &input)
Definition: XrdClFS.cc:2322
int read_history(const char *)
Definition: XrdClFS.cc:2292
char * readline(const char *prompt)
Definition: XrdClFS.cc:2267
uint16_t rl_insert
Definition: XrdClFS.cc:2290

References add_history(), BuildPrompt(), CreateExecutor(), XrdCl::FSExecutor::Execute(), getArguments(), XrdCl::FSExecutor::GetEnv(), XrdCl::Status::IsOK(), XrdCl::Env::PutInt(), read_history(), readline(), rl_bind_key(), rl_insert, XrdCl::XRootDStatus::ToStr(), and write_history().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getArguments()

bool getArguments ( std::vector< std::string > &  result,
const std::string &  input 
)

parse command line

@ result : command parameters @ input : string containing the command line @ return : true if the command has been completed, false otherwise

Definition at line 2322 of file XrdClFS.cc.

2323 {
2324  // the delimiter (space in the case of command line)
2325  static const char delimiter = ' ';
2326  // two types of quotes: single and double quotes
2327  const char singleQuote = '\'', doubleQuote = '\"';
2328  // if the current character of the command has been
2329  // quoted 'currentQuote' holds the type of quote,
2330  // otherwise it holds the null character
2331  char currentQuote = '\0';
2332 
2333  std::string tmp;
2334  for (std::string::const_iterator it = input.begin (); it != input.end (); ++it)
2335  {
2336  // if we encountered a quote character ...
2337  if (*it == singleQuote || *it == doubleQuote)
2338  {
2339  // if we are not within quoted text ...
2340  if (!currentQuote)
2341  {
2342  currentQuote = *it; // set the type of quote
2343  continue; // and continue, the quote character itself is not a part of the parameter
2344  }
2345  // otherwise if it is the closing quote character ...
2346  else if (currentQuote == *it)
2347  {
2348  currentQuote = '\0'; // reset the current quote type
2349  continue; // and continue, the quote character itself is not a part of the parameter
2350  }
2351  }
2352  // if we are within quoted text or the character is not a delimiter ...
2353  if (currentQuote || *it != delimiter)
2354  {
2355  // concatenate it
2356  tmp += *it;
2357  }
2358  else
2359  {
2360  // otherwise add a parameter and erase the tmp string
2361  if (!tmp.empty ())
2362  {
2363  result.push_back(tmp);
2364  tmp.erase ();
2365  }
2366  }
2367  }
2368  // if the there are some remainders of the command add them
2369  if (!tmp.empty())
2370  {
2371  result.push_back(tmp);
2372  }
2373  // return true if the quotation has been closed
2374  return currentQuote == '\0';
2375 }

Referenced by ExecuteInteractive().

+ Here is the caller graph for this function:

◆ getSizeStr()

std::string getSizeStr ( uint64_t  size,
bool  human,
uint64_t  base 
)

Definition at line 411 of file XrdClFS.cc.

411  {
412  std::ostringstream oss;
413  if (!human) {
414  oss << size;
415  } else {
416  oss << XrdOucUtils::genHumanSize(size,base);
417  }
418  return oss.str();
419 }
static std::string genHumanSize(size_t size, uint64_t base)
Definition: XrdOucUtils.cc:462

References XrdOucUtils::genHumanSize().

Referenced by DoLS(), and PrintDirListStatInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 2451 of file XrdClFS.cc.

2452 {
2454  enum { NoCwdOption = 256 };
2455  static const option options[] = {
2456  { "ipv4", no_argument, 0, '4' },
2457  { "ipv6", no_argument, 0, '6' },
2458  { "debug", required_argument, 0, 'd' },
2459  { "help", no_argument, 0, 'h' },
2460  { "no-cwd", no_argument, 0, NoCwdOption },
2461  { 0, 0, 0, 0 }
2462  };
2463 
2464  bool noCwd = false;
2465  int debugLevel = 0;
2466  std::string networkStack;
2467  opterr = 0;
2468  int option = 0;
2469  while( (option = getopt_long( argc, argv, "+46d:h", options, 0 )) != -1 )
2470  {
2471  switch( option )
2472  {
2473  case '4':
2474  if( networkStack == "IPv6" )
2475  {
2476  std::cerr << "xrdfs: -4 and -6 are mutually exclusive" << std::endl;
2477  return 1;
2478  }
2479  networkStack = "IPv4";
2480  break;
2481  case '6':
2482  if( networkStack == "IPv4" )
2483  {
2484  std::cerr << "xrdfs: -4 and -6 are mutually exclusive" << std::endl;
2485  return 1;
2486  }
2487  networkStack = "IPv6";
2488  break;
2489  case 'd':
2490  {
2491  char *end = 0;
2492  long level = std::strtol( optarg, &end, 10 );
2493  if( !*optarg || *end || level < 0 || level > 3 )
2494  {
2495  std::cerr << "xrdfs: invalid debug level '" << optarg
2496  << "' (expected 0-3)" << std::endl;
2497  return 1;
2498  }
2499  debugLevel = static_cast<int>( level );
2500  break;
2501  }
2502  case 'h':
2503  PrintHelp( 0, 0, params );
2504  return 0;
2505  case NoCwdOption:
2506  noCwd = true;
2507  break;
2508  default:
2509  PrintHelp( 0, 0, params );
2510  return 1;
2511  }
2512  }
2513 
2514  if( !networkStack.empty() )
2515  DefaultEnv::GetEnv()->PutString( "NetworkStack", networkStack );
2516 
2517  if( debugLevel )
2518  {
2519  Log *log = DefaultEnv::GetLog();
2520  if( debugLevel == 1 )
2521  log->SetLevel( Log::InfoMsg );
2522  else if( debugLevel == 2 )
2523  log->SetLevel( Log::DebugMsg );
2524  else
2525  log->SetLevel( Log::DumpMsg );
2526  }
2527 
2528  if( optind == argc )
2529  {
2530  PrintHelp( 0, 0, params );
2531  return 1;
2532  }
2533 
2534  FSExecutor::CommandParams arguments( argv + optind, argv + argc );
2535  URL url;
2536  std::string error;
2537  URLCommandResult result = ParseURLCommand( arguments, url, error );
2538  if( result == InvalidURLCommand )
2539  {
2540  std::cerr << "xrdfs: " << error << std::endl;
2541  return 1;
2542  }
2543 
2544  if( result == ValidURLCommand )
2545  return ExecuteCommand( url, arguments );
2546 
2547  url = URL( arguments[0] );
2548  if( !url.IsValid() )
2549  {
2550  PrintHelp( 0, 0, params );
2551  return 1;
2552  }
2553 
2554  if( arguments.size() == 1 )
2555  return ExecuteInteractive( url, noCwd );
2556 
2557  arguments.erase( arguments.begin() );
2558 
2559  // Raw query parameters are implementation-dependent and may themselves look
2560  // like URLs, so query intentionally remains server-first only.
2561  if( arguments[0] != "query" )
2562  {
2563  URL inferredEndpoint;
2564  result = ParseURLCommand( arguments, inferredEndpoint, error );
2565  if( result == InvalidURLCommand )
2566  {
2567  std::cerr << "xrdfs: " << error << std::endl;
2568  return 1;
2569  }
2570 
2571  if( result == ValidURLCommand )
2572  {
2573  std::cerr << "xrdfs: cannot mix a leading endpoint with full URL "
2574  "operands; use either server-first or command-first syntax"
2575  << std::endl;
2576  return 1;
2577  }
2578  }
2579 
2580  return ExecuteCommand( url, arguments );
2581 }
int ExecuteInteractive(const URL &url, bool noCwd=false)
Definition: XrdClFS.cc:2380
int optind
std::vector< std::string > CommandParams
Definition of command argument list.
void SetLevel(LogLevel level)
Set the level of the messages that should be sent to the destination.
Definition: XrdClLog.hh:193
bool IsValid() const
Is the url valid.
Definition: XrdClURL.cc:428

References XrdCl::Log::DebugMsg, XrdCl::Log::DumpMsg, ExecuteCommand(), ExecuteInteractive(), XrdCl::DefaultEnv::GetEnv(), XrdCl::DefaultEnv::GetLog(), XrdCl::Log::InfoMsg, XrdCl::URL::IsValid(), optind, PrintHelp(), XrdCl::Env::PutString(), and XrdCl::Log::SetLevel().

+ Here is the call graph for this function:

◆ nbDigits()

uint32_t nbDigits ( uint64_t  nb)

Definition at line 405 of file XrdClFS.cc.

406 {
407  if( nb == 0 ) return 1;
408  return uint32_t( log10( double(nb) ) + 1);
409 }

Referenced by DoLS().

+ Here is the caller graph for this function:

◆ PrintDirListStatInfo()

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 
)

Definition at line 421 of file XrdClFS.cc.

422 {
423  if( info->ExtendedFormat() )
424  {
425  if( info->TestFlags( StatInfo::IsDir ) )
426  std::cout << "d";
427  else
428  std::cout << "-";
429  std::cout << info->GetModeAsOctString();
430 
431  std::cout << " " << std::setw( ownerwidth ) << info->GetOwner();
432  std::cout << " " << std::setw( groupwidth ) << info->GetGroup();
433  std::cout << " " << std::setw( sizewidth ) << getSizeStr(info->GetSize(),human, base);
434  if( hascks && info->HasChecksum() )
435  std::cout << " " << std::setw( sizewidth ) << info->GetChecksum();
436  std::cout << " " << info->GetModTimeAsString() << " ";
437  }
438  else
439  {
440  if( info->TestFlags( StatInfo::IsDir ) )
441  std::cout << "d";
442  else
443  std::cout << "-";
444 
445  if( info->TestFlags( StatInfo::IsReadable ) )
446  std::cout << "r";
447  else
448  std::cout << "-";
449 
450  if( info->TestFlags( StatInfo::IsWritable ) )
451  std::cout << "w";
452  else
453  std::cout << "-";
454 
455  if( info->TestFlags( StatInfo::XBitSet ) )
456  std::cout << "x";
457  else
458  std::cout << "-";
459 
460  std::cout << " " << info->GetModTimeAsString();
461 
462  uint64_t size = info->GetSize();
463  std::string displaySize = getSizeStr(size,human,base);
464  int width = displaySize.size() + 2;
465  if (width < 12) {
466  width = 12;
467  }
468  std::cout << std::setw( width ) << displaySize << " ";
469  }
470 }
std::string GetModTimeAsString() const
Get modification time.
bool HasChecksum() const
Has checksum.
const std::string GetModeAsOctString() const
Get mode.
bool ExtendedFormat() const
Has extended stat information.

References XrdCl::StatInfo::ExtendedFormat(), XrdCl::StatInfo::GetChecksum(), XrdCl::StatInfo::GetGroup(), XrdCl::StatInfo::GetModeAsOctString(), XrdCl::StatInfo::GetModTimeAsString(), XrdCl::StatInfo::GetOwner(), XrdCl::StatInfo::GetSize(), getSizeStr(), XrdCl::StatInfo::HasChecksum(), XrdCl::StatInfo::IsDir, XrdCl::StatInfo::IsReadable, XrdCl::StatInfo::IsWritable, XrdCl::StatInfo::TestFlags(), and XrdCl::StatInfo::XBitSet.

Referenced by DoLS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintHelp()

XRootDStatus PrintHelp ( FileSystem *  ,
Env *  ,
const FSExecutor::CommandParams &   
)

Definition at line 2065 of file XrdClFS.cc.

2067 {
2068  printf( "Usage:\n" );
2069  printf( " xrdfs [options] host[:port] - interactive mode\n" );
2070  printf( " xrdfs [options] host[:port] command args - server-first batch\n" );
2071  printf( " xrdfs [options] command args-with-URLs - command-first batch\n\n" );
2072 
2073  printf( "The two batch forms cannot be mixed.\n\n" );
2074 
2075  printf( "Available options:\n\n" );
2076 
2077  printf( " -4, --ipv4 use only the IPv4 network stack\n" );
2078  printf( " -6, --ipv6 use only the IPv6 network stack\n" );
2079  printf( " -d, --debug <level> set debug level: 0 off, 1 low, 2 medium,\n" );
2080  printf( " 3 high\n" );
2081  printf( " -h, --help show this help\n" );
2082  printf( " --no-cwd do not preset a CWD in interactive mode\n\n" );
2083 
2084  printf( "Available commands:\n\n" );
2085 
2086  printf( " exit\n" );
2087  printf( " Exits from the program.\n\n" );
2088 
2089  printf( " help\n" );
2090  printf( " This help screen.\n\n" );
2091 
2092  printf( " cache {evict | fevict} <path>\n" );
2093  printf( " Evict a file from a cache if not in use; while fevict\n" );
2094  printf( " forcibly evicts the file causing any current uses of the\n" );
2095  printf( " file to get read failures on a subsequent read\n\n" );
2096 
2097  printf( " cd <path>\n" );
2098  printf( " Change the current working directory\n\n" );
2099 
2100  printf( " chmod <path> <user><group><other>\n" );
2101  printf( " Modify permissions. Permission string example:\n" );
2102  printf( " rwxr-x--x\n\n" );
2103 
2104  printf( " ls [-l] [-u] [-R] [-D] [-Z] [-C] [dirname]\n" );
2105  printf( " Get directory listing.\n" );
2106  printf( " -l stat every entry and print long listing\n" );
2107  printf( " -u print paths as URLs\n" );
2108  printf( " -R list subdirectories recursively\n" );
2109  printf( " -D show duplicate entries\n" );
2110  printf( " -Z if a ZIP archive list its content\n" );
2111  printf( " -C checksum every entry\n\n" );
2112 
2113  printf( " locate [-n] [-r] [-d] [-m] [-i] [-p] <path>\n" );
2114  printf( " Get the locations of the path.\n" );
2115  printf( " -r refresh, don't use cached locations\n" );
2116  printf( " -n make the server return the response immediately even\n" );
2117  printf( " though it may be incomplete\n" );
2118  printf( " -d do a recursive (deep) locate\n" );
2119  printf( " -m|-h prefer host names to IP addresses\n" );
2120  printf( " -i ignore network dependencies\n" );
2121  printf( " -p be passive: ignore tried/triedrc cgi opaque info\n\n" );
2122 
2123  printf( " mkdir [-p] [-m<user><group><other>] <dirname>\n" );
2124  printf( " Creates a directory/tree of directories.\n\n" );
2125 
2126  printf( " mv <path1> <path2>\n" );
2127  printf( " Move path1 to path2 locally on the same server.\n\n" );
2128 
2129  printf( " stat [-q query] <path>\n" );
2130  printf( " Get info about the file or directory.\n" );
2131  printf( " -q query optional flag query parameter that makes\n" );
2132  printf( " xrdfs return error code to the shell if the\n" );
2133  printf( " requested flag combination is not present;\n" );
2134  printf( " flags may be combined together using '|' or '&'\n" );
2135  printf( " Available flags:\n" );
2136  printf( " XBitSet, IsDir, Other, Offline, POSCPending,\n" );
2137  printf( " IsReadable, IsWritable\n\n" );
2138 
2139  printf( " statvfs <path>\n" );
2140  printf( " Get info about a virtual file system.\n\n" );
2141 
2142  printf( " query <code> <parameters>\n" );
2143  printf( " Obtain server information. Query codes:\n\n" );
2144 
2145  printf( " config <what> Server configuration; <what> is\n" );
2146  printf( " one of the following:\n" );
2147  printf( " bind_max - the maximum number of parallel streams\n" );
2148  printf( " chksum - the supported checksum\n" );
2149  printf( " cms - the status of the cmsd\n" );
2150  printf( " pio_max - maximum number of parallel I/O requests\n" );
2151  printf( " readv_ior_max - maximum size of a readv element\n" );
2152  printf( " readv_iov_max - maximum number of readv entries\n" );
2153  printf( " role - the role in a cluster\n" );
2154  printf( " sitename - the site name\n" );
2155  printf( " tpc - support for third party copies\n" );
2156  printf( " version - the version of the server\n" );
2157  printf( " wan_port - the port to use for wan copies\n" );
2158  printf( " wan_window - the wan_port window size\n" );
2159  printf( " window - the tcp window size\n" );
2160  printf( " checksumcancel <path> File checksum cancellation\n" );
2161  printf( " checksum <path> File checksum\n" );
2162  printf( " opaque <arg> Implementation dependent\n" );
2163  printf( " opaquefile <arg> Implementation dependent\n" );
2164  printf( " space <space> Logical space stats\n" );
2165  printf( " stats <what> Server stats; <what> is a list\n" );
2166  printf( " of letters indicating information\n");
2167  printf( " to be returned:\n" );
2168  printf( " a - all statistics\n" );
2169  printf( " p - protocol statistics\n" );
2170  printf( " b - buffer usage statistics\n" );
2171  printf( " s - scheduling statistics\n" );
2172  printf( " d - device polling statistics\n" );
2173  printf( " u - usage statistics\n" );
2174  printf( " i - server identification\n" );
2175  printf( " z - synchronized statistics\n" );
2176  printf( " l - connection statistics\n" );
2177  printf( " xattr <path> Extended attributes\n" );
2178  printf( " prepare <reqid> [filenames] Prepare request status\n\n" );
2179 
2180  printf( " rm <filename>\n" );
2181  printf( " Remove a file.\n\n" );
2182 
2183  printf( " rmdir <dirname>\n" );
2184  printf( " Remove a directory.\n\n" );
2185 
2186  printf( " truncate <filename> <length>\n" );
2187  printf( " Truncate a file.\n\n" );
2188 
2189  printf( " prepare [-c] [-f] [-s] [-w] [-e] [-p priority] [-a requestid] filenames\n" );
2190  printf( " Prepare one or more files for access.\n" );
2191  printf( " -c co-locate staged files if possible\n" );
2192  printf( " -f refresh file access time even if the location is known\n" );
2193  printf( " -s stage the files to disk if they are not online\n" );
2194  printf( " -w the files will be accessed for modification\n" );
2195  printf( " -p priority of the request, 0 (lowest) - 3 (highest)\n" );
2196  printf( " -a abort stage request\n" );
2197  printf( " -e evict the file from disk cache\n\n" );
2198 
2199  printf( " cat [-o local file] files\n" );
2200  printf( " Print contents of one or more files to stdout.\n" );
2201  printf( " -o print to the specified local file\n\n" );
2202 
2203  printf( " tail [-c bytes] [-f] file\n" );
2204  printf( " Output last part of files to stdout.\n" );
2205  printf( " -c num_bytes out last num_bytes\n" );
2206  printf( " -f output appended data as file grows\n\n" );
2207 
2208  printf( " spaceinfo path\n" );
2209  printf( " Get space statistics for given path.\n\n" );
2210 
2211  printf( " xattr <path> <code> <params> \n" );
2212  printf( " Operation on extended attributes. Codes:\n\n" );
2213  printf( " set <attr> Set extended attribute; <attr> is\n" );
2214  printf( " string of form name=value\n" );
2215  printf( " get <name> Get extended attribute\n" );
2216  printf( " del <name> Delete extended attribute\n" );
2217  printf( " list List extended attributes\n\n" );
2218 
2219  return XRootDStatus();
2220 }

Referenced by CreateExecutor(), and main().

+ Here is the caller graph for this function:

◆ ProcessStatQuery()

XRootDStatus ProcessStatQuery ( StatInfo &  info,
const std::string &  query 
)

Definition at line 1089 of file XrdClFS.cc.

1090 {
1091  Log *log = DefaultEnv::GetLog();
1092 
1093  //----------------------------------------------------------------------------
1094  // Process the query
1095  //----------------------------------------------------------------------------
1096  bool isOrQuery = false;
1097  bool status = true;
1098  if( query.find( '|' ) != std::string::npos )
1099  {
1100  isOrQuery = true;
1101  status = false;
1102  }
1103  std::vector<std::string> queryFlags;
1104  if( isOrQuery )
1105  Utils::splitString( queryFlags, query, "|" );
1106  else
1107  Utils::splitString( queryFlags, query, "&" );
1108 
1109  //----------------------------------------------------------------------------
1110  // Initialize flag translation map and check the input flags
1111  //----------------------------------------------------------------------------
1112  std::map<std::string, StatInfo::Flags> flagMap;
1113  flagMap["XBitSet"] = StatInfo::XBitSet;
1114  flagMap["IsDir"] = StatInfo::IsDir;
1115  flagMap["Other"] = StatInfo::Other;
1116  flagMap["Offline"] = StatInfo::Offline;
1117  flagMap["POSCPending"] = StatInfo::POSCPending;
1118  flagMap["IsReadable"] = StatInfo::IsReadable;
1119  flagMap["IsWritable"] = StatInfo::IsWritable;
1120  flagMap["BackUpExists"] = StatInfo::BackUpExists;
1121 
1122  std::vector<std::string>::iterator it;
1123  for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1124  if( flagMap.find( *it ) == flagMap.end() )
1125  {
1126  log->Error( AppMsg, "Flag '%s' is not recognized.", it->c_str() );
1127  return XRootDStatus( stError, errInvalidArgs );
1128  }
1129 
1130  //----------------------------------------------------------------------------
1131  // Process the query
1132  //----------------------------------------------------------------------------
1133  if( isOrQuery )
1134  {
1135  for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1136  if( info.TestFlags( flagMap[*it] ) )
1137  return XRootDStatus();
1138  }
1139  else
1140  {
1141  for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1142  if( !info.TestFlags( flagMap[*it] ) )
1144  }
1145 
1146  if( status )
1147  return XRootDStatus();
1149 }
const uint16_t errResponseNegative
Query response was negative.
Definition: XrdClStatus.hh:109

References XrdCl::AppMsg, XrdCl::StatInfo::BackUpExists, XrdCl::errInvalidArgs, XrdCl::Log::Error(), XrdCl::errResponseNegative, XrdCl::DefaultEnv::GetLog(), XrdCl::StatInfo::IsDir, XrdCl::StatInfo::IsReadable, XrdCl::StatInfo::IsWritable, XrdCl::StatInfo::Offline, XrdCl::StatInfo::Other, XrdCl::StatInfo::POSCPending, XrdCl::Utils::splitString(), XrdCl::stError, XrdCl::StatInfo::TestFlags(), and XrdCl::StatInfo::XBitSet.

Referenced by DoStat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_history()

int read_history ( const char *  )

Definition at line 2292 of file XrdClFS.cc.

2293 {
2294  return 0;
2295 }

Referenced by ExecuteInteractive().

+ Here is the caller graph for this function:

◆ readline()

char* readline ( const char *  prompt)

Definition at line 2267 of file XrdClFS.cc.

2268 {
2269  std::cout << prompt << std::flush;
2270  std::string input;
2271  std::getline( std::cin, input );
2272 
2273  if( !std::cin.good() )
2274  return 0;
2275 
2276  char *linebuf = (char *)malloc( input.size()+1 );
2277  strncpy( linebuf, input.c_str(), input.size()+1 );
2278 
2279  return linebuf;
2280 }
void getline(uchar *buff, int blen)

References getline().

Referenced by ExecuteInteractive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rl_bind_key()

void rl_bind_key ( char  ,
uint16_t   
)

Definition at line 2286 of file XrdClFS.cc.

2287 {
2288 }

Referenced by ExecuteInteractive().

+ Here is the caller graph for this function:

◆ write_history()

int write_history ( const char *  )

Definition at line 2297 of file XrdClFS.cc.

2298 {
2299  return 0;
2300 }

Referenced by ExecuteInteractive().

+ Here is the caller graph for this function:

Variable Documentation

◆ rl_insert

uint16_t rl_insert = 0

Definition at line 2290 of file XrdClFS.cc.

Referenced by ExecuteInteractive().