From ac1b825ceb3133880cfbf311136c72893ecbb923 Mon Sep 17 00:00:00 2001 From: samo38 Date: Wed, 16 Oct 2024 15:42:12 -0600 Subject: [PATCH 1/2] us_mpi_analysis: replaced US_Tar with US_Archive --- programs/us_mpi_analysis/us_mpi_analysis.cpp | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/programs/us_mpi_analysis/us_mpi_analysis.cpp b/programs/us_mpi_analysis/us_mpi_analysis.cpp index f2e8e6965..7c140d2f9 100644 --- a/programs/us_mpi_analysis/us_mpi_analysis.cpp +++ b/programs/us_mpi_analysis/us_mpi_analysis.cpp @@ -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" @@ -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 @@ -2481,8 +2482,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 Date: Wed, 16 Oct 2024 15:43:40 -0600 Subject: [PATCH 2/2] us_archive: add an optional string list to see the extracted file --- utils/us_archive.cpp | 10 +++++++++- utils/us_archive.h | 7 ++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/utils/us_archive.cpp b/utils/us_archive.cpp index 1cd773db8..e3818c2e7 100644 --- a/utils/us_archive.cpp +++ b/utils/us_archive.cpp @@ -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(); @@ -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); @@ -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; } diff --git a/utils/us_archive.h b/utils/us_archive.h index 09cd25e7a..77dad9706 100644 --- a/utils/us_archive.h +++ b/utils/us_archive.h @@ -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.