FileSystem: Remove QFileInfo based implementations.

QFileInfo has to be refreshed if the underlying file has been
modified in between. That is dangerous so ckamm and me decided
to eliminate the QFileInfo based implementations.

This was triggered by a bug that the client uploaded files that
it should not have.
This commit is contained in:
Klaas Freitag 2015-02-27 15:27:49 +01:00
Родитель e381143a8f
Коммит 05624e3fc8
7 изменённых файлов: 20 добавлений и 44 удалений

Просмотреть файл

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

Просмотреть файл

@ -534,9 +534,7 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa
fileNameSlash += QLatin1Char('/');
}
QFileInfo fi(file);
if( !FileSystem::fileExists(fi) ) {
if( !FileSystem::fileExists(file) ) {
qDebug() << "OO File " << file << " is not existing";
return SyncFileStatus(SyncFileStatus::STATUS_STAT_ERROR);
}
@ -544,6 +542,7 @@ 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"

Просмотреть файл

@ -251,17 +251,6 @@ qint64 FileSystem::getSize(const QString& filename)
return QFileInfo(filename).size();
}
qint64 FileSystem::getSize(const QFileInfo& fi)
{
#ifdef Q_OS_WIN
if (isLnkFile(fi)) {
// Use csync to get the file size. Qt seems unable to get at it.
return getSizeWithCsync(fi.absoluteFilePath());
}
#endif
return fi.size();
}
#ifdef Q_OS_WIN
static bool fileExistsWin(const QString& filename)
{
@ -288,17 +277,6 @@ bool FileSystem::fileExists(const QString& filename)
return file.exists();
}
bool FileSystem::fileExists(const QFileInfo& fi)
{
#ifdef Q_OS_WIN
if (isLnkFile(fi)) {
// Use a native check.
return fileExistsWin(fi.absoluteFilePath());
}
#endif
return fi.exists();
}
#ifdef Q_OS_WIN
QString FileSystem::fileSystemForPath(const QString & path)
{

Просмотреть файл

@ -51,7 +51,6 @@ bool setModTime(const QString &filename, time_t modTime);
* See https://bugreports.qt.io/browse/QTBUG-24831.
*/
qint64 OWNCLOUDSYNC_EXPORT getSize(const QString& filename);
qint64 OWNCLOUDSYNC_EXPORT getSize(const QFileInfo& fi);
/** Checks whether a file exists.
*
@ -59,7 +58,6 @@ qint64 OWNCLOUDSYNC_EXPORT getSize(const QFileInfo& fi);
* files, see above.
*/
bool OWNCLOUDSYNC_EXPORT fileExists(const QString& filename);
bool OWNCLOUDSYNC_EXPORT fileExists(const QFileInfo& fi);
/**
* Rename the file \a originFileName to \a destinationFileName, and overwrite the destination if it

Просмотреть файл

@ -502,7 +502,7 @@ void PropagateDownloadFileQNAM::downloadFinished()
}
QFileInfo existingFile(fn);
if(FileSystem::fileExists(existingFile) && existingFile.permissions() != _tmpFile.permissions()) {
if(FileSystem::fileExists(fn) && existingFile.permissions() != _tmpFile.permissions()) {
_tmpFile.setPermissions(existingFile.permissions());
}
@ -531,7 +531,7 @@ void PropagateDownloadFileQNAM::downloadFinished()
// Maybe we downloaded a newer version of the file than we thought we would...
// Get up to date information for the journal.
FileSystem::setModTime(fn, _item._modtime);
_item._size = FileSystem::getSize(existingFile);
_item._size = FileSystem::getSize(fn);
_propagator->_journal->setFileRecord(SyncJournalFileRecord(_item, fn));
_propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo());

Просмотреть файл

@ -155,18 +155,20 @@ bool PollJob::finished()
void PropagateUploadFileQNAM::start()
{
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) {
return;
}
QFileInfo fi(_propagator->getFilePath(_item._file));
if (!FileSystem::fileExists(fi)) {
const QString fullFilePath(_propagator->getFilePath(_item._file));
if (!FileSystem::fileExists(fullFilePath)) {
done(SyncFileItem::SoftError, tr("File Removed"));
return;
}
// Update the mtime and size, it might have changed since discovery.
_item._modtime = FileSystem::getModTime(fi.absoluteFilePath());
quint64 fileSize = FileSystem::getSize(fi);
_item._modtime = FileSystem::getModTime(fullFilePath);
quint64 fileSize = FileSystem::getSize(fullFilePath);
_item._size = fileSize;
// But skip the file if the mtime is too close to 'now'!
@ -515,11 +517,9 @@ void PropagateUploadFileQNAM::slotPutFinished()
bool finished = job->reply()->hasRawHeader("ETag")
|| job->reply()->hasRawHeader("OC-ETag");
QFileInfo fi(_propagator->getFilePath(_item._file));
// Check if the file still exists
if( !FileSystem::fileExists(fi) ) {
const QString fullFilePath(_propagator->getFilePath(_item._file));
if( !FileSystem::fileExists(fullFilePath) ) {
if (!finished) {
abortWithError(SyncFileItem::SoftError, tr("The local file was removed during sync."));
return;
@ -529,8 +529,9 @@ void PropagateUploadFileQNAM::slotPutFinished()
}
// compare expected and real modification time of the file and size
const time_t new_mtime = FileSystem::getModTime(fi.absoluteFilePath());
const quint64 new_size = static_cast<quint64>(FileSystem::getSize(fi));
const time_t new_mtime = FileSystem::getModTime(fullFilePath);
const quint64 new_size = static_cast<quint64>(FileSystem::getSize(fullFilePath));
QFileInfo fi(_propagator->getFilePath(_item._file));
if (new_mtime != _item._modtime || new_size != _item._size) {
qDebug() << "The local file has changed during upload:"
<< "mtime: " << _item._modtime << "<->" << new_mtime

Просмотреть файл

@ -96,7 +96,7 @@ void PropagateLocalRemove::start()
}
} else {
QFile file(filename);
if (FileSystem::fileExists(file) && !file.remove()) {
if (FileSystem::fileExists(filename) && !file.remove()) {
done(SyncFileItem::NormalError, file.errorString());
return;
}