Skip to content

Commit

Permalink
fix: Do not use the "/tmp" directory
Browse files Browse the repository at this point in the history
  • Loading branch information
zccrs committed May 31, 2019
1 parent 1268024 commit be8ebab
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/src/corelib/ddevicediskinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ bool DDeviceDiskInfoPrivate::openDataStream(int index)

if (currentMode == DDiskInfo::Read) {
const QString &executer = Helper::getPartcloneExecuter(part);
process->start(QStringLiteral("%1 -s %2 -o - -c -z %3 -L /tmp/partclone.log").arg(executer).arg(part.filePath()).arg(Global::bufferSize), QIODevice::ReadOnly);
process->start(QStringLiteral("%1 -s %2 -o - -c -z %3 -L /var/log/partclone.log").arg(executer).arg(part.filePath()).arg(Global::bufferSize), QIODevice::ReadOnly);
} else {
process->start(QStringLiteral("partclone.restore -s - -o %2 -z %3 -L /tmp/partclone.log").arg(part.filePath()).arg(Global::bufferSize));
process->start(QStringLiteral("partclone.restore -s - -o %2 -z %3 -L /var/log/partclone.log").arg(part.filePath()).arg(Global::bufferSize));
}

break;
Expand Down
8 changes: 5 additions & 3 deletions app/src/corelib/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ int Helper::processExec(QProcess *process, const QString &command, int timeout,
if (process->state() != QProcess::NotRunning) {
dCDebug("The \"%s\" timeout, timeout: %d", qPrintable(command), timeout);

// QT Bug,某种情况下(未知) QProcess::state 返回的状态有误,导致进程已退出却未能正确获取到其当前状态
// 因此,额外通过系统文件判断进程是否还存在
if (QFile::exists(QString("/proc/%1").arg(process->pid()))) {
process->terminate();
process->waitForFinished();
Expand Down Expand Up @@ -331,7 +333,7 @@ bool Helper::getPartitionSizeInfo(const QString &partDevice, qint64 *used, qint6

return true;
} else {
process.start(QString("%1 -s %2 -c -q -C -L /tmp/partclone.log").arg(getPartcloneExecuter(DDevicePartInfo(partDevice))).arg(partDevice));
process.start(QString("%1 -s %2 -c -q -C -L /var/log/partclone.log").arg(getPartcloneExecuter(DDevicePartInfo(partDevice))).arg(partDevice));
process.setStandardOutputFile("/dev/null");
process.setReadChannel(QProcess::StandardError);
process.waitForStarted();
Expand Down Expand Up @@ -501,9 +503,9 @@ QString Helper::temporaryMountDevice(const QString &device, const QString &name,
return mount_point;

mount_point = "%1/.%2/mount/%3";
const QStringList &tmp_paths = QStandardPaths::standardLocations(QStandardPaths::TempLocation);
const QStringList &tmp_paths = QStandardPaths::standardLocations(QStandardPaths::RuntimeLocation);

mount_point = mount_point.arg(tmp_paths.isEmpty() ? "/tmp" : tmp_paths.first()).arg(qApp->applicationName()).arg(name);
mount_point = mount_point.arg(tmp_paths.isEmpty() ? "/run/user/0" : tmp_paths.first()).arg(qApp->applicationName()).arg(name);

if (!QDir::current().mkpath(mount_point)) {
dCError("mkpath \"%s\" failed", qPrintable(mount_point));
Expand Down
2 changes: 2 additions & 0 deletions app/src/corelib/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class Helper : public QObject
static QString parseSerialUrl(const QString &urlString, QString *errorString = 0);
static QString toSerialUrl(const QString &file);

static bool clearSymlink(const QString &path);

signals:
void newWarning(const QString &message);
void newError(const QString &message);
Expand Down
3 changes: 1 addition & 2 deletions app/src/fixboot/bootdoctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ bool BootDoctor::fix(const QString &partDevice)
}

{
const QStringList &tmp_paths = QStandardPaths::standardLocations(QStandardPaths::TempLocation);
const QString tmp_dir = (tmp_paths.isEmpty() ? "/tmp" : tmp_paths.first()) + "/.deepin-clone";
const QString tmp_dir = "/var/cache/deepin-clone";

if (!QDir::current().mkpath(tmp_dir)) {
dCError("mkpath \"%s\" failed", qPrintable(tmp_dir));
Expand Down
26 changes: 5 additions & 21 deletions app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,36 +102,20 @@ int main(int argc, char *argv[])
ConsoleAppender *consoleAppender = new ConsoleAppender;
consoleAppender->setFormat(logFormat);

RollingFileAppender *rollingFileAppender = new RollingFileAppender("/tmp/.deepin-clone.log");
const QString log_file("/var/log/deepin-clone.log");

RollingFileAppender *rollingFileAppender = new RollingFileAppender(log_file);
rollingFileAppender->setFormat(logFormat);
rollingFileAppender->setLogFilesLimit(5);
rollingFileAppender->setDatePattern(RollingFileAppender::DailyRollover);

logger->registerAppender(consoleAppender);
logger->registerAppender(rollingFileAppender);
logger->registerAppender(consoleAppender);

if (qEnvironmentVariableIsSet("PKEXEC_UID")) {
const quint32 pkexec_uid = qgetenv("PKEXEC_UID").toUInt();
const QDir user_home(getpwuid(pkexec_uid)->pw_dir);

QFile pam_file(user_home.absoluteFilePath(".pam_environment"));

if (pam_file.open(QIODevice::ReadOnly)) {
while (!pam_file.atEnd()) {
const QByteArray &line = pam_file.readLine().simplified();

if (line.startsWith("QT_SCALE_FACTOR")) {
const QByteArrayList &list = line.split('=');

if (list.count() == 2) {
qputenv("QT_SCALE_FACTOR", list.last());
break;
}
}
}

pam_file.close();
}
DApplication::customQtThemeConfigPathByUserHome(getpwuid(pkexec_uid)->pw_dir);
}

DApplication::loadDXcbPlugin();
Expand Down

0 comments on commit be8ebab

Please sign in to comment.