Commit 00c7ff0a authored by Michael Davis's avatar Michael Davis
Browse files

Merge branch 'master' of https://gitlab.cern.ch:8443/cta/CTA

parents 3bd5483d 2d0d7b63
......@@ -18,6 +18,7 @@
#include "xroot_plugins/ListArchiveFilesCmd.hpp"
#include <iomanip>
#include <sstream>
#include <stdint.h>
......@@ -51,11 +52,27 @@ XrdSfsXferSize ListArchiveFilesCmd::read(XrdSfsFileOffset offset, char *buffer,
m_state = State::LISTING_ARCHIVE_FILES;
// The first character of the reply stream is the return code
m_readBuffer = "0";
m_readBuffer << "0";
if(m_displayHeader) {
m_readBuffer += "\x1b[31;1mid copy no vid fseq block id instance disk id size checksum type checksum value "
"storage class owner group path creation time\x1b[0m\n";
m_readBuffer <<
"\x1b[31;1m" << // Change the colour of the output text to red
std::setfill(' ') << std::setw(7) << std::right << "id" << " " <<
std::setfill(' ') << std::setw(7) << std::right << "copy no" << " " <<
std::setfill(' ') << std::setw(7) << std::right << "vid" << " " <<
std::setfill(' ') << std::setw(7) << std::right << "fseq" << " " <<
std::setfill(' ') << std::setw(8) << std::right << "block id" << " " <<
std::setfill(' ') << std::setw(8) << std::right << "instance" << " " <<
std::setfill(' ') << std::setw(7) << std::right << "disk id" << " " <<
std::setfill(' ') << std::setw(7) << std::right << "size" << " " <<
std::setfill(' ') << std::setw(13) << std::right << "checksum type" << " " <<
std::setfill(' ') << std::setw(14) << std::right << "checksum value" << " " <<
std::setfill(' ') << std::setw(13) << std::right << "storage class" << " " <<
std::setfill(' ') << std::setw(8) << std::right << "owner" << " " <<
std::setfill(' ') << std::setw(8) << std::right << "group" << " " <<
std::setfill(' ') << std::setw(13) << std::right << "creation time" << " " <<
"path" <<
"\x1b[0m\n"; // Return the colour of the output text
}
}
......@@ -74,7 +91,7 @@ XrdSfsXferSize ListArchiveFilesCmd::read(XrdSfsFileOffset offset, char *buffer,
return SFS_ERROR;
}
XrdSfsXferSize nbBytesToBeReadFromBuffer = (XrdSfsXferSize)m_readBuffer.size() - offSetIntoReadBuffer;
XrdSfsXferSize nbBytesToBeReadFromBuffer = (XrdSfsXferSize)m_readBuffer.str().size() - offSetIntoReadBuffer;
if(0 > nbBytesToBeReadFromBuffer) {
std::ostringstream errMsg;
errMsg << "nbBytesToBeReadFromBuffer must be positive: actual=" << nbBytesToBeReadFromBuffer;
......@@ -84,13 +101,13 @@ XrdSfsXferSize ListArchiveFilesCmd::read(XrdSfsFileOffset offset, char *buffer,
if(nbBytesToBeReadFromBuffer == 0) {
refreshReadBuffer();
if (m_readBuffer.empty()) {
if (m_readBuffer.str().empty()) {
m_state = State::LISTED_LAST_ARCHIVE_FILE;
return SFS_OK;
}
m_fileOffsetOfReadBuffer = offset;
offSetIntoReadBuffer = 0;
nbBytesToBeReadFromBuffer = m_readBuffer.size();
nbBytesToBeReadFromBuffer = m_readBuffer.str().size();
}
const XrdSfsXferSize actualNbBytesToRead = nbBytesToBeReadFromBuffer >= size ? size : nbBytesToBeReadFromBuffer;
......@@ -101,7 +118,7 @@ XrdSfsXferSize ListArchiveFilesCmd::read(XrdSfsFileOffset offset, char *buffer,
return SFS_ERROR;
}
strncpy(buffer, m_readBuffer.c_str() + offSetIntoReadBuffer, actualNbBytesToRead);
strncpy(buffer, m_readBuffer.str().c_str() + offSetIntoReadBuffer, actualNbBytesToRead);
m_expectedFileOffset += actualNbBytesToRead;
return actualNbBytesToRead;
......@@ -115,7 +132,8 @@ void ListArchiveFilesCmd::refreshReadBuffer() {
const uint32_t nbArchiveFilesToFetch = 100;
uint32_t nbFetchedArchiveFiles = 0;
m_readBuffer.clear();
// Clear the read buffer
m_readBuffer.str(std::string());
while(m_archiveFileItor->hasMore() && nbArchiveFilesToFetch > nbFetchedArchiveFiles) {
const common::dataStructures::ArchiveFile archiveFile = m_archiveFileItor->next();
......@@ -123,22 +141,22 @@ void ListArchiveFilesCmd::refreshReadBuffer() {
for(auto copyNbToTapeFile: archiveFile.tapeFiles) {
const auto copyNb = copyNbToTapeFile.first;
const common::dataStructures::TapeFile &tapeFile = copyNbToTapeFile.second;
m_readBuffer +=
std::to_string((unsigned long long) archiveFile.archiveFileID) + " " +
std::to_string((unsigned long long) copyNb) + " " +
tapeFile.vid + " " +
std::to_string((unsigned long long) tapeFile.fSeq) + " " +
std::to_string((unsigned long long) tapeFile.blockId) + " " +
archiveFile.diskInstance + " " +
archiveFile.diskFileId + " " +
std::to_string((unsigned long long) archiveFile.fileSize) + " " +
archiveFile.checksumType + " " +
archiveFile.checksumValue + " " +
archiveFile.storageClass + " " +
archiveFile.diskFileInfo.owner + " " +
archiveFile.diskFileInfo.group + " " +
archiveFile.diskFileInfo.path + " " +
std::to_string((unsigned long long) archiveFile.creationTime) + "\n";
m_readBuffer <<
std::setfill(' ') << std::setw(7) << std::right << archiveFile.archiveFileID << " " <<
std::setfill(' ') << std::setw(7) << std::right << copyNb << " " <<
std::setfill(' ') << std::setw(7) << std::right << tapeFile.vid << " " <<
std::setfill(' ') << std::setw(7) << std::right << tapeFile.fSeq << " " <<
std::setfill(' ') << std::setw(8) << std::right << tapeFile.blockId << " " <<
std::setfill(' ') << std::setw(8) << std::right << archiveFile.diskInstance << " " <<
std::setfill(' ') << std::setw(7) << std::right << archiveFile.diskFileId << " " <<
std::setfill(' ') << std::setw(7) << std::right << archiveFile.fileSize << " " <<
std::setfill(' ') << std::setw(13) << std::right << archiveFile.checksumType << " " <<
std::setfill(' ') << std::setw(14) << std::right << archiveFile.checksumValue << " " <<
std::setfill(' ') << std::setw(13) << std::right << archiveFile.storageClass << " " <<
std::setfill(' ') << std::setw(8) << std::right << archiveFile.diskFileInfo.owner << " " <<
std::setfill(' ') << std::setw(8) << std::right << archiveFile.diskFileInfo.group << " " <<
std::setfill(' ') << std::setw(13) << std::right << archiveFile.creationTime << " " <<
archiveFile.diskFileInfo.path << "\n";
}
}
}
......
......@@ -24,6 +24,7 @@
#include <XrdSfs/XrdSfsInterface.hh>
#include <memory>
#include <sstream>
#include <string>
namespace cta {
......@@ -112,7 +113,7 @@ protected:
* of the CTA catalogue.
*
*/
std::string m_readBuffer;
std::ostringstream m_readBuffer;
/**
* The offset in the reply file at which the current m_readBuffer starts.
......
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