mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +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)]));
|
||||
xindex = result.indexOf(xchar, xindex + 1);
|
||||
}
|
||||
result.prepend(underscorechar);
|
||||
result.prepend(KGlobal::mainComponent().componentName());
|
||||
result.prepend(KGlobal::dirs()->saveLocation("tmp"));
|
||||
if (!QDir::isAbsolutePath(result)) {
|
||||
result.prepend(underscorechar);
|
||||
result.prepend(KGlobal::mainComponent().componentName());
|
||||
result.prepend(KGlobal::dirs()->saveLocation("tmp"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -138,8 +138,8 @@ public:
|
|||
* If @p pathtemplate is empty the result will have 10 characters, the
|
||||
* standard temporary directory prepended along with the main component
|
||||
* name. Otherwise any 'X' in @p pathtemplate is replaced with random
|
||||
* character, the standard temporary directory prepended along with the
|
||||
* main component name.
|
||||
* character. The standard temporary directory prepended along with the
|
||||
* main component name unless @p pathtemplate is absolute path.
|
||||
*
|
||||
* @param pathtemplate The template to use when generating filepath.
|
||||
*/
|
||||
|
|
|
@ -27,48 +27,48 @@
|
|||
|
||||
void KTempDirTest::testNoDelete()
|
||||
{
|
||||
KTempDir dir("test");
|
||||
dir.setAutoRemove(false);
|
||||
QVERIFY(dir.status() == 0);
|
||||
QVERIFY(dir.exists());
|
||||
QVERIFY(QDir(dir.name()).exists());
|
||||
KTempDir dir("test");
|
||||
dir.setAutoRemove(false);
|
||||
QVERIFY(dir.status() == 0);
|
||||
QVERIFY(dir.exists());
|
||||
QVERIFY(QDir(dir.name()).exists());
|
||||
|
||||
dir.unlink();
|
||||
QVERIFY(dir.status() == 0);
|
||||
QVERIFY(!dir.exists());
|
||||
QVERIFY(!QDir(dir.name()).exists());
|
||||
dir.unlink();
|
||||
QVERIFY(dir.status() == 0);
|
||||
QVERIFY(!dir.exists());
|
||||
QVERIFY(!QDir(dir.name()).exists());
|
||||
}
|
||||
|
||||
void KTempDirTest::testAutoDelete()
|
||||
{
|
||||
KTempDir *dir = new KTempDir("test");
|
||||
QVERIFY(dir->status() == 0);
|
||||
QVERIFY(dir->exists());
|
||||
KTempDir *dir = new KTempDir("test");
|
||||
QVERIFY(dir->status() == 0);
|
||||
QVERIFY(dir->exists());
|
||||
|
||||
QString dName = dir->name();
|
||||
delete dir;
|
||||
QVERIFY(!QDir(dName).exists());
|
||||
QString dName = dir->name();
|
||||
delete dir;
|
||||
QVERIFY(!QDir(dName).exists());
|
||||
}
|
||||
|
||||
void KTempDirTest::testCreateSubDir()
|
||||
{
|
||||
KTempDir *dir = new KTempDir("test");
|
||||
QVERIFY(dir->status() == 0);
|
||||
QVERIFY(dir->exists());
|
||||
KTempDir *dir = new KTempDir("test");
|
||||
QVERIFY(dir->status() == 0);
|
||||
QVERIFY(dir->exists());
|
||||
|
||||
QDir d ( dir->name() );
|
||||
QVERIFY(d.exists());
|
||||
QDir d ( dir->name() );
|
||||
QVERIFY(d.exists());
|
||||
|
||||
QVERIFY(d.mkdir(QString("123")));
|
||||
QVERIFY(d.mkdir(QString("456")));
|
||||
QVERIFY(d.mkdir(QString("123")));
|
||||
QVERIFY(d.mkdir(QString("456")));
|
||||
|
||||
QString dName = dir->name();
|
||||
delete dir;
|
||||
d.refresh();
|
||||
QString dName = dir->name();
|
||||
delete dir;
|
||||
d.refresh();
|
||||
|
||||
QVERIFY(!QDir(dName).exists());
|
||||
QVERIFY(!d.exists(QString("123")));
|
||||
QVERIFY(!d.exists(QString("456")));
|
||||
QVERIFY(!QDir(dName).exists());
|
||||
QVERIFY(!d.exists(QString("123")));
|
||||
QVERIFY(!d.exists(QString("456")));
|
||||
}
|
||||
|
||||
QTEST_KDEMAIN_CORE(KTempDirTest)
|
||||
|
|
|
@ -25,9 +25,10 @@ class KTempDirTest : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void testNoDelete();
|
||||
void testAutoDelete();
|
||||
void testCreateSubDir();
|
||||
void testNoDelete();
|
||||
void testAutoDelete();
|
||||
void testCreateSubDir();
|
||||
void testCreateSubDir();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // KTEMPDIRTEST_H
|
||||
|
|
|
@ -98,3 +98,15 @@ void KTemporaryFileTest::testKTemporaryFile()
|
|||
//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 cleanupTestCase();
|
||||
void testKTemporaryFile();
|
||||
void testFilePath();
|
||||
|
||||
private:
|
||||
QString kdeTempDir;
|
||||
QString componentName;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // KTEMPORARYFILETEST_H
|
||||
|
|
Loading…
Add table
Reference in a new issue