Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support xz and tar in ZipWrapper #17925

Draft
wants to merge 15 commits into
base: 3.3RC
Choose a base branch
from
102 changes: 56 additions & 46 deletions src/common/misc/FileFunctions.C
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <cerrno>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


Expand All @@ -30,10 +31,39 @@
#include <pwd.h>
#endif


const int STATIC_BUF_SIZE = 4096;
static char StaticStringBuf[STATIC_BUF_SIZE];

//
// very simple circular cache for short-lived strings returned to callers
//
static size_t const max_retstrs = 32;
static char const * retstrbuf[max_retstrs];
static char const * save_returned_string(char const * const retstr)
{
static size_t n = 0;
int modn = (int) (n++ % max_retstrs);
if (retstr == 0) // to wholly free memory if ever needed.
{
for (n = 0; n < max_retstrs; n++)
{
if (retstrbuf[n])
free((void*)retstrbuf[n]);
}
n = 0;
return 0;
}
if (retstrbuf[modn])
free((void*)retstrbuf[modn]);
retstrbuf[modn] = strdup(retstr);
return retstrbuf[modn];
}

static std::string save_returned_string(std::string const &retstr)
{
return std::string(save_returned_string(retstr.c_str()));
}

// ****************************************************************************
// Method: FileFunctions::VisItStat
//
Expand Down Expand Up @@ -591,13 +621,11 @@ basename(char const *path, int& start, char const *suffix=0)

if (path == 0)
{
strcpy(StaticStringBuf, ".");
return StaticStringBuf;
return save_returned_string(".");
}
else if (*path == '\0')
{
strcpy(StaticStringBuf, ".");
return StaticStringBuf;
return save_returned_string(".");
}
else
{
Expand All @@ -609,8 +637,7 @@ basename(char const *path, int& start, char const *suffix=0)
// deal with string too large
if (n == STATIC_BUF_SIZE)
{
strcpy(StaticStringBuf, ".");
return StaticStringBuf;
return save_returned_string(".");
}

// backup, skipping over all trailing slash chars
Expand All @@ -622,8 +649,7 @@ basename(char const *path, int& start, char const *suffix=0)
if (j == -1)
{
start = -1;
strcpy(StaticStringBuf, VISIT_SLASH_STRING);
return StaticStringBuf;
return save_returned_string(VISIT_SLASH_STRING);
}

// backup to just after next slash char
Expand All @@ -648,7 +674,7 @@ basename(char const *path, int& start, char const *suffix=0)
StaticStringBuf[k-n] = '\0';
}

return StaticStringBuf;
return save_returned_string(StaticStringBuf);
}
}

Expand All @@ -669,9 +695,7 @@ FileFunctions::Basename(char const *path, char const *suffix)
{
suffString = suffix;
}
std::string fbn = Basename(std::string(path), suffString);
strcpy(StaticStringBuf, fbn.c_str());
return StaticStringBuf;
return save_returned_string(Basename(path, suffString.c_str()));
#else
int dummy1;
return basename(path, dummy1, suffix);
Expand Down Expand Up @@ -735,13 +759,12 @@ FileFunctions::Dirname(const char *path)
{
// preserve the previous assumption of 'current directory' if 'path'
// contains no directory information
strcpy(StaticStringBuf, ".");
return save_returned_string(".");
}
else
{
strcpy(StaticStringBuf, fsp.parent_path().string().c_str());
return save_returned_string(fsp.parent_path().string().c_str());
}
return StaticStringBuf;
#else
int start;

Expand All @@ -750,13 +773,11 @@ FileFunctions::Dirname(const char *path)

if (start == -1)
{
strcpy(StaticStringBuf, VISIT_SLASH_STRING);
return StaticStringBuf;
return save_returned_string(VISIT_SLASH_STRING);
}
else if (start == 0)
{
strcpy(StaticStringBuf, ".");
return StaticStringBuf;
return save_returned_string(".");
}
else
{
Expand All @@ -768,7 +789,7 @@ FileFunctions::Dirname(const char *path)
StaticStringBuf[i-1] = '\0';
else
StaticStringBuf[i] = '\0';
return StaticStringBuf;
return save_returned_string(StaticStringBuf);
}
#endif
}
Expand All @@ -782,8 +803,7 @@ FileFunctions::Dirname(const std::string &path)
{
// preserve the previous assumption of 'current directory' if 'path'
// contains no directory information
strcpy(StaticStringBuf, ".");
return StaticStringBuf;
return save_returned_string(".");
}
else
{
Expand Down Expand Up @@ -886,9 +906,7 @@ FileFunctions::Normalize(const char *path, const char *pathSep)

if (retval == "" && !noCharsRemainingToBackup) retval = ".";

StaticStringBuf[0] = '\0';
strcat(StaticStringBuf, retval.c_str());
return StaticStringBuf;
return save_returned_string(retval.c_str());
}

std::string
Expand Down Expand Up @@ -926,56 +944,48 @@ FileFunctions::Absname(const char *cwd_context, const char *path,
// cwd_context is null or empty string
if (!cwd_context || cwd_context[0] == '\0')
{
if (!path) return StaticStringBuf;
if (path[0] != pathSep[0]) return StaticStringBuf;
if (!path) return save_returned_string("");
if (path[0] != pathSep[0]) return save_returned_string("");

std::string npath(Normalize(path, pathSep));
strcpy(StaticStringBuf, npath.c_str());
return StaticStringBuf;
return save_returned_string(Normalize(path, pathSep));
}

// path is null or empty string
if (!path || path[0] == '\0')
{
if (!cwd_context) return StaticStringBuf;
if (cwd_context[0] != pathSep[0]) return StaticStringBuf;
if (!cwd_context) return save_returned_string("");
if (cwd_context[0] != pathSep[0]) return save_returned_string("");

std::string ncwd(Normalize(cwd_context, pathSep));
strcpy(StaticStringBuf, ncwd.c_str());
return StaticStringBuf;
return save_returned_string(Normalize(cwd_context, pathSep));
}

if (path[0] == pathSep[0])
{
std::string npath(Normalize(path, pathSep));
strcpy(StaticStringBuf, npath.c_str());
return StaticStringBuf;
return save_returned_string(Normalize(path, pathSep));
}

#ifndef _WIN32
if (cwd_context[0] != pathSep[0])
{
return StaticStringBuf;
return save_returned_string("");
}
#else
if(cwd_context[0] == '.')
{
if (PathIsRelative(path))
{
if(_fullpath(StaticStringBuf, ".\\", _MAX_PATH) != NULL)
return StaticStringBuf;
return save_returned_string("");
else
return path;
return save_returned_string(path);
}
return path;
return save_returned_string(path);
}
#endif

// Catenate path to cwd_context and then Normalize the result
std::string path2 = std::string(cwd_context) + std::string(pathSep) + std::string(path);
std::string npath = Normalize(path2.c_str(), pathSep);
strcpy(StaticStringBuf, npath.c_str());
return StaticStringBuf;
return save_returned_string(Normalize(path2.c_str(), pathSep));
}

std::string
Expand Down
9 changes: 9 additions & 0 deletions src/common/misc/FileFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,21 @@ typedef enum
FILE_TYPE_NOT_KNOWN
} FileType;

typedef enum
{
REMOVE_ENTRY, // file or empty dir
REMOVE_LEAFAN, // dir and children none of which are dirs
REMOVE_TREE // dir and all things below it
} RemoveMode;

VisItStat_t* const FILE_TYPE_DONT_STAT = ((VisItStat_t*)0x1);

PermissionsResult MISC_API CheckPermissions(const std::string &filename);

int MISC_API VisItStat(const std::string &filename, VisItStat_t *buf);
int MISC_API VisItFstat(int fd, VisItStat_t *buf);
int MISC_API VisItRemove(char const *path, RemoveMode mode = REMOVE_ENTRY);
int MISC_API VisItRemove(std::string const &path, RemoveMode mode = REMOVE_ENTRY);
bool MISC_API ReadAndProcessDirectory(const std::string &,
ProcessDirectoryCallback *,
void * = 0,
Expand Down
9 changes: 9 additions & 0 deletions src/databases/ZipWrapper/ZipWrapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
<FilePatterns>
*.gz
*.bz2
*.xz
*.zip
*.tar.gz
*.tgz
*.tar.bz2
*.tbz2
*.tar.bz
*.tbz
*.tar.xz
*.txz
</FilePatterns>
<Files components="M,E">
avtZipWrapperFileFormatInterface.C
Expand Down
10 changes: 10 additions & 0 deletions src/databases/ZipWrapper/ZipWrapperPluginInfo.C
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,17 @@ ZipWrapperGeneralPluginInfo::GetDefaultFilePatterns() const
{
std::vector<std::string> defaultPatterns;
defaultPatterns.push_back("*.gz");
defaultPatterns.push_back("*.bz");
defaultPatterns.push_back("*.bz2");
defaultPatterns.push_back("*.xz");
defaultPatterns.push_back("*.tar.gz");
defaultPatterns.push_back("*.tar.bz");
defaultPatterns.push_back("*.tar.bz2");
defaultPatterns.push_back("*.tar.xz");
defaultPatterns.push_back("*.tgz");
defaultPatterns.push_back("*.tbz");
defaultPatterns.push_back("*.tbz2");
defaultPatterns.push_back("*.txz");
defaultPatterns.push_back("*.zip");

return defaultPatterns;
Expand Down
Loading