This commit is contained in:
Christian Kamm 2015-02-25 10:51:05 +01:00
Родитель ed315f54e3
Коммит f88398e776
7 изменённых файлов: 101 добавлений и 24 удалений

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

@ -29,6 +29,7 @@
#include "syncengine.h"
#include "syncrunfilelog.h"
#include "theme.h"
#include "filesystem.h"
#include "creds/abstractcredentials.h"
@ -150,7 +151,7 @@ void Folder::checkLocalPath()
if( fi.isDir() && fi.isReadable() ) {
qDebug() << "Checked local path ok";
} else {
if( !fi.exists() ) {
if( !FileSystem::fileExists(fi) ) {
// try to create the local dir
QDir d(_path);
if( d.mkpath(_path) ) {
@ -158,7 +159,7 @@ void Folder::checkLocalPath()
}
}
// Check directory again
if( !fi.exists() ) {
if( !FileSystem::fileExists(fi) ) {
_syncResult.setErrorString(tr("Local folder %1 does not exist.").arg(_path));
_syncResult.setStatus( SyncResult::SetupError );
} else if( !fi.isDir() ) {

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

@ -530,7 +530,7 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa
QFileInfo fi(file);
if( !fi.exists() ) {
if( !FileSystem::fileExists(fi) ) {
qDebug() << "OO File " << file << " is not existing";
return SyncFileStatus(SyncFileStatus::STATUS_STAT_ERROR);
}

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

@ -120,7 +120,7 @@ bool FileSystem::renameReplace(const QString& originFileName, const QString& des
// Qt 5.1 has QSaveFile::renameOverwrite we cold use.
// ### FIXME
success = true;
bool destExists = QFileInfo::exists(destinationFileName);
bool destExists = fileExists(destinationFileName);
if( destExists && !QFile::remove(destinationFileName) ) {
*errorString = orig.errorString();
qDebug() << Q_FUNC_INFO << "Target file could not be removed.";
@ -214,26 +214,90 @@ bool FileSystem::openFileSharedRead(QFile* file, QString* error)
return ok;
}
#ifdef Q_OS_WIN
static bool isLnkFile(const QString& filename)
{
return filename.endsWith(".lnk");
}
static bool isLnkFile(const QFileInfo& fi)
{
return fi.suffix() == "lnk";
}
static qint64 getSizeWithCsync(const QString& filename)
{
qint64 result = 0;
csync_vio_file_stat_t* stat = csync_vio_file_stat_new();
if (csync_vio_local_stat(filename.toUtf8().data(), stat) != -1
&& (stat->fields & CSYNC_VIO_FILE_STAT_FIELDS_SIZE)) {
result = stat->size;
} else {
qDebug() << "Could not get size time for" << filename << "with csync";
}
csync_vio_file_stat_destroy(stat);
return result;
}
#endif
qint64 FileSystem::getSize(const QString& filename)
{
#ifdef Q_OS_WIN
if (filename.endsWith(".lnk")) {
if (isLnkFile(filename)) {
// Use csync to get the file size. Qt seems unable to get at it.
qint64 result = 0;
csync_vio_file_stat_t* stat = csync_vio_file_stat_new();
if (csync_vio_local_stat(filename.toUtf8().data(), stat) != -1
&& (stat->fields & CSYNC_VIO_FILE_STAT_FIELDS_SIZE)) {
result = stat->size;
} else {
qDebug() << "Could not get size time for" << filename << "with csync";
}
csync_vio_file_stat_destroy(stat);
return result;
return getSizeWithCsync(filename);
}
#endif
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)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFileW( (wchar_t*)filename.utf16(), &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
return false;
}
FindClose(hFind);
return true;
}
#endif
bool FileSystem::fileExists(const QString& filename)
{
#ifdef Q_OS_WIN
if (isLnkFile(filename)) {
// Use a native check.
return fileExistsWin(filename);
}
#endif
return QFileInfo::exists(filename);
}
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)
{

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

@ -14,11 +14,13 @@
#pragma once
#include <QString>
#include <QFile>
#include <ctime>
#include <owncloudlib.h>
class QFile;
class QFileInfo;
namespace OCC {
/**
@ -39,7 +41,7 @@ void OWNCLOUDSYNC_EXPORT setFileHidden(const QString& filename, bool hidden);
* Use this over QFileInfo::lastModified() to avoid timezone related bugs. See
* owncloud/core#9781 for details.
*/
time_t OWNCLOUDSYNC_EXPORT getModTime(const QString &filename);
time_t OWNCLOUDSYNC_EXPORT getModTime(const QString& filename);
bool setModTime(const QString &filename, time_t modTime);
@ -49,6 +51,15 @@ 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.
*
* 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 QFileInfo& fi);
/**
* Rename the file \a originFileName to \a destinationFileName, and overwrite the destination if it

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

@ -491,7 +491,7 @@ void PropagateDownloadFileQNAM::downloadFinished()
}
QFileInfo existingFile(fn);
if(existingFile.exists() && existingFile.permissions() != _tmpFile.permissions()) {
if(FileSystem::fileExists(existingFile) && existingFile.permissions() != _tmpFile.permissions()) {
_tmpFile.setPermissions(existingFile.permissions());
}
@ -520,7 +520,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(fn);
_item._size = FileSystem::getSize(existingFile);
_propagator->_journal->setFileRecord(SyncJournalFileRecord(_item, fn));
_propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo());

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

@ -152,14 +152,14 @@ void PropagateUploadFileQNAM::start()
return;
QFileInfo fi(_propagator->getFilePath(_item._file));
if (!fi.exists()) {
if (!FileSystem::fileExists(fi)) {
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.absoluteFilePath());
quint64 fileSize = FileSystem::getSize(fi);
_item._size = fileSize;
// But skip the file if the mtime is too close to 'now'!
@ -509,7 +509,7 @@ void PropagateUploadFileQNAM::slotPutFinished()
QFileInfo fi(_propagator->getFilePath(_item._file));
// Check if the file still exists
if( !fi.exists() ) {
if( !FileSystem::fileExists(fi) ) {
if (!finished) {
abortWithError(SyncFileItem::SoftError, tr("The local file was removed during sync."));
return;
@ -520,7 +520,7 @@ 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.absoluteFilePath()));
const quint64 new_size = static_cast<quint64>(FileSystem::getSize(fi));
if (new_mtime != _item._modtime || new_size != _item._size) {
qDebug() << "The local file has changed during upload:"
<< "mtime: " << _item._modtime << "<->" << new_mtime

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

@ -19,6 +19,7 @@
#include "utility.h"
#include "syncjournaldb.h"
#include "syncjournalfilerecord.h"
#include "filesystem.h"
#include <qfile.h>
#include <qdir.h>
#include <qdiriterator.h>
@ -95,7 +96,7 @@ void PropagateLocalRemove::start()
}
} else {
QFile file(filename);
if (file.exists() && !file.remove()) {
if (FileSystem::fileExists(file) && !file.remove()) {
done(SyncFileItem::NormalError, file.errorString());
return;
}