Manage the checksum calc objects.
More...
#include <XrdClCheckSumManager.hh>
Manage the checksum calc objects.
Definition at line 41 of file XrdClCheckSumManager.hh.
◆ CheckSumManager()
XrdCl::CheckSumManager::CheckSumManager |
( |
| ) |
|
◆ ~CheckSumManager()
XrdCl::CheckSumManager::~CheckSumManager |
( |
| ) |
|
|
virtual |
Definition at line 59 of file XrdClCheckSumManager.cc.
60 {
61 CalcMap::iterator it;
62 for( it = pCalculators.begin(); it != pCalculators.end(); ++it )
63 delete it->second;
64 delete pLoader;
65 }
◆ Calculate()
bool XrdCl::CheckSumManager::Calculate |
( |
XrdCksData & | result, |
|
|
const std::string & | algName, |
|
|
const std::string & | filePath ) |
Calculate a checksum of for a given file.
Definition at line 100 of file XrdClCheckSumManager.cc.
103 {
104
105
106
109
110 if( !calc )
111 {
112 log->Error(
UtilityMsg,
"Unable to get a calculator for %s",
113 algName.c_str() );
114 return false;
115 }
116 std::unique_ptr<XrdCksCalc> calcPtr( calc );
117
118
119
120
121 log->Debug(
UtilityMsg,
"Opening %s for reading (checksum calc)",
122 filePath.c_str() );
123
124 int fd =
open( filePath.c_str(), O_RDONLY );
125 if( fd == -1 )
126 {
127 log->Error(
UtilityMsg,
"Unable to open %s: %s", filePath.c_str(),
129 return false;
130 }
131
132
133
134
135 const uint32_t buffSize = 2*1024*1024;
136 char *buffer = new char[buffSize];
137 int64_t bytesRead = 0;
138
139 while( (bytesRead =
read( fd, buffer, buffSize )) )
140 {
141 if( bytesRead == -1 )
142 {
143 log->Error(
UtilityMsg,
"Unable read from %s: %s", filePath.c_str(),
146 delete [] buffer;
147 return false;
148 }
149 calc->
Update( buffer, bytesRead );
150 }
151
152 int size;
154 result.
Set( (
void*)calc->
Final(), size );
155
156
157
158
159 delete [] buffer;
161 return true;
162 }
const char * XrdSysE2T(int errcode)
virtual void Update(const char *Buff, int BLen)=0
virtual const char * Type(int &csSize)=0
int Set(const char *csName)
XrdCksCalc * GetCalculator(const std::string &algName)
static Log * GetLog()
Get default log.
const uint64_t UtilityMsg
References close, XrdCl::Log::Debug(), XrdCl::Log::Error(), XrdCksCalc::Final(), GetCalculator(), XrdCl::DefaultEnv::GetLog(), open, read, XrdCksData::Set(), XrdCksCalc::Type(), XrdCksCalc::Update(), XrdCl::UtilityMsg, and XrdSysE2T().
Referenced by XrdCl::Utils::GetLocalCheckSum().
◆ GetCalculator()
XrdCksCalc * XrdCl::CheckSumManager::GetCalculator |
( |
const std::string & | algName | ) |
|
Get the check sum calc object for a given checksum type
- Parameters
-
algName | name of the checksumming algorithm |
- Returns
- the appropriate calc object (must be deleted by the user) or 0 if a calculator cannot be obtained
Definition at line 70 of file XrdClCheckSumManager.cc.
71 {
74 CalcMap::iterator it = pCalculators.find( algName );
75 if( it == pCalculators.end() )
76 {
77 char *errBuff = new char[1024];
78 log->Dump(
UtilityMsg,
"Attempting to load a calculator for: %s",
79 algName.c_str() );
80 XrdCksCalc *c = pLoader->
Load( algName.c_str(),
"", errBuff, 1024 );
81 if( !c )
82 {
83 log->Error(
UtilityMsg,
"Unable to load %s calculator: %s",
84 algName.c_str(), errBuff );
85 delete [] errBuff;
86 return 0;
87
88 }
89 delete [] errBuff;
90
91 pCalculators[algName] = c;
93 }
94 return it->second->
New();;
95 }
virtual XrdCksCalc * New()=0
XrdCksCalc * Load(const char *csName, const char *csParms=0, char *eBuff=0, int eBlen=0, bool orig=false)
References XrdCl::Log::Dump(), XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCksLoader::Load(), XrdCksCalc::New(), and XrdCl::UtilityMsg.
Referenced by Calculate(), and XrdCl::CheckSumHelper::Initialize().
The documentation for this class was generated from the following files: