& message,
68 if(message.empty()) {
69 msg=
"Unsupported entry type for '"+
info.GetName() +
"'";
77 if(!
info.GetName().empty()) {
78 msg+=
", while in '"+
info.GetName() +
'\'';
97 const char* strerr = x_errno ?
strerror(x_errno) : 0;
108 #define ARCHIVE_THROW1(errcode) \ 109 NCBI_THROW(CArchiveException, errcode, s_FormatMessage(CArchiveException::errcode, kEmptyStr, this->m_Current)) 110 #define ARCHIVE_THROW(errcode, message) \ 111 NCBI_THROW(CArchiveException, errcode, s_FormatMessage(CArchiveException::errcode, message, this->m_Current)) 112 #define ARCHIVE_THROW_INFO(errcode, message, info) \ 113 NCBI_THROW(CArchiveException, errcode, s_FormatMessage(CArchiveException::errcode, message, info)) 121 #define ARCHIVE m_Archive.get() 123 #define ARCHIVE_CHECK _ASSERT(m_Archive.get() != NULL) 126 #define F_ISSET(mask) ((m_Flags & (mask)) == (mask)) 147 static string s_ToArchiveName(
const string& base_dir,
const string& path,
boolis_absolute_allowed)
163 if(retval.size() > base_dir.size()) {
164retval.erase(0, base_dir.size()
);
166retval.assign(1,
'.');
176 if(retval.size() > 1
177&&
isalpha((
unsigned char) retval[0]) && retval[1] ==
':') {
183 while(pos < retval.size() && retval[pos] ==
'/') {
187retval.erase(0, pos);
190 while(pos > 0 && retval[pos - 1] ==
'/') {
193 if(pos < retval.size()) {
198 if(absolute && is_absolute_allowed) {
311 return ARCHIVE->HaveSupport_AbsolutePath();
313 return ARCHIVE->HaveSupport_FileStream();
362 if(!
buf|| !buf_size) {
379*out_size = (size_t)
info.GetSize();
388 if(!buf_ptr || !buf_size_ptr) {
403 Uint8uncompressed_size =
info.GetSize();
404 if(!uncompressed_size) {
408 if( uncompressed_size >
get_limits(*buf_size_ptr).max() ) {
409 ARCHIVE_THROW(eMemory,
"File is too big to extract to memory, its size is "+
413 size_tx_uncompressed_size = (size_t)uncompressed_size;
414 void* ptr =
malloc(x_uncompressed_size);
429*buf_size_ptr = x_uncompressed_size;
446 ARCHIVE->ExtractEntryToCallback(
info, callback);
452 const string& comment)
456 return x_Append(path, level, comment);
460unique_ptr<CArchive::TEntries>
462 ELevellevel,
const string& comment)
465 if(!
buf|| !buf_size) {
477 ARCHIVE_THROW(eBadName,
"Empty entry name is not allowed");
490 ARCHIVE_THROW(eUnsupported,
"Selected archive format doesn't allow to append files from memory");
568 ARCHIVE_THROW(eUnsupported,
"File streams allow writing to it only, any other operations are prohibited");
576 ARCHIVE_THROW(eUnsupported,
"Append to an existing archive is not implemented");
611 size_t n=
ARCHIVE->GetNumEntries();
614 for(
size_t i= 0;
i<
n;
i++) {
632list<CTempString> elems;
634 ITERATE(list<CTempString>, it, elems) {
678 if( entry->
GetPath().empty() ) {
690unique_ptr<CDirEntry> dst(
695dst->DereferenceLink();
727 if(dst->GetTimeT(&dst_time)
735 "' with an archive entry of different type");
763 stringdirname = dst->GetDir();
764 if(!dirname.empty()) {
765 if(!
CDir(dirname).CreatePath()) {
781dst->GetPath() +
"' back in place"+
s_OSReason(x_errno));
807unique_ptr<CDirEntry> path_ptr;
811dst = path_ptr.get();
818time_t mtime(
info.GetModificationTime());
819time_t atime(
info.GetLastAccessTime());
820time_t ctime(
info.GetCreationTime());
821 if(!dst->
SetTimeT(&mtime, &atime, &ctime)) {
823 ARCHIVE_THROW(eRestoreAttrs,
"Cannot restore date/time for '"+
833 unsigned intuid, gid;
841 if(uid !=
info.GetUserId() || gid !=
info.GetGroupId()) {
868 if(
mode& (S_ISUID | S_ISGID)) {
869 mode&= ~(S_ISUID | S_ISGID);
897 const string& comment,
913 if(!entry.
Stat(&
st, follow_links)) {
932list<CTempString> elems;
934 ITERATE(list<CTempString>, it, elems) {
936 ARCHIVE_THROW(eBadName,
"Name '"+ temp +
"' embeds parent directory ('..')");
953 ARCHIVE_THROW(eUnsupportedEntryType,
"Cannot append to archive, unsupported entry type for '"+ path +
"', ");
980 unsigned intuid = 0, gid = 0;
992 st.orig.st_uid = (uid_t) uid;
993 st.orig.st_gid = (gid_t) gid;
1004 boolfound =
false;
1011 if(!temp.empty()) {
1034e->GetModificationTime()) {
1134 boolisread = ((
int)action & (
int)
eRO) > 0;
1184 boolisread = ((
int)action & (
int)
eRO) > 0;
1196 if(!buf_ptr || !buf_size_ptr) {
1200 ARCHIVE->FinalizeMemory(buf_ptr, buf_size_ptr);
1230 Int8filesize =
f.GetLength();
1232 intx_errno = errno;
1236 ARCHIVE_THROW(eOpen,
"Cannot load empty file '"+ filename +
"' to memory");
1243 size_tn_read = fio.
Read(
tmp.get(), (
size_t)filesize);
1244 if(n_read != (
size_t)filesize) {
1245 ARCHIVE_THROW(eWrite,
"Failed to load archive to memory");
1268 ARCHIVE_THROW(eOpen,
"Cannot create file stream from the file descriptor");
static string s_FormatMessage(CArchiveException::TErrCode errcode, const string &message, const CArchiveEntryInfo &info)
static string s_ToArchiveName(const string &base_dir, const string &path, bool is_absolute_allowed)
#define ARCHIVE_THROW1(errcode)
#define ARCHIVE_THROW_INFO(errcode, message, info)
static string s_ToFilesystemPath(const string &base_dir, const string &name)
#define ARCHIVE_THROW(errcode, message)
static string s_OSReason(int x_errno)
ncbi::TMaskedQueryRegions mask
CArchiveZip â implementation of IArchive interface for ZIP-archives.
CArchive - base class for file- or memory-based archives.
Class for support low level input/output for files.
The NCBI C++ standard methods for dealing with std::string.
std::ofstream out("events_result.xml")
main entry point for tests
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
EFollowLinks
Whether to follow symbolic links (also known as shortcuts or aliases)
element_type * get(void) const
Get pointer.
void reset(element_type *p=0)
Reset will delete the old pointer, set content to the new value, and assume the ownership upon the ne...
#define REVERSE_ITERATE(Type, Var, Cont)
ITERATE macro to reverse sequence through container elements.
@ eIgnoreLinks
Do not follow symbolic links.
@ eFollowLinks
Follow symbolic links.
@ eNoOwnership
No ownership is assumed.
CArchiveFile(EFormat format, const string &filename)
Constructor for file-based archive.
virtual bool Checkpoint(const CArchiveEntryInfo &, EAction)
Return false to skip the current entry when processing.
virtual void SkipEntry(void)
Process current entry (List/Test/Extract/Append)
CDirEntry::EType GetType(void) const
string m_GroupName
Group name.
void x_ExtractEntry(const TEntries *prev_entries)
const string & GetUserName(void) const
int m_fd
File/socket descriptor.
void Save(const string &filename)
Save current opened/created archive to file.
bool HaveSupport(ESupportFeature feature, int param=0)
Check that current archive format have support for specific features.
virtual ~CArchiveCompressionFileStream(void)
Destructor.
virtual unique_ptr< TEntries > Append(const string &path, ELevel level=CCompression::eLevel_Default, const string &comment=kEmptyStr)
Append an entry to the archive.
virtual ~CArchive(void)
Destructor.
const string & GetGroupName(void) const
size_t m_InitialAllocationSize
< Initial allocation size for created archive
unique_ptr< TEntries > x_ReadAndProcess(EAction action)
EOpenMode
Archive open mode.
IArchive::ELocation m_Location
Archive location (file/memory)
ELevel
Compression level.
string m_Comment
Entry comment.
EFormat m_Format
Archive format.
void SetMask(CMask *mask, EOwnership own=eNoOwnership, EMaskType type=eFullPathMask, NStr::ECase acase=NStr::eNocase)
Set name mask for processing.
void x_RestoreAttrs(const CArchiveEntryInfo &info, const CDirEntry *dst=NULL) const
unique_ptr< IArchive > m_Archive
Pointer to interface to EFormat-specific archive support.
virtual void Close(void)
Close the archive making sure all pending output is flushed.
string m_BaseDir
Base directory for relative paths.
CDirEntry::EType m_Type
Type.
virtual void TestEntry(void)
CArchive(EFormat format)
Construct an archive object of specified format.
const void * m_Buf
Buffer where the opening archive is located.
size_t m_BufSize
Size of m_Buf.
bool m_Modified
True after at least one write.
const string & GetLinkName(void) const
virtual void SetBaseDir(const string &dirname)
Set base directory to use for files while extracting from/adding to the archive, and in the latter ca...
string m_LinkName
Link name if type is eLink.
virtual void AppendEntry(const string &path, ELevel level)
virtual void Open(EAction action)
Open the archive for specified action.
string m_FileName
Archive file name.
TNcbiSys_stat m_Stat
Direntry-compatible info (as applicable)
virtual void Close(void)
Close archive.
void x_Open(EAction action)
const string & GetName(void) const
list< CArchiveEntryInfo > TEntries
Define a list of entries.
string m_Name
Entry name.
bool x_AppendEntry(const string &path, ELevel level=CCompression::eLevel_Default)
size_t(* Callback_Write)(const CArchiveEntryInfo &info, const void *buf, size_t n)
Type of user-defined callback for extraction from archive.
void Load(const string &filename)
Load existing archive from file system to memory.
virtual void Create(void)
Create a new empty archive.
CArchiveEntryInfo m_Current
Information about current entry being processed.
unique_ptr< TEntries > x_Append(const string &path, ELevel level, const string &comment, const TEntries *toc=NULL)
virtual void Open(EAction action)
Open the archive for specified action.
virtual void Create(void)
Create a new empty archive.
virtual unique_ptr< TEntries > List(void)
Get information about archive entries.
CArchiveCompressionFileStream(EFormat format, int fd)
Constructor for stream-based archive.
AutoArray< char > m_OwnBuf
Holder for the pointer to memory buffer that will be automatically deallocated if we own it (used for...
TFlags m_Flags
Bitwise OR of flags.
virtual void Open(EAction action)
Open the archive for specified action.
SMask m_MaskFullPath
Set of masks for operations (full path)
virtual void Create(void)
Create a new empty archive.
virtual unique_ptr< TEntries > Extract(void)
Extract the entire archive.
EOpenMode m_OpenMode
What was it opened for.
EAction
Action, performed on the archive.
string m_UserName
User name.
virtual unique_ptr< TEntries > Test(void)
Verify archive integrity.
SMask m_MaskPattern
Set of masks for operations (path components)
FILE * m_FileStream
File stream, can be based on m_fd.
virtual void ExtractFileToMemory(const CArchiveEntryInfo &info, void *buf, size_t buf_size, size_t *out_size)
Extract single file entry to a memory buffer.
#define COMPRESS_HANDLE_EXCEPTIONS(subcode, message)
Macro to catch and handle exceptions (from streams in the destructor)
virtual void ExtractEntry(const CDirEntry &dst)
CArchiveMemory(EFormat format, const void *buf=NULL, size_t buf_size=0)
Constructor for memory-based archive.
time_t GetModificationTime(void) const
virtual void Finalize(void **buf_ptr, size_t *buf_size_ptr)
Finalize the archive created in memory.
virtual void Open(EAction action)=0
Open archive.
virtual void ExtractFileToCallback(const CArchiveEntryInfo &info, IArchive::Callback_Write callback)
Extract single file entry using user-defined callback.
virtual unique_ptr< CArchive::TEntries > AppendFileFromMemory(const string &name_in_archive, void *buf, size_t buf_size, ELevel level=CCompression::eLevel_Default, const string &comment=kEmptyStr)
Append a single file entry to the created archive using data from memory buffer.
virtual void ExtractFileToHeap(const CArchiveEntryInfo &info, void **buf_ptr, size_t *buf_size_ptr)
Extract single file entry to a dynamically allocated memory buffer.
@ eFileStream
File stream based archive (FILE*)
@ eFile
File-based archive.
@ eMemory
Memory-based archive.
@ fSkipUnsupported
Skip unsupported entries rather than making files out of them when extracting (the latter is the defa...
@ fPreserveTime
Preserve date/times for extracted files Note, that some formats, as zip for example,...
@ fUpdate
Only update entries that are older than those already existing.
@ fPreserveAll
Preserve all file attributes.
@ fFollowLinks
Follow symbolic links (instead of storing/extracting them)
@ fBackup
Backup destinations if they exist (all entries including dirs)
@ fOverwrite
Allow to overwrite destinations with entries from the archive.
@ fPreserveOwner
Create extracted files with the original ownership.
@ fDefault
Default flags.
@ fPreserveMode
Create extracted files with the original permissions.
@ fEqualTypes
If destination entry exists, it must have the same type as source.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Close(void)
Close file.
EType
Directory entry type.
static string NormalizePath(const string &path, EFollowLinks follow_links=eIgnoreLinks)
Normalize a path.
TEntries GetEntries(const string &mask=kEmptyStr, TGetEntriesFlags flags=0) const
Get directory entries based on the specified "mask".
static string GetTmpNameEx(const string &dir=kEmptyStr, const string &prefix=kEmptyStr, ETmpFileCreationMode mode=eTmpFileGetName)
Get temporary file name.
size_t Write(const void *buf, size_t count) const
Write file.
static bool IsAbsolutePath(const string &path)
Check if a "path" is absolute for the current OS.
void Open(const string &filename, EOpenMode open_mode, EAccessMode access_mode, EShareMode share_mode=eShare)
Open file.
unsigned int TSpecialModeBits
Bitwise OR of ESpecialModeBits.
unsigned int TMode
Bitwise OR of "EMode".
virtual bool SetMode(TMode user_mode, TMode group_mode=fDefault, TMode other_mode=fDefault, TSpecialModeBits special=0, TSetModeFlags flags=eEntryOnly) const
Set permission mode(s) of a directory entry.
bool Backup(const string &suffix=kEmptyStr, EBackupMode mode=eBackup_Default, TCopyFlags copyflags=fCF_Default, size_t copybufsize=0)
Backup an entry.
virtual bool Remove(TRemoveFlags flags=eRecursive) const
Remove a directory entry.
string LookupLink(void) const
Get an entry name that a link points to.
static void ModeFromModeT(mode_t mode, TMode *user_mode, TMode *group_mode=0, TMode *other_mode=0, TSpecialModeBits *special=0)
Convert mode_t to permission mode(s).
static CDirEntry * CreateObject(EType type, const string &path=kEmptyStr)
Construct a directory entry object of a specified type.
static string AddTrailingPathSeparator(const string &path)
Add trailing path separator, if needed.
bool GetOwner(string *owner, string *group=0, EFollowLinks follow=eFollowLinks, unsigned int *uid=0, unsigned int *gid=0) const
Get an entry owner.
static string ConcatPath(const string &first, const string &second)
Concatenate two parts of the path for the current OS.
bool SetTimeT(const time_t *modification=0, const time_t *last_access=0, const time_t *creation=0) const
Set time stamp(s) of a directory entry (time_t version).
bool Stat(struct SStat *buffer, EFollowLinks follow_links=eIgnoreLinks) const
Get status information on a dir entry.
size_t Read(void *buf, size_t count) const
Read file.
bool SetOwner(const string &owner, const string &group=kEmptyStr, EFollowLinks follow=eFollowLinks, unsigned int *uid=0, unsigned int *gid=0) const
Set an entry owner and/or group.
EType GetType(EFollowLinks follow=eIgnoreLinks) const
Get a type of a directory entry.
const string & GetPath(void) const
Get entry path.
@ eSocket
Socket (UNIX only)
@ eBlockSpecial
Block special (UNIX only)
@ eLink
Symbolic link (UNIX only)
@ eCharSpecial
Character special.
@ fRF_Default
Default flags.
@ fRF_Overwrite
Remove destination if it exists.
@ eTmpFileCreate
Create empty file for each GetTmpName* call.
@ eRead
File can be read.
@ eReadWrite
File can be read and written.
@ eOpen
Open an existing file, or create a new one.
@ eCreate
Create a new file, or truncate an existing one.
@ eBackup_Rename
Rename entry.
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
ncbi_numeric_limits< T > get_limits(const T &)
Generic template to get STD limits by a variable.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
NCBI_NS_STD::string::size_type SIZE_TYPE
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
ECase
Which type of string comparison.
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
@ eNocase
Case insensitive compare.
@ eCase
Case sensitive compare.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
virtual bool Match(CTempString str, NStr::ECase use_case=NStr::eCase) const =0
Match a string.
unsigned int
A callback function used to compare two keys in a database.
Definition of all error codes used in util (xutil.lib).
The blob sat and sat key Both must be positive integers</td > n< td > Non empty string The interpretation of the blob id depends on a processor Cassandra n processor expects the following format
const struct ncbi::grid::netcache::search::fields::SIZE size
static int match(PCRE2_SPTR start_eptr, PCRE2_SPTR start_ecode, uint16_t top_bracket, PCRE2_SIZE frame_size, pcre2_match_data *match_data, match_block *mb)
static SLJIT_INLINE sljit_ins st(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Alternate stat structure for use instead of the standard struct stat.
static void Delete(CDirEntry *entry)
static TTarMode s_ModeToTar(mode_t mode)
static wxAcceleratorEntry entries[3]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4