Commit 72363ab6 authored by Daniele Kruse's avatar Daniele Kruse
Browse files

Fixed checksum problem

parent 3e7f0561
......@@ -76,9 +76,9 @@ std::string cta::Checksum::str() const {
if(0 < arraySize) {
const auto bytes = m_byteArray.getBytes();
oss << "0x" << std::hex;
oss << "0x";
for(uint32_t i = 0; i < arraySize; i++) {
oss << bytes[i];
oss << std::hex << bytes[i];
}
}
......
......@@ -44,7 +44,7 @@ struct NameServerTapeFile {
/**
* The copy number of the tape file where copy numbers start from 1.
* Please note that copy number 0 is an ivalid copy number.
* Please note that copy number 0 is an invalid copy number.
*/
uint16_t copyNb;
......
......@@ -54,6 +54,27 @@ void cta::MockNameServer::assertFsDirExists(const std::string &path) const {
}
}
//------------------------------------------------------------------------------
// assertFsFileExists
//------------------------------------------------------------------------------
void cta::MockNameServer::assertFsFileExists(const std::string &path) const {
struct stat statResult;
if(::stat(path.c_str(), &statResult)) {
const int savedErrno = errno;
std::ostringstream msg;
msg << __FUNCTION__ << " - " << path << " stat error. Reason: " <<
Utils::errnoToString(savedErrno);
throw(exception::Exception(msg.str()));
}
if(!S_ISREG(statResult.st_mode)) {
std::ostringstream msg;
msg << "assertFsFileExists() - " << path << " is not a regular file";
throw(exception::Exception(msg.str()));
}
}
//------------------------------------------------------------------------------
// assertFsPathDoesNotExist
//------------------------------------------------------------------------------
......@@ -174,7 +195,7 @@ void cta::MockNameServer::assertStorageClassIsNotInUse(
std::string cta::MockNameServer::fromNameServerTapeFileToString(const cta::NameServerTapeFile &tapeFile) const {
std::stringstream ss;
ss << tapeFile.checksum.checksumTypeToStr(tapeFile.checksum.getType())
<< " " << tapeFile.checksum.str()
<< " " << *((uint32_t *)(tapeFile.checksum.getByteArray().getBytes()))
<< " " << tapeFile.compressedSize
<< " " << tapeFile.copyNb
<< " " << tapeFile.size
......@@ -192,9 +213,9 @@ cta::NameServerTapeFile cta::MockNameServer::fromStringToNameServerTapeFile(cons
NameServerTapeFile tapeFile;
std::stringstream ss(xAttributeString);
std::string checksumTypeString;
std::string checksumString;
uint32_t checksumInt32;
ss >> checksumTypeString
>> checksumString
>> checksumInt32
>> tapeFile.compressedSize
>> tapeFile.copyNb
>> tapeFile.size
......@@ -202,8 +223,8 @@ cta::NameServerTapeFile cta::MockNameServer::fromStringToNameServerTapeFile(cons
>> tapeFile.tapeFileLocation.copyNb
>> tapeFile.tapeFileLocation.fSeq
>> tapeFile.tapeFileLocation.vid;
cta::ByteArray byteArray(checksumString);
cta::Checksum::ChecksumType checksumType=checksumString=="ADLER32"?cta::Checksum::ChecksumType::CHECKSUMTYPE_ADLER32:cta::Checksum::ChecksumType::CHECKSUMTYPE_NONE;
cta::ByteArray byteArray(checksumInt32);
cta::Checksum::ChecksumType checksumType=checksumTypeString=="ADLER32"?cta::Checksum::ChecksumType::CHECKSUMTYPE_ADLER32:cta::Checksum::ChecksumType::CHECKSUMTYPE_NONE;
cta::Checksum checksum(checksumType, byteArray);
tapeFile.checksum=checksum;
return tapeFile;
......@@ -215,7 +236,7 @@ cta::NameServerTapeFile cta::MockNameServer::fromStringToNameServerTapeFile(cons
void cta::MockNameServer::addTapeFile(const SecurityIdentity &requester, const std::string &path, const NameServerTapeFile &tapeFile) {
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
assertFsDirExists(fsPath);
assertFsFileExists(fsPath);
if(tapeFile.tapeFileLocation.copyNb==1) {
Utils::setXattr(fsPath.c_str(), "user.CTATapeFileCopyOne", fromNameServerTapeFileToString(tapeFile));
}
......@@ -232,7 +253,7 @@ void cta::MockNameServer::addTapeFile(const SecurityIdentity &requester, const s
std::list<cta::NameServerTapeFile> cta::MockNameServer::getTapeFiles(const SecurityIdentity &requester, const std::string &path) {
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
assertFsDirExists(fsPath);
assertFsFileExists(fsPath);
std::list<cta::NameServerTapeFile> tapeFileList;
std::string copyOne = Utils::getXattr(fsPath, "user.CTATapeFileCopyOne");
std::string copyTwo = Utils::getXattr(fsPath, "user.CTATapeFileCopyTwo");
......
......@@ -126,6 +126,8 @@ private:
void assertFsDirExists(const std::string &path) const;
void assertFsFileExists(const std::string &path) const;
void assertFsPathDoesNotExist(const std::string &path) const;
std::list<cta::ArchiveDirEntry> getDirEntries(const SecurityIdentity &requester, const std::string &path) const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment