Skip to content

Commit

Permalink
Fixes for selective extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
tsujan committed Mar 6, 2019
1 parent 4d73126 commit 3a8d7fc
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 161 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ V0.2.0
* View/expand/collapse the current item with Enter/Return.
* With tar/bsdtar and if the parent dir exists, change the parent dir name instead of extracting in a child dir.
* A root archive file may mean a parent directory or a single file. Previously, it was supposed to be a parent directory and that caused single files not to be extracted with non-Gzip archives when they were present in the extraction directory.
* If a file comes after its containing folder in the command line, bsdtar doesn't extract the folder. A workaround is added for this behavior.

V0.1.0
---------
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Latest version:

24 Feb 2019, V0.2.0
7 Mar 2019, V0.2.0

See "ChangeLog" for changes.
4 changes: 4 additions & 0 deletions about.ui
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-weight:400; font-style:normal;">


<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Dutch:</span> Heimen Stoffels <a href="https://github.com/Vistaus"><span;>(Vistaus at GitHub)</span></a></p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Esperanto:</span> Tsu Jan (author)</p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Polish:</span> Marcin Mikołajczak <a href="https://github.com/m4sk1n"><span;>(m4sk1n at GitHub)</span></a></p>
Expand Down
82 changes: 53 additions & 29 deletions backends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ bool Backend::isWorking(){
return (PROC.state() != QProcess::Running);
}

//Listing routines
QStringList Backend::hierarchy() {
return contents_.keys();
}

QString Backend::singleRoot() {
return archiveSingleRoot_;
}

