Skip to content
Snippets Groups Projects
Commit e786204f authored by T.J. Corona's avatar T.J. Corona
Browse files

vtkArchiver: add method to check for entry in archive

parent 981d8c44
No related branches found
No related tags found
No related merge requests found
......@@ -19,12 +19,15 @@
#include <archive.h>
#include <archive_entry.h>
#include <set>
struct vtkBufferedArchiver::Internal
{
struct archive* Archive;
char* Buffer;
size_t AllocatedSize;
size_t BufferSize;
std::set<std::string> Entries;
};
//----------------------------------------------------------------------------
......@@ -85,6 +88,14 @@ void vtkBufferedArchiver::InsertIntoArchive(
archive_write_header(this->Internals->Archive, entry);
archive_write_data(this->Internals->Archive, data, size);
archive_entry_free(entry);
this->Internals->Entries.insert(relativePath);
}
//----------------------------------------------------------------------------
bool vtkBufferedArchiver::Contains(const std::string& relativePath)
{
return this->Internals->Entries.find(relativePath) != this->Internals->Entries.end();
}
//----------------------------------------------------------------------------
......
......@@ -59,6 +59,13 @@ public:
const std::string& relativePath, const char* data, std::streamsize size) override;
//@}
//@{
/**
* Checks if \p relativePath represents an entry in the archive.
*/
bool Contains(const std::string& relativePath) override;
//@}
//@{
/**
* Access the buffer.
......
......@@ -119,6 +119,12 @@ void vtkPartitionedArchiver::InsertIntoArchive(
this->Internals->Buffers[relativePath] = std::make_pair(used, b);
}
//----------------------------------------------------------------------------
bool vtkPartitionedArchiver::Contains(const std::string& relativePath)
{
return this->Internals->Buffers.find(relativePath) != this->Internals->Buffers.end();
}
//----------------------------------------------------------------------------
const char* vtkPartitionedArchiver::GetBuffer(const char* relativePath)
{
......
......@@ -60,6 +60,13 @@ public:
const std::string& relativePath, const char* data, std::streamsize size) override;
//@}
//@{
/**
* Checks if \p relativePath represents an entry in the archive.
*/
bool Contains(const std::string& relativePath) override;
//@}
//@{
/**
* Access the buffer.
......
......@@ -68,6 +68,15 @@ void vtkArchiver::InsertIntoArchive(
out.close();
}
//----------------------------------------------------------------------------
bool vtkArchiver::Contains(const std::string& relativePath)
{
std::stringstream path;
path << this->ArchiveName << "/" << relativePath;
return vtksys::SystemTools::FileExists(vtksys::SystemTools::GetFilenamePath(path.str()), true);
}
//----------------------------------------------------------------------------
void vtkArchiver::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -70,6 +70,13 @@ public:
const std::string& relativePath, const char* data, std::streamsize size);
//@}
//@{
/**
* Checks if \p relativePath represents an entry in the archive.
*/
virtual bool Contains(const std::string& relativePath);
//@}
protected:
vtkArchiver();
~vtkArchiver() override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment