FileSystem: Reuse the FileInfo object that is created in the caller.

With that, a lot of stats can be avoided, ie. in SocketAPI
This commit is contained in:
Klaas Freitag 2015-10-09 13:02:02 +02:00
parent 74a7755ad9
commit 419d18c128
4 changed files with 16 additions and 8 deletions

View file

@ -156,7 +156,7 @@ void Folder::checkLocalPath()
if( fi.isDir() && fi.isReadable() ) {
qDebug() << "Checked local path ok";
} else {
if( !FileSystem::fileExists(_definition.localPath) ) {
if( !FileSystem::fileExists(_definition.localPath, fi) ) {
// try to create the local dir
QDir d(_definition.localPath);
if( d.mkpath(_definition.localPath) ) {
@ -164,7 +164,7 @@ void Folder::checkLocalPath()
}
}
// Check directory again
if( !FileSystem::fileExists(_definition.localPath) ) {
if( !FileSystem::fileExists(_definition.localPath, fi) ) {
_syncResult.setErrorString(tr("Local folder %1 does not exist.").arg(_definition.localPath));
_syncResult.setStatus( SyncResult::SetupError );
} else if( !fi.isDir() ) {

View file

@ -517,7 +517,8 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa
fileNameSlash += QLatin1Char('/');
}
if( !FileSystem::fileExists(file) ) {
const QFileInfo fi(file);
if( !FileSystem::fileExists(file, fi) ) {
qDebug() << "OO File " << file << " is not existing";
return SyncFileStatus(SyncFileStatus::STATUS_STAT_ERROR);
}
@ -525,7 +526,6 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa
// file is ignored?
// Qt considers .lnk files symlinks on Windows so we need to work
// around that here.
const QFileInfo fi(file);
if( fi.isSymLink()
#ifdef Q_OS_WIN
&& fi.suffix() != "lnk"

View file

@ -403,7 +403,7 @@ static bool fileExistsWin(const QString& filename)
}
#endif
bool FileSystem::fileExists(const QString& filename)
bool FileSystem::fileExists(const QString& filename, const QFileInfo& fileInfo)
{
#ifdef Q_OS_WIN
if (isLnkFile(filename)) {
@ -411,8 +411,15 @@ bool FileSystem::fileExists(const QString& filename)
return fileExistsWin(filename);
}
#endif
QFileInfo file(filename);
return file.exists();
bool re = fileInfo.exists();
// if the filename is different from the filename in fileInfo, the fileInfo is
// not valid. There needs to be one initialised here. Otherwise the incoming
// fileInfo is re-used.
if( fileInfo.filePath() != filename ) {
QFileInfo myFI(filename);
re = myFI.exists();
}
return re;
}
#ifdef Q_OS_WIN

View file

@ -18,6 +18,7 @@
#include <QString>
#include <ctime>
#include <QCryptographicHash>
#include <QFileInfo>
#include <owncloudlib.h>
@ -73,7 +74,7 @@ qint64 OWNCLOUDSYNC_EXPORT getSize(const QString& filename);
* Use this over QFileInfo::exists() and QFile::exists() to avoid bugs with lnk
* files, see above.
*/
bool OWNCLOUDSYNC_EXPORT fileExists(const QString& filename);
bool OWNCLOUDSYNC_EXPORT fileExists(const QString& filename, const QFileInfo& = QFileInfo() );
/**
* @brief Rename the file \a originFileName to \a destinationFileName.