mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdecore: do not prepend the temporary directory and main component name if template is absolute path from KTemporaryFile::filePath()
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
8224768f2a
commit
b287467137
6 changed files with 54 additions and 38 deletions
|
@ -100,8 +100,10 @@ QString KTemporaryFile::filePath(const QString &pathtemplate)
|
||||||
result.replace(xindex, 1, QChar::fromLatin1(tmpnamechars[KRandom::randomMax(52)]));
|
result.replace(xindex, 1, QChar::fromLatin1(tmpnamechars[KRandom::randomMax(52)]));
|
||||||
xindex = result.indexOf(xchar, xindex + 1);
|
xindex = result.indexOf(xchar, xindex + 1);
|
||||||
}
|
}
|
||||||
result.prepend(underscorechar);
|
if (!QDir::isAbsolutePath(result)) {
|
||||||
result.prepend(KGlobal::mainComponent().componentName());
|
result.prepend(underscorechar);
|
||||||
result.prepend(KGlobal::dirs()->saveLocation("tmp"));
|
result.prepend(KGlobal::mainComponent().componentName());
|
||||||
|
result.prepend(KGlobal::dirs()->saveLocation("tmp"));
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,8 +138,8 @@ public:
|
||||||
* If @p pathtemplate is empty the result will have 10 characters, the
|
* If @p pathtemplate is empty the result will have 10 characters, the
|
||||||
* standard temporary directory prepended along with the main component
|
* standard temporary directory prepended along with the main component
|
||||||
* name. Otherwise any 'X' in @p pathtemplate is replaced with random
|
* name. Otherwise any 'X' in @p pathtemplate is replaced with random
|
||||||
* character, the standard temporary directory prepended along with the
|
* character. The standard temporary directory prepended along with the
|
||||||
* main component name.
|
* main component name unless @p pathtemplate is absolute path.
|
||||||
*
|
*
|
||||||
* @param pathtemplate The template to use when generating filepath.
|
* @param pathtemplate The template to use when generating filepath.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,48 +27,48 @@
|
||||||
|
|
||||||
void KTempDirTest::testNoDelete()
|
void KTempDirTest::testNoDelete()
|
||||||
{
|
{
|
||||||
KTempDir dir("test");
|
KTempDir dir("test");
|
||||||
dir.setAutoRemove(false);
|
dir.setAutoRemove(false);
|
||||||
QVERIFY(dir.status() == 0);
|
QVERIFY(dir.status() == 0);
|
||||||
QVERIFY(dir.exists());
|
QVERIFY(dir.exists());
|
||||||
QVERIFY(QDir(dir.name()).exists());
|
QVERIFY(QDir(dir.name()).exists());
|
||||||
|
|
||||||
dir.unlink();
|
dir.unlink();
|
||||||
QVERIFY(dir.status() == 0);
|
QVERIFY(dir.status() == 0);
|
||||||
QVERIFY(!dir.exists());
|
QVERIFY(!dir.exists());
|
||||||
QVERIFY(!QDir(dir.name()).exists());
|
QVERIFY(!QDir(dir.name()).exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
void KTempDirTest::testAutoDelete()
|
void KTempDirTest::testAutoDelete()
|
||||||
{
|
{
|
||||||
KTempDir *dir = new KTempDir("test");
|
KTempDir *dir = new KTempDir("test");
|
||||||
QVERIFY(dir->status() == 0);
|
QVERIFY(dir->status() == 0);
|
||||||
QVERIFY(dir->exists());
|
QVERIFY(dir->exists());
|
||||||
|
|
||||||
QString dName = dir->name();
|
QString dName = dir->name();
|
||||||
delete dir;
|
delete dir;
|
||||||
QVERIFY(!QDir(dName).exists());
|
QVERIFY(!QDir(dName).exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
void KTempDirTest::testCreateSubDir()
|
void KTempDirTest::testCreateSubDir()
|
||||||
{
|
{
|
||||||
KTempDir *dir = new KTempDir("test");
|
KTempDir *dir = new KTempDir("test");
|
||||||
QVERIFY(dir->status() == 0);
|
QVERIFY(dir->status() == 0);
|
||||||
QVERIFY(dir->exists());
|
QVERIFY(dir->exists());
|
||||||
|
|
||||||
QDir d ( dir->name() );
|
QDir d ( dir->name() );
|
||||||
QVERIFY(d.exists());
|
QVERIFY(d.exists());
|
||||||
|
|
||||||
QVERIFY(d.mkdir(QString("123")));
|
QVERIFY(d.mkdir(QString("123")));
|
||||||
QVERIFY(d.mkdir(QString("456")));
|
QVERIFY(d.mkdir(QString("456")));
|
||||||
|
|
||||||
QString dName = dir->name();
|
QString dName = dir->name();
|
||||||
delete dir;
|
delete dir;
|
||||||
d.refresh();
|
d.refresh();
|
||||||
|
|
||||||
QVERIFY(!QDir(dName).exists());
|
QVERIFY(!QDir(dName).exists());
|
||||||
QVERIFY(!d.exists(QString("123")));
|
QVERIFY(!d.exists(QString("123")));
|
||||||
QVERIFY(!d.exists(QString("456")));
|
QVERIFY(!d.exists(QString("456")));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_KDEMAIN_CORE(KTempDirTest)
|
QTEST_KDEMAIN_CORE(KTempDirTest)
|
||||||
|
|
|
@ -25,9 +25,10 @@ class KTempDirTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void testNoDelete();
|
void testNoDelete();
|
||||||
void testAutoDelete();
|
void testAutoDelete();
|
||||||
void testCreateSubDir();
|
void testCreateSubDir();
|
||||||
|
void testCreateSubDir();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // KTEMPDIRTEST_H
|
||||||
|
|
|
@ -98,3 +98,15 @@ void KTemporaryFileTest::testKTemporaryFile()
|
||||||
//directories we have write access to?
|
//directories we have write access to?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KTemporaryFileTest::testFilePath()
|
||||||
|
{
|
||||||
|
const QString tmpdir = KGlobal::dirs()->saveLocation("tmp");
|
||||||
|
|
||||||
|
QString tmpfilepath = KTemporaryFile::filePath();
|
||||||
|
QVERIFY(tmpfilepath.startsWith(tmpdir));
|
||||||
|
QVERIFY(!tmpfilepath.contains('X'));
|
||||||
|
|
||||||
|
tmpfilepath = KTemporaryFile::filePath("/foo/bar/XXXXX.tmp");
|
||||||
|
QVERIFY(tmpfilepath.startsWith(QLatin1String("/foo/bar/")));
|
||||||
|
QVERIFY(!tmpfilepath.contains('X'));
|
||||||
|
}
|
||||||
|
|
|
@ -17,10 +17,11 @@ private slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
void testKTemporaryFile();
|
void testKTemporaryFile();
|
||||||
|
void testFilePath();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString kdeTempDir;
|
QString kdeTempDir;
|
||||||
QString componentName;
|
QString componentName;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // KTEMPORARYFILETEST_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue