kio: replace QFile::exists() with QDir::exists() and QFileInfo::exists() where applicable

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2020-02-03 01:05:44 +00:00
parent 38c049bb36
commit 1d85d63589
3 changed files with 34 additions and 34 deletions

View file

@ -374,12 +374,12 @@ void FileUndoManagerTest::testRenameDir()
bool ok = KIO::NetAccess::synchronousRun( job, 0 );
QVERIFY( ok );
QVERIFY( !QFile::exists( srcSubDir() ) );
QVERIFY( !QDir( srcSubDir() ).exists() );
QVERIFY( QFileInfo( newUrl.toLocalFile() ).isDir() );
doUndo();
QVERIFY( QFile::exists( srcSubDir() ) );
QVERIFY( QDir( srcSubDir() ).exists() );
QVERIFY( !QFileInfo( newUrl.toLocalFile() ).isDir() );
}
@ -387,14 +387,14 @@ void FileUndoManagerTest::testCreateDir()
{
const KUrl url( srcSubDir() + ".mkdir" );
const QString path = url.toLocalFile();
QVERIFY( !QFile::exists(path) );
QVERIFY( !QDir(path).exists() );
KIO::SimpleJob* job = KIO::mkdir(url);
job->setUiDelegate( 0 );
FileUndoManager::self()->recordJob( FileUndoManager::Mkdir, KUrl(), url, job );
bool ok = KIO::NetAccess::synchronousRun( job, 0 );
QVERIFY( ok );
QVERIFY( QFile::exists(path) );
QVERIFY( QDir(path).exists() );
QVERIFY( QFileInfo(path).isDir() );
m_uiInterface->clear();
@ -402,7 +402,7 @@ void FileUndoManagerTest::testCreateDir()
FileUndoManager::self()->undo();
QCOMPARE( m_uiInterface->files().count(), 1 ); // confirmDeletion was called
QCOMPARE( m_uiInterface->files()[0].url(), url.url() );
QVERIFY( QFile::exists(path) ); // nothing happened yet
QVERIFY( QDir(path).exists() ); // nothing happened yet
// OK, now do it
m_uiInterface->clear();
@ -430,7 +430,7 @@ void FileUndoManagerTest::testTrashFiles()
// Check that things got removed
QVERIFY( !QFile::exists( srcFile() ) );
QVERIFY( !QFileInfo( srcLink() ).isSymLink() );
QVERIFY( !QFile::exists( srcSubDir() ) );
QVERIFY( !QDir( srcSubDir() ).exists() );
// check trash?
// Let's just check that it's not empty. kio_trash has its own unit tests anyway.
@ -442,7 +442,7 @@ void FileUndoManagerTest::testTrashFiles()
QVERIFY( QFile::exists( srcFile() ) );
QVERIFY( QFileInfo( srcLink() ).isSymLink() );
QVERIFY( QFile::exists( srcSubDir() ) );
QVERIFY( QDir( srcSubDir() ).exists() );
// We can't check that the trash is empty; other partitions might have their own trash
}

View file

@ -275,18 +275,18 @@ void JobTest::copyLocalDirectory( const QString& src, const QString& _dest, int
KUrl d;
d.setPath( dest );
if ( flags & AlreadyExists )
QVERIFY( QFile::exists( dest ) );
QVERIFY( QDir( dest ).exists() );
else
QVERIFY( !QFile::exists( dest ) );
QVERIFY( !QDir( dest ).exists() );
KIO::Job* job = KIO::copy(u, d, KIO::HideProgressInfo);
job->setUiDelegate(0);
bool ok = KIO::NetAccess::synchronousRun(job, 0);
QVERIFY( ok );
QVERIFY( QFile::exists( dest ) );
QVERIFY( QDir( dest ).exists() );
QVERIFY( QFileInfo( dest ).isDir() );
QVERIFY( QFileInfo( dest + "/testfile" ).isFile() );
QVERIFY( QFile::exists( src ) ); // still there
QVERIFY( QDir( src ).exists() ); // still there
if ( flags & AlreadyExists ) {
dest += '/' + u.fileName();
@ -419,7 +419,7 @@ static void moveLocalSymlink( const QString& src, const QString& dest )
void JobTest::moveLocalDirectory( const QString& src, const QString& dest )
{
kDebug() << src << " " << dest;
QVERIFY( QFile::exists( src ) );
QVERIFY( QDir( src ).exists() );
QVERIFY( QFileInfo( src ).isDir() );
QVERIFY( QFileInfo( src + "/testfile" ).isFile() );
QVERIFY( QFileInfo( src + "/testlink" ).isSymLink() );
@ -432,10 +432,10 @@ void JobTest::moveLocalDirectory( const QString& src, const QString& dest )
job->setUiDelegate( 0 );
bool ok = KIO::NetAccess::synchronousRun(job, 0);
QVERIFY( ok );
QVERIFY( QFile::exists( dest ) );
QVERIFY( QDir( dest).exists() );
QVERIFY( QFileInfo( dest ).isDir() );
QVERIFY( QFileInfo( dest + "/testfile" ).isFile() );
QVERIFY( !QFile::exists( src ) ); // not there anymore
QVERIFY( !QDir( src ).exists() ); // not there anymore
QVERIFY( QFileInfo( dest + "/testlink" ).isSymLink() );
}
@ -516,11 +516,11 @@ void JobTest::moveDirectoryNoPermissions()
// All of /etc is a bit much, so try to find something smaller:
QString src = "/etc/fonts";
if ( !QFile::exists( src ) )
if ( !QDir( src ).exists() )
src = "/etc";
const QString dest = homeTmpDir() + "mdnp";
QVERIFY( QFile::exists( src ) );
QVERIFY( QDir( src ).exists() );
QVERIFY( QFileInfo( src ).isDir() );
KUrl u;
u.setPath( src );
@ -533,8 +533,8 @@ void JobTest::moveDirectoryNoPermissions()
bool ok = KIO::NetAccess::synchronousRun( job, 0, 0, 0, &metaData );
QVERIFY( !ok );
QCOMPARE( KIO::NetAccess::lastError(), (int)KIO::ERR_ACCESS_DENIED );
//QVERIFY( QFile::exists( dest ) ); // see moveFileNoPermissions
QVERIFY( QFile::exists( src ) );
//QVERIFY( QDir( dest ).exists() ); // see moveFileNoPermissions
QVERIFY( QDir( src ).exists() );
}
void JobTest::listRecursive()
@ -1137,20 +1137,20 @@ void JobTest::deleteSymlink(bool using_fast_path)
const QString src = homeTmpDir() + "dirFromHome";
createTestDirectory(src);
QVERIFY(QFile::exists(src));
QVERIFY(QDir(src).exists());
const QString dest = homeTmpDir() + "/dirFromHome_link";
if (!QFile::exists(dest)) {
if (!QDir(dest).exists()) {
// Add a symlink to a dir, to make sure we don't recurse into those
bool symlinkOk = symlink(QFile::encodeName(src), QFile::encodeName(dest)) == 0;
QVERIFY( symlinkOk );
QVERIFY(QFile::exists(dest));
QVERIFY(QDir(dest).exists());
}
KIO::Job* job = KIO::del(KUrl(dest), KIO::HideProgressInfo);
job->setUiDelegate(0);
bool ok = KIO::NetAccess::synchronousRun(job, 0);
QVERIFY(ok);
QVERIFY(!QFile::exists(dest));
QVERIFY(QFile::exists(src));
QVERIFY(!QDir(dest).exists());
QVERIFY(QDir(src).exists());
kio_resolve_local_urls = true;
}
@ -1261,10 +1261,10 @@ void JobTest::rmdirEmpty()
{
const QString dir = homeTmpDir() + "dir";
QDir().mkdir(dir);
QVERIFY(QFile::exists(dir));
QVERIFY(QDir(dir).exists());
KIO::Job* job = KIO::rmdir(dir);
QVERIFY(job->exec());
QVERIFY(!QFile::exists(dir));
QVERIFY(!QDir(dir).exists());
}
void JobTest::rmdirNotEmpty()
@ -1274,7 +1274,7 @@ void JobTest::rmdirNotEmpty()
createTestDirectory(dir + "/subdir");
KIO::Job* job = KIO::rmdir(dir);
QVERIFY(!job->exec());
QVERIFY(QFile::exists(dir));
QVERIFY(QDir(dir).exists());
}
void JobTest::stat()
@ -1404,7 +1404,7 @@ void JobTest::moveDestAlreadyExistsAutoRename()
// cleanup
KIO::Job* job = KIO::del(dir, KIO::HideProgressInfo);
QVERIFY(job->exec());
QVERIFY(!QFile::exists(dir));
QVERIFY(!QDir(dir).exists());
}
}
@ -1435,14 +1435,14 @@ void JobTest::moveDestAlreadyExistsAutoRename(const QString& destDir, bool moveD
kDebug() << QDir(destDir).entryList();
QVERIFY(ok);
QVERIFY(!QFile::exists(file1)); // it was moved
QVERIFY(!QFile::exists(file2)); // it was moved
QVERIFY(QFile::exists(existingDest1));
QVERIFY(QFile::exists(existingDest2));
QVERIFY(!QFileInfo(file1).exists()); // it was moved
QVERIFY(!QFileInfo(file2).exists()); // it was moved
QVERIFY(QFileInfo(existingDest1).exists());
QVERIFY(QFileInfo(existingDest2).exists());
const QString file3 = destDir + prefix + "3";
const QString file4 = destDir + prefix + "4";
QVERIFY(QFile::exists(file3));
QVERIFY(QFile::exists(file4));
QVERIFY(QFileInfo(file3).exists());
QVERIFY(QFileInfo(file4).exists());
if (moveDirs) {
QDir().rmdir(file1);
QDir().rmdir(file2);

View file

@ -32,7 +32,7 @@
QString homeTmpDir()
{
const QString dir(QFile::decodeName(getenv("KDEHOME")) + "/kiotests/");
if (!QFile::exists(dir)) {
if (!QDir(dir).exists()) {
const bool ok = QDir().mkdir(dir);
if ( !ok )
kFatal() << "Couldn't create " << dir;