Skip to content

Commit

Permalink
Merge pull request #155 from ehb54/samo38-issue-375
Browse files Browse the repository at this point in the history
Samo38 issue 375
  • Loading branch information
demeler authored Nov 21, 2024
2 parents 51d4e32 + 3fd930c commit dee661f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
23 changes: 15 additions & 8 deletions programs/us_mpi_analysis/us_mpi_analysis.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "us_mpi_analysis.h"
#include "us_math2.h"
#include "us_astfem_math.h"
#include "us_tar.h"
#include "us_archive.h"
#include "us_memory.h"
#include "us_sleep.h"
#include "us_util.h"
Expand Down Expand Up @@ -172,11 +172,12 @@ DbgLv(0) << "work_dir=" << work_dir;
DbgLv(0) << "Us_Mpi_Analysis " << REVISION;

// Unpack the input tarfile
US_Tar tar;

int result = tar.extract( tarfile );

if ( result != TAR_OK ) abort( "Could not unpack " + tarfile );
US_Archive archive;
bool ok = archive.extract( tarfile );
if ( !ok ) {
QString error = archive.getError();
abort( "Could not unpack\n " + error + "\n" + tarfile );
}

// Create a dedicated output directory and make sure it's empty
// During testing, it may not always be empty
Expand Down Expand Up @@ -2518,8 +2519,14 @@ DbgLv(0) << my_rank << ": model2.description" << model2.description;
}

// Create the archive file containing all outputs
US_Tar tar;
tar.create( "analysis-results.tar", files );
US_Archive archive;
QString filename = "analysis-results.tar";
bool ok = archive.compress( files, filename );
if ( !ok ) {
QString error = archive.getError();
abort( "Could not compress files\n " + error + "\n" + filename );
}

for(int jf=0;jf<files.size();jf++)
DbgLv(0) << my_rank << " tar file" << jf << ":" << files[jf];

Expand Down
10 changes: 9 additions & 1 deletion utils/us_archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
#include "archive_entry.h"
#include "archive.h"

bool US_Archive::extract(const QString& filename, const QString& path) {
bool US_Archive::extract(const QString& filename, const QString& path, QStringList* file_list) {

if ( file_list != nullptr ) {
file_list->clear();
}
QStringList file_list_in;
QDir dir;
QFileInfo fino(filename);
QString outpath = path.trimmed();
Expand Down Expand Up @@ -89,6 +93,7 @@ bool US_Archive::extract(const QString& filename, const QString& path) {
}
file.close();
emit itemExtracted(entry_path, target.absoluteFilePath());
file_list_in << target.absoluteFilePath();
} else {
error = "US_Archive: Error: Failed to open file: " + target.absolutePath();
archive_read_close(archive);
Expand All @@ -102,6 +107,9 @@ bool US_Archive::extract(const QString& filename, const QString& path) {

archive_read_close(archive);
archive_read_free(archive);
if ( file_list != nullptr) {
file_list->append(file_list_in);
}
return true;
}

Expand Down
7 changes: 4 additions & 3 deletions utils/us_archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ class US_UTIL_EXTERN US_Archive : public QObject
US_Archive() {};

//! \brief Method to extract archive file (Supported files: tar, tar.gz, tgz, tar.bz2, tar.xz, .zip).
//! \param archivePath Path to the archive file.
//! \param outputPath Path to where extracted data will be saved. Default is the path where the archive file is located.
//! \param archivePath Path to the archive file.
//! \param outputPath Path to where extracted data will be saved. Default is the path where the archive file is located.
//! \param outputFileList The optional output list of extracted files.
//! \return True if file extraction is completed, false otherwise.
bool extract(const QString&, const QString& = "");
bool extract(const QString&, const QString& = "", QStringList* = nullptr);

//! \brief Method to compress files and folders into an archive file.
//! \param sourcePathList List of all files and folders need to be compressed. No need to list the contents of folders.
Expand Down

0 comments on commit dee661f

Please sign in to comment.