Skip to content

Commit

Permalink
Fixed modifying/copying files as root
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavpandeyvpz committed Nov 6, 2014
1 parent d549f04 commit afa3158
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
34 changes: 25 additions & 9 deletions source/helpers/vpz/apkstudio/helpers/adb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "adb.hpp"
#include <QDebug>

using namespace VPZ::APKStudio::Resources;

Expand Down Expand Up @@ -68,7 +67,7 @@ bool ADB::chmod(const QString &device, const QString &path, const QString &mode,
if (Settings::rootShell()) {
arguments << "su";
arguments << "-c";
arguments << QString(recurse ? "chmod -R %1 \"%2\"" : "chmod %1 \"%2\"").arg(mode, path);
arguments << QString(recurse ? "chmod -R %1 %2" : "chmod %1 %2").arg(mode, quote(path));
} else {
arguments << "chmod";
if (recurse)
Expand All @@ -87,7 +86,7 @@ bool ADB::chown(const QString &device, const QString &path, const QString &owner
if (Settings::rootShell()) {
arguments << "su";
arguments << "-c";
arguments << QString(recurse ? "chown -R %2 \"%3\"" : "chmod %2 \"%3\"").arg(QString("%1:%2").arg(owner, group), path);
arguments << QString(recurse ? "chown -R %1:%2 %3" : "chown %1:%2 %3").arg(owner, group, quote(path));
} else {
arguments << "chown";
if (recurse)
Expand All @@ -106,7 +105,7 @@ bool ADB::copy(const QString &device, const QString &source, const QString &dest
if (Settings::rootShell()) {
arguments << "su";
arguments << "-c";
arguments << QString(recursive ? "cp -R %1 %2" : "cp %1 %2").arg(source, destination);
arguments << QString(recursive ? "cp -R %1 %2" : "cp %1 %2").arg(quote(source), quote(destination));
} else {
arguments << "cp";
if (recursive)
Expand Down Expand Up @@ -188,7 +187,7 @@ QVector<File> ADB::files(const QString &device, const QString &path) const
if (Settings::rootShell()) {
arguments << "su";
arguments << "-c";
arguments << QString("ls -l \"%1\"").arg(path);
arguments << QString("ls -l %1").arg(quote(path));
} else {
arguments << "ls";
arguments << "-l";
Expand Down Expand Up @@ -313,10 +312,10 @@ bool ADB::move(const QString &device, const QStringList &source, const QString &
if (Settings::rootShell()) {
arguments << "su";
arguments << "-c";
arguments << QString("mv %1 %2").arg(source.join(' '), destination);
arguments << QString("mv %1 %2").arg(quote(source), quote(destination));
} else {
arguments << "mv";
arguments << source;
arguments << source.join(' ');
arguments << destination;
}
return execute(arguments).isEmpty();
Expand Down Expand Up @@ -492,6 +491,23 @@ bool ADB::push(const QString &device, const QString &source, const QString &dest
return true;
}

QString ADB::quote(const QString &text) const
{
return quote(QStringList(text));
}

QString ADB::quote(const QStringList &text) const
{
int i = 0;
QString quoted;
foreach (const QString &segment, text) {
if (i++ == 0)
quoted += ' ';
quoted += ("\\\"" + segment + "\\\"");
}
return quoted;
}

void ADB::reboot(const QString &device, const Reboot &mode)
{
QStringList arguments("-s");
Expand Down Expand Up @@ -579,7 +595,7 @@ bool ADB::remove(const QString &device, const QString &path, bool recurse) const
if (Settings::rootShell()) {
arguments << "su";
arguments << "-c";
arguments << QString(recurse ? "rm -R \"%1\"" : "rm \"%1\"").arg(path);
arguments << QString(recurse ? "rm -R %1" : "rm %1").arg(quote(path));
} else {
arguments << "rm";
if (recurse)
Expand All @@ -597,7 +613,7 @@ bool ADB::rename(const QString &device, const QString &source, const QString &de
if (Settings::rootShell()) {
arguments << "su";
arguments << "-c";
arguments << QString("mv \"%1\" \"%2\"").arg(source, destination);
arguments << QString("mv %1 %2").arg(quote(source), quote(destination));
} else {
arguments << "mv";
arguments << source;
Expand Down
2 changes: 2 additions & 0 deletions source/helpers/vpz/apkstudio/helpers/adb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ADB : public CLI
QMap<QString, QString> properties(const QString &) const;
bool pull(const QString &, const QString &, const QString &) const;
bool push(const QString &, const QString &, const QString &) const;
QString quote(const QString &) const;
QString quote(const QStringList &) const;
void reboot(const QString &, const Resources::Reboot &);
bool rename(const QString &, const QString &, const QString &) const;
bool remount(const QString &, const Resources::Partition &);
Expand Down

0 comments on commit afa3158

Please sign in to comment.