Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/files fixes for windows and logs #3370

Merged
merged 3 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/common/filesystembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "filesystembase.h"
#include "utility.h"
#include "common/asserts.h"

#include <QDateTime>
#include <QDir>
Expand Down Expand Up @@ -204,14 +205,8 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName,
(wchar_t *)dest.utf16(),
MOVEFILE_REPLACE_EXISTING + MOVEFILE_COPY_ALLOWED + MOVEFILE_WRITE_THROUGH);
if (!ok) {
wchar_t *string = 0;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, ::GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&string, 0, nullptr);

*errorString = QString::fromWCharArray(string);
*errorString = Utility::formatWinError(GetLastError());
qCWarning(lcFileSystem) << "Renaming temp file to final failed: " << *errorString;
LocalFree((HLOCAL)string);
return false;
}
#endif
Expand Down Expand Up @@ -448,13 +443,13 @@ bool FileSystem::moveToTrash(const QString &fileName, QString *errorString)
bool FileSystem::isFileLocked(const QString &fileName)
{
#ifdef Q_OS_WIN
const wchar_t *wuri = reinterpret_cast<const wchar_t *>(fileName.utf16());
// Check if file exists
DWORD attr = GetFileAttributesW(wuri);
const QString fName = longWinPath(fileName);
DWORD attr = GetFileAttributesW(reinterpret_cast<const wchar_t *>(fName.utf16()));
if (attr != INVALID_FILE_ATTRIBUTES) {
// Try to open the file with as much access as possible..
HANDLE win_h = CreateFileW(
wuri,
reinterpret_cast<const wchar_t *>(fName.utf16()),
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_EXISTING,
Expand Down Expand Up @@ -492,7 +487,7 @@ bool FileSystem::isJunction(const QString &filename)
{
#ifdef Q_OS_WIN
WIN32_FIND_DATA findData;
HANDLE hFind = FindFirstFileEx((const wchar_t *)filename.utf16(), FindExInfoBasic, &findData, FindExSearchNameMatch, nullptr, 0);
HANDLE hFind = FindFirstFileEx(reinterpret_cast<const wchar_t *>(longWinPath(filename).utf16()), FindExInfoBasic, &findData, FindExSearchNameMatch, nullptr, 0);
if (hFind != INVALID_HANDLE_VALUE) {
FindClose(hFind);
return false;
Expand All @@ -509,6 +504,7 @@ bool FileSystem::isJunction(const QString &filename)
#ifdef Q_OS_WIN
QString FileSystem::pathtoUNC(const QString &_str)
{
Q_ASSERT(QFileInfo(_str).isAbsolute());
if (_str.isEmpty()) {
return _str;
}
Expand All @@ -522,6 +518,7 @@ QString FileSystem::pathtoUNC(const QString &_str)
// prepend \\?\ and to support long names

if (str.at(0) == sep) {
// should not happen as we require the path to be absolute
return QStringLiteral(R"(\\?)") + str;
}
return QStringLiteral(R"(\\?\)") + str;
Expand Down
3 changes: 2 additions & 1 deletion src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "config.h"

#include "common/utility.h"
#include "common/filesystembase.h"
#include "version.h"

// Note: This file must compile without QtGui
Expand Down Expand Up @@ -229,7 +230,7 @@ qint64 Utility::freeDiskSpace(const QString &path)
#elif defined(Q_OS_WIN)
ULARGE_INTEGER freeBytes;
freeBytes.QuadPart = 0L;
if (GetDiskFreeSpaceEx(reinterpret_cast<const wchar_t *>(path.utf16()), &freeBytes, nullptr, nullptr)) {
if (GetDiskFreeSpaceEx(reinterpret_cast<const wchar_t *>(FileSystem::longWinPath(path).utf16()), &freeBytes, nullptr, nullptr)) {
return freeBytes.QuadPart;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ bool OwncloudPropagator::localFileNameClash(const QString &relFile)
WIN32_FIND_DATA FindFileData;
HANDLE hFind;

hFind = FindFirstFileW((wchar_t *)file.utf16(), &FindFileData);
hFind = FindFirstFileW(reinterpret_cast<const wchar_t *>(FileSystem::longWinPath(file).utf16()), &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
// returns false.
} else {
Expand Down Expand Up @@ -582,7 +582,7 @@ bool OwncloudPropagator::hasCaseClashAccessibilityProblem(const QString &relfile
WIN32_FIND_DATA FindFileData;
HANDLE hFind;

hFind = FindFirstFileW(reinterpret_cast<const wchar_t *>(file.utf16()), &FindFileData);
hFind = FindFirstFileW(reinterpret_cast<const wchar_t *>(FileSystem::longWinPath(file).utf16()), &FindFileData);
if (hFind != INVALID_HANDLE_VALUE) {
QString firstFile = QString::fromWCharArray(FindFileData.cFileName);
if (FindNextFile(hFind, &FindFileData)) {
Expand Down