QString Backend::sizeString(const QString& file) {
if (contents_.contains(file))
return contents_.value(file)[1];
Expand Down Expand Up @@ -344,7 +347,11 @@ void Backend::startExtract(const QString& path, const QStringList& files, bool o
emit extractionSuccessful();
return;
}

QStringList args;
QStringList filesList = files;
filesList.removeAll(QString());

if(is7z_) { // extract the whole archive; no selective extraction
if (encrypted_)
args << "-p" + pswrd_;
Expand All @@ -354,28 +361,59 @@ void Backend::startExtract(const QString& path, const QStringList& files, bool o
}
else {
args << "-x" << "--no-same-owner";
if (!overwrite) // NOTE: We never overwrite in Arqiver. This might be changed later.
if (!overwrite) // NOTE: We never overwrite in Arqiver. This may changed later.
args << "-k";
args << fileArgs_;
for (int i = 0; i < files.length(); i++) {
if (files[i].simplified().isEmpty())
continue;
args << "--include" << files[i] << "--strip-components" << QString::number(files[i].count("/"));
if (!filesList.isEmpty()) {
filesList.removeDuplicates();
/* If a file comes after its containing folder in the command line,
bsdtar doesn't extract the folder. So, we sort the list and read it inversely. */
filesList.sort();
int N = files.length();
for (int i = 0; i < N; i++) {
if (filesList[N - 1 - i].simplified().isEmpty())
continue;
args << "--include" << filesList[N - 1 - i]
<< "--strip-components" << QString::number(filesList[N - 1 - i].count("/"));
}
}
keyArgs_ << "-x";
}

QString xPath = path;
if (!archiveSingleRoot_.isEmpty() && archiveSingleRoot_.startsWith("."))
archiveSingleRoot_.remove(0, 1); // no hidden extraction folder (with rpm)
bool archiveRootExists(false);
if (!archiveSingleRoot_.isEmpty()) {
if(QFile::exists(xPath + "/" + archiveSingleRoot_)) {
archiveRootExists = true;
QDir dir (xPath);
QString subdirName = archiveSingleRoot_ + "-arqiver-" + QDateTime::currentDateTime().toString("yyyyMMddhhmmss");

/* prevent overwriting by making an appropriate directory and extracting into it
if the whole archive is going to be extracted (otherwise, overwriting will be handled by mainWin) */
if (filesList.isEmpty() || is7z_) {
QString archiveSingleRoot = archiveSingleRoot_;
if (!archiveSingleRoot.isEmpty() && archiveSingleRoot.startsWith("."))
archiveSingleRoot.remove(0, 1); // no hidden extraction folder (with rpm)
if (!archiveSingleRoot.isEmpty()) {
if(QFile::exists(xPath + "/" + archiveSingleRoot)) {
archiveRootExists = true;
QDir dir (xPath);
QString subdirName = archiveSingleRoot + "-arqiver-" + QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
xPath += "/" + subdirName;

/* this is practically impossible */
int i = 0;
QString suffix;
while (QFile::exists(xPath + suffix)) {
suffix = QString::number(i);
++i;
}
xPath += suffix;
subdirName += suffix;

dir.mkdir(subdirName);
}
}
else { // the archive doesn't have a parent dir and isn't a single file
QDir dir(xPath);
QString subdirName = filepath_.section("/", -1) + "-arqiver-" + QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
xPath += "/" + subdirName;

/* this is practically impossible */
int i = 0;
QString suffix;
while (QFile::exists(xPath + suffix)) {
Expand All @@ -388,22 +426,7 @@ void Backend::startExtract(const QString& path, const QStringList& files, bool o
dir.mkdir(subdirName);
}
}
else { // the archive doesn't have a parent dir and isn't a single file
QDir dir(xPath);
QString subdirName = filepath_.section("/", -1) + "-arqiver-" + QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
xPath += "/" + subdirName;

int i = 0;
QString suffix;
while (QFile::exists(xPath + suffix)) {
suffix = QString::number(i);
++i;
}
xPath += suffix;
subdirName += suffix;

dir.mkdir(subdirName);
}
if(is7z_) {
args << "-o" + xPath;
PROC.start("7z", args);
Expand Down Expand Up @@ -605,6 +628,7 @@ void Backend::parseLines (QStringList& lines) {
file.remove(QRegularExpression("svgz$"));
file += "svg";
}
archiveSingleRoot_ = file.section('/', 0, 0);
contents_.insert(file,
QStringList() << "-rw-r--r--" << info.at(1) << QString()); // [perms, size, linkto]
}
Expand Down
1 change: 1 addition & 0 deletions backends.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Backend : public QObject{
bool isWorking();

QStringList hierarchy();
QString singleRoot();
QString sizeString(const QString& file);
double size(const QString& file);
double csize(const QString& file);
Expand Down
70 changes: 39 additions & 31 deletions data/translations/arqiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@
<context>
<name>Arqiver::AboutDialog</name>
<message>
<location filename="../../about.ui" line="114"/>
<location filename="../../about.ui" line="118"/>
<source>License</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Arqiver::Backend</name>
<message>
<location filename="../../backends.cpp" line="730"/>
<location filename="../../backends.cpp" line="769"/>
<location filename="../../backends.cpp" line="754"/>
<location filename="../../backends.cpp" line="793"/>
<source>Could not read archive</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="733"/>
<location filename="../../backends.cpp" line="774"/>
<location filename="../../backends.cpp" line="757"/>
<location filename="../../backends.cpp" line="798"/>
<source>Archive Loaded</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="740"/>
<location filename="../../backends.cpp" line="820"/>
<location filename="../../backends.cpp" line="764"/>
<location filename="../../backends.cpp" line="844"/>
<source>Modification Finished</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="791"/>
<location filename="../../backends.cpp" line="815"/>
<source>Extraction Finished</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="901"/>
<location filename="../../backends.cpp" line="925"/>
<source>%1 is missing from your system.
Please install it for this kind of archive!</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -357,6 +357,7 @@ Please install it for this kind of archive!</source>
</message>
<message>
<location filename="../../mainWin.cpp" line="467"/>
<location filename="../../mainWin.cpp" line="782"/>
<source>Question</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -386,8 +387,8 @@ Please install it for this kind of archive!</source>
<message>
<location filename="../../mainWin.cpp" line="566"/>
<location filename="../../mainWin.cpp" line="581"/>
<location filename="../../mainWin.cpp" line="739"/>
<location filename="../../mainWin.cpp" line="745"/>
<location filename="../../mainWin.cpp" line="741"/>
<location filename="../../mainWin.cpp" line="747"/>
<source>Adding Items...</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -398,10 +399,10 @@ Please install it for this kind of archive!</source>
</message>
<message>
<location filename="../../mainWin.cpp" line="604"/>
<location filename="../../mainWin.cpp" line="707"/>
<location filename="../../mainWin.cpp" line="717"/>
<location filename="../../mainWin.cpp" line="771"/>
<location filename="../../mainWin.cpp" line="783"/>
<location filename="../../mainWin.cpp" line="709"/>
<location filename="../../mainWin.cpp" line="719"/>
<location filename="../../mainWin.cpp" line="792"/>
<location filename="../../mainWin.cpp" line="804"/>
<source>Extracting...</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -411,70 +412,77 @@ Please install it for this kind of archive!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="627"/>
<location filename="../../mainWin.cpp" line="635"/>
<location filename="../../mainWin.cpp" line="629"/>
<location filename="../../mainWin.cpp" line="637"/>
<source>Enter Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="639"/>
<location filename="../../mainWin.cpp" line="641"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="640"/>
<location filename="../../mainWin.cpp" line="642"/>
<source>OK</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="644"/>
<location filename="../../mainWin.cpp" line="646"/>
<source>Encrypt the file list</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="645"/>
<location filename="../../mainWin.cpp" line="647"/>
<source>This will take effect after files/folders are added.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="704"/>
<location filename="../../mainWin.cpp" line="767"/>
<location filename="../../mainWin.cpp" line="706"/>
<location filename="../../mainWin.cpp" line="773"/>
<source>Extract Into Directory</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="875"/>
<location filename="../../mainWin.cpp" line="783"/>
<source>Some files will be overwritten.
Do you want to continue?
</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="896"/>
<source>Link To: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1111"/>
<location filename="../../mainWin.cpp" line="1132"/>
<source>A simple Qt archive manager</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1112"/>
<location filename="../../mainWin.cpp" line="1133"/>
<source>based on libarchive, gzip and 7z</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1113"/>
<location filename="../../mainWin.cpp" line="1134"/>
<source>Author</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1114"/>
<location filename="../../mainWin.cpp" line="1135"/>
<source>aka.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1115"/>
<location filename="../../mainWin.cpp" line="1116"/>
<location filename="../../mainWin.cpp" line="1136"/>
<location filename="../../mainWin.cpp" line="1137"/>
<source>About Arqiver</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1115"/>
<location filename="../../mainWin.cpp" line="1136"/>
<source>Translators</source>
<translation type="unfinished"></translation>
</message>
Expand Down
Loading

0 comments on commit 3a8d7fc

Please sign in to comment.