Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nemo-systemsettings] Cleanup hardcoded nemo user. Fixes JB#47605
  • Loading branch information
rainemak committed Oct 17, 2019
1 parent 2e04b05 commit 1f91b5c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/diskusage.cpp
Expand Up @@ -98,8 +98,8 @@ QVariantMap DiskUsageWorker::calculate(QStringList paths)
// Sort keys in reverse order (so child directories come before their
// parents, and the calculation is done correctly, no child directory
// subtracted once too often), for example:
// 1. a0 = size(/home/nemo/foo/)
// 2. b0 = size(/home/nemo/)
// 1. a0 = size(/home/<user>/foo/)
// 2. b0 = size(/home/<user>/)
// 3. c0 = size(/)
//
// This will calculate the following changes in the nested for loop below:
Expand All @@ -113,9 +113,9 @@ QVariantMap DiskUsageWorker::calculate(QStringList paths)
// 3. c' = c2 = c1 - b1 = (c0 - a0) - (b0 - a0) = c0 - a0 - b0 + a0 = c0 - b0
//
// Or with paths:
// 1. output(/home/nemo/foo/) = size(/home/nemo/foo/)
// 2. output(/home/nemo/) = size(/home/nemo/) - size(/home/nemo/foo/)
// 3. output(/) = size(/) - size(/home/nemo/)
// 1. output(/home/<user>/foo/) = size(/home/<user>/foo/)
// 2. output(/home/<user>/) = size(/home/<user>/) - size(/home/<user>/foo/)
// 3. output(/) = size(/) - size(/home/<user>/)
QStringList keys;
foreach (const QString &key, usage.uniqueKeys()) {
keys << expandedPaths.value(key, key);
Expand Down
26 changes: 13 additions & 13 deletions tests/ut_diskusage.cpp
@@ -1,7 +1,7 @@

/*
* Copyright (C) 2015 Jolla Ltd.
* Contact: Thomas Perl <thomas.perl@jolla.com>
* Copyright (c) 2015 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* You may use this file under the terms of the BSD license as follows:
*
Expand Down Expand Up @@ -37,7 +37,7 @@
#include "ut_diskusage.h"

#include <QtTest>

#include <QDir>

static QVariantMap g_mocked_file_size;
static QVariantMap g_mocked_rpm_size;
Expand Down Expand Up @@ -131,37 +131,37 @@ void Ut_DiskUsage::testSubtractNestedSubdirectory()
{
g_mocked_file_size["/"] = MB(1000);
g_mocked_file_size["/home/"] = MB(300);
g_mocked_file_size["/home/nemo/"] = MB(150);
g_mocked_file_size["/home/nemo/Documents/"] = MB(70);
g_mocked_file_size[QDir::homePath()] = MB(150);
g_mocked_file_size[QDir::homePath() + "/Documents/"] = MB(70);

QVariantMap usage = DiskUsageWorker().calculate(QStringList() <<
"/" << "/home/" << "/home/nemo/" << "/home/nemo/Documents/");
"/" << "/home/" << QDir::homePath() << QDir::homePath() + "/Documents/");

UT_DISKUSAGE_EXPECT_SIZE("/", MB(1000) - MB(300))
UT_DISKUSAGE_EXPECT_SIZE("/home/", MB(300) - MB(150))
UT_DISKUSAGE_EXPECT_SIZE("/home/nemo/", MB(150) - MB(70))
UT_DISKUSAGE_EXPECT_SIZE("/home/nemo/Documents/", MB(70))
UT_DISKUSAGE_EXPECT_SIZE(QDir::homePath(), MB(150) - MB(70))
UT_DISKUSAGE_EXPECT_SIZE(QDir::homePath() + "/Documents/", MB(70))
}

void Ut_DiskUsage::testSubtractNestedSubdirectoryMulti()
{
g_mocked_file_size["/"] = MB(1000);
g_mocked_file_size["/home/"] = MB(300);
g_mocked_file_size["/home/nemo/"] = MB(150);
g_mocked_file_size["/home/nemo/Documents/"] = MB(70);
g_mocked_file_size[QDir::homePath()] = MB(150);
g_mocked_file_size[QDir::homePath() + "/Documents/"] = MB(70);
g_mocked_file_size["/opt/"] = MB(100);
g_mocked_file_size["/opt/foo/"] = MB(30);
g_mocked_file_size["/opt/foo/bar/"] = MB(20);
g_mocked_file_size["/opt/baz/"] = MB(10);

QVariantMap usage = DiskUsageWorker().calculate(QStringList() << "/" <<
"/home/" << "/home/nemo/" << "/home/nemo/Documents/" <<
"/home/" << QDir::homePath() << QDir::homePath() + "/Documents/" <<
"/opt/" << "/opt/foo/" << "/opt/foo/bar/" << "/opt/baz/");

UT_DISKUSAGE_EXPECT_SIZE("/", MB(1000) - MB(300) - MB(100))
UT_DISKUSAGE_EXPECT_SIZE("/home/", MB(300) - MB(150))
UT_DISKUSAGE_EXPECT_SIZE("/home/nemo/", MB(150) - MB(70))
UT_DISKUSAGE_EXPECT_SIZE("/home/nemo/Documents/", MB(70))
UT_DISKUSAGE_EXPECT_SIZE(QDir::homePath(), MB(150) - MB(70))
UT_DISKUSAGE_EXPECT_SIZE(QDir::homePath() + "/Documents/", MB(70))
UT_DISKUSAGE_EXPECT_SIZE("/opt/", MB(100) - MB(30) - MB(10))
UT_DISKUSAGE_EXPECT_SIZE("/opt/foo/", MB(30) - MB(20))
UT_DISKUSAGE_EXPECT_SIZE("/opt/foo/bar/", MB(20))
Expand Down

0 comments on commit 1f91b5c

Please sign in to comment.