Skip to content

Commit

Permalink
Fixed archiving of files from different folders
Browse files Browse the repository at this point in the history
Also fixed a mistake in choosing the archive name.
  • Loading branch information
tsujan committed Oct 24, 2019
1 parent d260bee commit 8c889f6
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 290 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
V0.3.1
---------
* Fixed archiving of files from different folders.
* Fixed a mistake in choosing the archive name on compressing a folder.

V0.3.0
---------
* Eliminated a rare cause of crash, when the file list contains "/" and "//" (with "application/x-archive", for example).
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 Oct 2019, V0.3.0
25 Oct 2019, V0.3.1

See "ChangeLog" for changes.
58 changes: 30 additions & 28 deletions backends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,31 +199,32 @@ static inline void skipExistingFiles(QString& file) {
file += suffix;
}

void Backend::startAdd(QStringList& paths, bool absolutePaths) {
void Backend::startAdd(const QStringList& paths, bool absolutePaths) {
keyArgs_.clear();
QStringList filePaths = paths;
/* exclude the archive itself */
if (paths.contains(filepath_))
paths.removeAll(filepath_);
if (filePaths.contains(filepath_))
filePaths.removeAll(filepath_);
/* no path should be a parent folder of the archive */
QString parentDir = filepath_.section("/", 0, -2);
for (int i = 0; !paths.isEmpty() && i < paths.length(); i++) {
if (parentDir.startsWith (paths[i])) {
paths.removeAt(i);
for (int i = 0; !filePaths.isEmpty() && i < filePaths.length(); i++) {
if (parentDir.startsWith (filePaths[i])) {
filePaths.removeAt(i);
i--;
}
}

if(paths.isEmpty()) return;
if(filePaths.isEmpty()) return;
/* no path should be repeated */
paths.removeDuplicates();
filePaths.removeDuplicates();

QStringList args;
if (isGzip_) {
emit processStarting();
if (QFile::exists(filepath_)) // the overwrite prompt should be already accepted
args << "--to-stdout" << "--force" << paths[0];
args << "--to-stdout" << "--force" << filePaths[0];
else
args << "--to-stdout" << paths[0];
args << "--to-stdout" << filePaths[0];
QProcess tmpProc;
tmpProc.setStandardOutputFile(filepath_);
tmpProc.start("gzip", args); // "gzip -c (-f) file > archive.gz"
Expand All @@ -248,36 +249,36 @@ void Backend::startAdd(QStringList& paths, bool absolutePaths) {
args << "-p" + pswrd_;
encrypted_ = true;
}
args << "a" << fileArgs_ << paths;
args << "a" << fileArgs_ << filePaths;
starting7z_ = true;
keyArgs_ << "a";
proc_.start ("7z", args);
return;
}
/* NOTE: All paths should have the same parent directory.
Check that and put the wrong paths into insertQueue_. */
QString parent = paths[0].section("/", 0, -2);
QString parent = filePaths[0].section("/", 0, -2);
insertQueue_.clear();
for (int i = 1; i < paths.length(); i++) {
if (paths[i].section("/", 0, -2) != parent) {
insertQueue_ << paths.takeAt(i);
for (int i = 1; i < filePaths.length(); i++) {
if (filePaths[i].section("/", 0, -2) != parent) {
insertQueue_ << filePaths.takeAt(i);
i--;
}
}
args << "-c" << "-a";
args << fileArgs_;
/* now, setup the parent dir */
if (!absolutePaths) {
for (int i = 0; i < paths.length(); i++) {
paths[i] = paths[i].section(parent, 1, -1);
if (paths[i].startsWith("/"))
paths[i].remove(0, 1);
for (int i = 0; i < filePaths.length(); i++) {
filePaths[i] = filePaths[i].section(parent, 1, -1);
if (filePaths[i].startsWith("/"))
filePaths[i].remove(0, 1);
}
args << "-C" << parent;
}
else
args << "-C" << "/";
args << paths;
args << filePaths;
if (QFile::exists(filepath_)) { // append to the existing archive
skipExistingFiles(tmpfilepath_); // practically not required
args.replaceInStrings(filepath_, tmpfilepath_);
Expand All @@ -287,19 +288,20 @@ void Backend::startAdd(QStringList& paths, bool absolutePaths) {
proc_.start(TAR_CMD, args);
}

void Backend::startRemove(QStringList& paths) {
void Backend::startRemove(const QStringList& paths) {
keyArgs_.clear();
if (isGzip_) return;
if (paths.contains(filepath_))
paths.removeAll(filepath_);
if (contents_.isEmpty() || paths.isEmpty() || !QFile::exists(filepath_))
QStringList filePaths = paths;
if (filePaths.contains(filepath_))
filePaths.removeAll(filepath_);
if (contents_.isEmpty() || filePaths.isEmpty() || !QFile::exists(filepath_))
return; // invalid
paths.removeDuplicates();
filePaths.removeDuplicates();
QStringList args;
if (is7z_) {
if (encrypted_)
args << "-p" + pswrd_;
args << "d" << fileArgs_ << paths;
args << "d" << fileArgs_ << filePaths;
starting7z_ = true;
keyArgs_ << "d";
proc_.start("7z", args);
Expand All @@ -309,8 +311,8 @@ void Backend::startRemove(QStringList& paths) {
args << fileArgs_;
skipExistingFiles(tmpfilepath_); // practically not required
args.replaceInStrings(filepath_, tmpfilepath_);
for (int i = 0; i < paths.length(); i++) {
args << "--exclude" << paths[i];
for (int i = 0; i < filePaths.length(); i++) {
args << "--exclude" << filePaths[i];
}
args << "@" + filepath_;
keyArgs_ << "-c" << "-a" << "--exclude";
Expand Down
4 changes: 2 additions & 2 deletions backends.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class Backend : public QObject{
bool isLink(const QString& file);
QString linkTo(const QString& file);

void startAdd(QStringList& paths, bool absolutePaths = false);
void startRemove(QStringList& paths);
void startAdd(const QStringList& paths, bool absolutePaths = false);
void startRemove(const QStringList& paths);
void startExtract(const QString& path, const QString& file = QString(), bool overwrite = true, bool preservePaths = true);
void startExtract(const QString& path, const QStringList& files, bool overwrite = true, bool preservePaths = true);

Expand Down
100 changes: 50 additions & 50 deletions data/translations/arqiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@
<context>
<name>Arqiver::Backend</name>
<message>
<location filename="../../backends.cpp" line="817"/>
<location filename="../../backends.cpp" line="860"/>
<location filename="../../backends.cpp" line="819"/>
<location filename="../../backends.cpp" line="862"/>
<source>Could not read archive</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="820"/>
<location filename="../../backends.cpp" line="865"/>
<location filename="../../backends.cpp" line="822"/>
<location filename="../../backends.cpp" line="867"/>
<source>Archive Loaded</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="827"/>
<location filename="../../backends.cpp" line="913"/>
<location filename="../../backends.cpp" line="829"/>
<location filename="../../backends.cpp" line="915"/>
<source>Modification Finished</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="848"/>
<location filename="../../backends.cpp" line="882"/>
<location filename="../../backends.cpp" line="850"/>
<location filename="../../backends.cpp" line="884"/>
<source>Extraction Finished</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="851"/>
<location filename="../../backends.cpp" line="901"/>
<location filename="../../backends.cpp" line="853"/>
<location filename="../../backends.cpp" line="903"/>
<source>Extraction Failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="994"/>
<location filename="../../backends.cpp" line="996"/>
<source>%1 is missing from your system.
Please install it for this kind of archive!</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -249,8 +249,8 @@ Clear text with the Escape key.</source>
</message>
<message>
<location filename="../../mainWin.cpp" line="331"/>
<location filename="../../mainWin.cpp" line="586"/>
<location filename="../../mainWin.cpp" line="622"/>
<location filename="../../mainWin.cpp" line="581"/>
<location filename="../../mainWin.cpp" line="617"/>
<source>Opening Archive...</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -372,138 +372,138 @@ Clear text with the Escape key.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="522"/>
<location filename="../../mainWin.cpp" line="517"/>
<source>Create Archive</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="548"/>
<location filename="../../mainWin.cpp" line="948"/>
<location filename="../../mainWin.cpp" line="543"/>
<location filename="../../mainWin.cpp" line="943"/>
<source>Question</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="549"/>
<location filename="../../mainWin.cpp" line="544"/>
<source>The following archive already exists:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="551"/>
<location filename="../../mainWin.cpp" line="546"/>
<source>Do you want to replace it?
</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="578"/>
<location filename="../../mainWin.cpp" line="573"/>
<source>Open Archive</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="637"/>
<location filename="../../mainWin.cpp" line="645"/>
<location filename="../../mainWin.cpp" line="680"/>
<location filename="../../mainWin.cpp" line="632"/>
<location filename="../../mainWin.cpp" line="640"/>
<location filename="../../mainWin.cpp" line="675"/>
<source>Add to Archive</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="675"/>
<location filename="../../mainWin.cpp" line="705"/>
<location filename="../../mainWin.cpp" line="906"/>
<location filename="../../mainWin.cpp" line="912"/>
<location filename="../../mainWin.cpp" line="670"/>
<location filename="../../mainWin.cpp" line="700"/>
<location filename="../../mainWin.cpp" line="901"/>
<location filename="../../mainWin.cpp" line="907"/>
<source>Adding Items...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="739"/>
<location filename="../../mainWin.cpp" line="734"/>
<source>Removing Items...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="753"/>
<location filename="../../mainWin.cpp" line="873"/>
<location filename="../../mainWin.cpp" line="884"/>
<location filename="../../mainWin.cpp" line="961"/>
<location filename="../../mainWin.cpp" line="975"/>
<location filename="../../mainWin.cpp" line="748"/>
<location filename="../../mainWin.cpp" line="868"/>
<location filename="../../mainWin.cpp" line="879"/>
<location filename="../../mainWin.cpp" line="956"/>
<location filename="../../mainWin.cpp" line="970"/>
<source>Extracting...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="766"/>
<location filename="../../mainWin.cpp" line="761"/>
<source>View Current Item</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="777"/>
<location filename="../../mainWin.cpp" line="785"/>
<location filename="../../mainWin.cpp" line="772"/>
<location filename="../../mainWin.cpp" line="780"/>
<source>Enter Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="789"/>
<location filename="../../mainWin.cpp" line="784"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="790"/>
<location filename="../../mainWin.cpp" line="785"/>
<source>OK</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="794"/>
<location filename="../../mainWin.cpp" line="789"/>
<source>Encrypt the file list</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="795"/>
<location filename="../../mainWin.cpp" line="790"/>
<source>This will take effect after files/folders are added.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="866"/>
<location filename="../../mainWin.cpp" line="938"/>
<location filename="../../mainWin.cpp" line="861"/>
<location filename="../../mainWin.cpp" line="933"/>
<source>Extract Into Directory</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="949"/>
<location filename="../../mainWin.cpp" line="944"/>
<source>Some files will be overwritten.
Do you want to continue?
</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1067"/>
<location filename="../../mainWin.cpp" line="1062"/>
<source>Link To: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1320"/>
<location filename="../../mainWin.cpp" line="1315"/>
<source>A simple Qt archive manager</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1321"/>
<location filename="../../mainWin.cpp" line="1316"/>
<source>based on libarchive, gzip and 7z</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1322"/>
<location filename="../../mainWin.cpp" line="1317"/>
<source>Author</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1323"/>
<location filename="../../mainWin.cpp" line="1318"/>
<source>aka.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1324"/>
<location filename="../../mainWin.cpp" line="1325"/>
<location filename="../../mainWin.cpp" line="1319"/>
<location filename="../../mainWin.cpp" line="1320"/>
<source>About Arqiver</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../mainWin.cpp" line="1324"/>
<location filename="../../mainWin.cpp" line="1319"/>
<source>Translators</source>
<translation type="unfinished"></translation>
</message>
Expand Down
Loading

0 comments on commit 8c889f6

Please sign in to comment.