//------------------------------------------------------------------------------ // Copyright (c) 2011-2017 by European Organization for Nuclear Research (CERN) // Author: Krzysztof Jamrog , // Michal Simon //------------------------------------------------------------------------------ // This file is part of the XRootD software suite. // // XRootD is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // XRootD is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with XRootD. If not, see . // // In applying this licence, CERN does not waive the privileges and immunities // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. //------------------------------------------------------------------------------ #ifndef __XRD_CL_FILE_SYSTEM_OPERATIONS_HH__ #define __XRD_CL_FILE_SYSTEM_OPERATIONS_HH__ #include "XrdCl/XrdClFileSystem.hh" #include "XrdCl/XrdClOperations.hh" #include "XrdCl/XrdClOperationHandlers.hh" namespace XrdCl { //---------------------------------------------------------------------------- //! Base class for all file system releated operations //! //! @arg Derived : the class that derives from this template (CRTP) //! @arg HasHndl : true if operation has a handler, false otherwise //! @arg Args : operation arguments //---------------------------------------------------------------------------- template class Derived, bool HasHndl, typename Response, typename ... Args> class FileSystemOperation: public ConcreteOperation { template class, bool, typename, typename ...> friend class FileSystemOperation; public: //------------------------------------------------------------------------ //! Constructor //! //! @param fs : file system on which the operation will be performed //! @param args : file operation arguments //------------------------------------------------------------------------ FileSystemOperation( FileSystem *fs, Args... args): ConcreteOperation( std::move( args )... ), filesystem(fs) { } //------------------------------------------------------------------------ //! Constructor //! //! @param fs : file system on which the operation will be performed //! @param args : file operation arguments //------------------------------------------------------------------------ FileSystemOperation( FileSystem &fs, Args... args): FileSystemOperation( &fs, std::move( args )... ) { } //------------------------------------------------------------------------ //! Move constructor from other states //! //! @arg from : state from which the object is being converted //! //! @param op : the object that is being converted //------------------------------------------------------------------------ template FileSystemOperation( FileSystemOperation && op ): ConcreteOperation( std::move( op ) ), filesystem( op.filesystem ) { } //------------------------------------------------------------------------ //! Destructor //------------------------------------------------------------------------ virtual ~FileSystemOperation() { } protected: //------------------------------------------------------------------------ //! The file system object itself. //------------------------------------------------------------------------ FileSystem *filesystem; }; //---------------------------------------------------------------------------- //! Locate operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class LocateImpl: public FileSystemOperation, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg, FlagsArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Locate"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); OpenFlags::Flags flags = std::get( this->args ).Get(); return this->filesystem->Locate( path, flags, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef LocateImpl Locate; //---------------------------------------------------------------------------- //! DeepLocate operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class DeepLocateImpl: public FileSystemOperation, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg, FlagsArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "DeepLocate"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); OpenFlags::Flags flags = std::get( this->args ).Get(); return this->filesystem->DeepLocate( path, flags, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef DeepLocateImpl DeepLocate; //---------------------------------------------------------------------------- //! Mv operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class MvImpl: public FileSystemOperation, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { SourceArg, DestArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Mv"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string source = std::get( this->args ).Get(); std::string dest = std::get( this->args ).Get(); return this->filesystem->Mv( source, dest, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef MvImpl Mv; //---------------------------------------------------------------------------- //! Query operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class QueryImpl: public FileSystemOperation, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { QueryCodeArg, BufferArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Query"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { QueryCode::Code queryCode = std::get( this->args ).Get(); const Buffer buffer( std::get( this->args ).Get() ); return this->filesystem->Query( queryCode, buffer, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef QueryImpl Query; //---------------------------------------------------------------------------- //! Truncate operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class TruncateFsImpl: public FileSystemOperation, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg, SizeArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Truncate"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); uint64_t size = std::get( this->args ).Get(); return this->filesystem->Truncate( path, size, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; TruncateFsImpl Truncate( FileSystem *fs, Arg path, Arg size ) { return TruncateFsImpl( fs, std::move( path ), std::move( size ) ); } TruncateFsImpl Truncate( FileSystem &fs, Arg path, Arg size ) { return TruncateFsImpl( fs, std::move( path ), std::move( size ) ); } //---------------------------------------------------------------------------- //! Rm operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class RmImpl: public FileSystemOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Rm"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); return this->filesystem->Rm( path, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef RmImpl Rm; //---------------------------------------------------------------------------- //! MkDir operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class MkDirImpl: public FileSystemOperation, Arg, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg, Arg, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg, FlagsArg, ModeArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "MkDir"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); MkDirFlags::Flags flags = std::get( this->args ).Get(); Access::Mode mode = std::get( this->args ).Get(); return this->filesystem->MkDir( path, flags, mode, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef MkDirImpl MkDir; //---------------------------------------------------------------------------- //! RmDir operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class RmDirImpl: public FileSystemOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "RmDir"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); return this->filesystem->RmDir( path, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef RmDirImpl RmDir; //---------------------------------------------------------------------------- //! ChMod operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class ChModImpl: public FileSystemOperation, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg, ModeArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "ChMod"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); Access::Mode mode = std::get( this->args ).Get(); return this->filesystem->ChMod( path, mode, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef ChModImpl ChMod; //---------------------------------------------------------------------------- //! Ping operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class PingImpl: public FileSystemOperation> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation>::FileSystemOperation; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Ping"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { return this->filesystem->Ping( this->handler.get() ); } }; typedef PingImpl Ping; //---------------------------------------------------------------------------- //! Stat operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class StatFsImpl: public FileSystemOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Stat"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); return this->filesystem->RmDir( path, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; StatFsImpl Stat( FileSystem *fs, Arg path ) { return StatFsImpl( fs, std::move( path ) ); } StatFsImpl Stat( FileSystem &fs, Arg path ) { return StatFsImpl( fs, std::move( path ) ); } //---------------------------------------------------------------------------- //! StatVS operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class StatVFSImpl: public FileSystemOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "StatVFS"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); return this->filesystem->StatVFS( path, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef StatVFSImpl StatVFS; //---------------------------------------------------------------------------- //! Protocol operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class ProtocolImpl: public FileSystemOperation> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation>::FileSystemOperation; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Protocol"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { return this->filesystem->Protocol( this->handler.get() ); } }; typedef ProtocolImpl Protocol; //---------------------------------------------------------------------------- //! DirList operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class DirListImpl: public FileSystemOperation, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { PathArg, FlagsArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "DirList"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string path = std::get( this->args ).Get(); DirListFlags::Flags flags = std::get( this->args ).Get(); return this->filesystem->DirList( path, flags, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef DirListImpl DirList; //---------------------------------------------------------------------------- //! SendInfo operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class SendInfoImpl: public FileSystemOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { InfoArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "SendInfo"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::string info = std::get( this->args ).Get(); return this->filesystem->SendInfo( info, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef SendInfoImpl SendInfo; //---------------------------------------------------------------------------- //! Prepare operation (@see FileSystemOperation) //---------------------------------------------------------------------------- template class PrepareImpl: public FileSystemOperation, Arg>, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileSystemOperation (@see FileSystemOperation) //------------------------------------------------------------------------ using FileSystemOperation, Arg>, Arg, Arg>::FileSystemOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { FileListArg, FlagsArg, PriorityArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Prepare"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl() { try { std::vector fileList = std::get( this->args ).Get(); PrepareFlags::Flags flags = std::get( this->args ).Get(); uint8_t priority = std::get( this->args ).Get(); return this->filesystem->Prepare( fileList, flags, priority, this->handler.get() ); } catch( const PipelineException& ex ) { return ex.GetError(); } catch( const std::exception& ex ) { return XRootDStatus( stError, ex.what() ); } } }; typedef PrepareImpl Prepare; } #endif // __XRD_CL_FILE_SYSTEM_OPERATIONS_HH__