Skip to content

Commit

Permalink
feat: use QStorageInfo::fileSystemType() to get the filesystem type o…
Browse files Browse the repository at this point in the history
…n all platforms
  • Loading branch information
DeepDiver1975 authored and erikjv committed Jan 23, 2025
1 parent d4bb78c commit 1b2d2ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
25 changes: 9 additions & 16 deletions src/common/filesystembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

#include <QCoreApplication>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QSettings>
#include <QStorageInfo>

#include <sys/stat.h>
#include <sys/types.h>
Expand Down Expand Up @@ -200,7 +200,7 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName,
#ifndef Q_OS_WIN
bool success;
QFile orig(originFileName);
// We want a rename that also overwites. QFile::rename does not overwite.
// We want a rename that also overwrites. QFile::rename does not overwrite.
// Qt 5.1 has QSaveFile::renameOverwrite we could use.
// ### FIXME
success = true;
Expand Down Expand Up @@ -343,32 +343,25 @@ bool FileSystem::fileExists(const QString &filename, const QFileInfo &fileInfo)
#endif
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
// not valid. There needs to be one initialised here. Otherwise, the incoming
// fileInfo is re-used.
if (fileInfo.filePath() != filename) {
re = QFileInfo::exists(filename);
}
return re;
}

#ifdef Q_OS_WIN
QString FileSystem::fileSystemForPath(const QString &path)
{
// See also QStorageInfo (Qt >=5.4) and GetVolumeInformationByHandleW (>= Vista)
QString drive = path.left(2);
if (!drive.endsWith(QLatin1Char(':')))
return QString();
drive.append(QLatin1Char('\\'));

const size_t fileSystemBufferSize = 4096;
TCHAR fileSystemBuffer[fileSystemBufferSize];

if (!GetVolumeInformationW(reinterpret_cast<LPCWSTR>(drive.utf16()), nullptr, 0, nullptr, nullptr, nullptr, fileSystemBuffer, fileSystemBufferSize)) {
return QString();
const QStorageInfo storage(path);
if (storage.isValid() && storage.isReady()) {
return {};
}
return QString::fromUtf16(reinterpret_cast<const char16_t *>(fileSystemBuffer));

return QString::fromUtf8(storage.fileSystemType());
}

#ifdef Q_OS_WIN
bool FileSystem::longPathsEnabledOnWindows()
{
static std::optional<bool> longPathsEnabledCached = {};
Expand Down
2 changes: 1 addition & 1 deletion src/common/filesystembase.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ namespace FileSystem {

bool OCSYNC_EXPORT longPathsEnabledOnWindows();

#endif
/**
* Returns the file system used at the given path.
*/
QString OCSYNC_EXPORT fileSystemForPath(const QString &path);
#endif

/**
* Returns whether the file is a shortcut file (ends with .lnk)
Expand Down

0 comments on commit 1b2d2ca

Please sign in to comment.