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

Kdesktop 1275 sync on fat system are broken #338

Merged
merged 18 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e20f941
IoHelper::checkIfPathExists fix for FAT32/exFAT Disk.
herve-er Oct 7, 2024
6ee1144
IoHelper::getFileStat fix for FAT32/exFAT Disk.
herve-er Oct 7, 2024
6917d85
Revert "IoHelper::getFileStat fix for FAT32/exFAT Disk."
herve-er Oct 7, 2024
d2d8051
We should not rely on std::filesystem::is_symlink returning invalid a…
herve-er Oct 7, 2024
bff9e61
Consolidate IoHelper::checkIfPathExists fix for FAT32 disk.
herve-er Oct 7, 2024
06cc7ab
Merge branch 'develop' into KDESKTOP-1275-Sync-on-FAT-system-are-broken
ClementKunz Oct 8, 2024
5125d61
Ensure that we do not misinterpret an invalidArgument error as a fals…
herve-er Oct 8, 2024
11ba739
Merge branch 'KDESKTOP-1275-Sync-on-FAT-system-are-broken' of https:/…
herve-er Oct 8, 2024
a45ed8e
Apply suggestions from code review
herve-er Oct 8, 2024
ff0ce59
Uniformization of _WIN32 in #ifdef or #ifndef
herve-er Oct 8, 2024
e845dea
Merge branch 'KDESKTOP-1275-Sync-on-FAT-system-are-broken' of https:/…
herve-er Oct 8, 2024
d120287
Prefer ifdef instead of ifndef.
herve-er Oct 8, 2024
79d37fc
Merge branch 'develop' into KDESKTOP-1275-Sync-on-FAT-system-are-broken
herve-er Oct 8, 2024
ef2b45f
Merge branch 'develop' into KDESKTOP-1275-Sync-on-FAT-system-are-broken
herve-er Oct 8, 2024
5d1438f
Merge branch 'develop' into KDESKTOP-1275-Sync-on-FAT-system-are-broken
ClementKunz Oct 9, 2024
3915c59
Update src/libcommonserver/io/iohelper.cpp
herve-er Oct 9, 2024
b3028ae
Replace dirPath with targetPath in utility when a method can accept e…
herve-er Oct 9, 2024
9676a24
Merge branch 'develop' into KDESKTOP-1275-Sync-on-FAT-system-are-broken
herve-er Oct 9, 2024
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
4 changes: 2 additions & 2 deletions src/libcommon/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ enum class RequestNum {
PARAMETERS_UPDATE,
UTILITY_FINDGOODPATHFORNEWSYNC,
UTILITY_BESTVFSAVAILABLEMODE,
#ifdef WIN32
#ifdef _WIN32
UTILITY_SHOWSHORTCUT,
UTILITY_SETSHOWSHORTCUT,
#endif
Expand Down Expand Up @@ -239,7 +239,7 @@ inline std::string toString(RequestNum e) {
return "UTILITY_FINDGOODPATHFORNEWSYNC";
case RequestNum::UTILITY_BESTVFSAVAILABLEMODE:
return "UTILITY_BESTVFSAVAILABLEMODE";
#ifdef WIN32
#ifdef _WIN32
case RequestNum::UTILITY_SHOWSHORTCUT:
return "UTILITY_SHOWSHORTCUT";
case RequestNum::UTILITY_SETSHOWSHORTCUT:
Expand Down
19 changes: 19 additions & 0 deletions src/libcommonserver/io/iohelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "libcommonserver/io/filestat.h"
#include "libcommonserver/io/iohelper.h"
#include "libcommonserver/utility/utility.h" // Path2WStr
#include "libcommon/utility/utility.h"

#include "config.h" // APPLICATION

Expand Down Expand Up @@ -284,8 +285,12 @@ bool IoHelper::getItemType(const SyncPath &path, ItemType &itemType) noexcept {
const bool isSymlink = _isSymlink(path, ec);

itemType.ioError = stdError2ioError(ec);
#ifdef _WIN32
const bool fsSupportsSymlinks = Utility::isNtfs(path);
#else
const bool fsSupportsSymlinks =
itemType.ioError != IoError::InvalidArgument; // If true, we assume that the file system in use does support symlinks.
#endif

if (!isSymlink && itemType.ioError != IoError::Success && fsSupportsSymlinks) {
if (isExpectedError(itemType.ioError)) {
Expand Down Expand Up @@ -598,6 +603,20 @@ bool IoHelper::checkIfPathExists(const SyncPath &path, bool &exists, IoError &io
ioError = IoError::Success;
return true;
}
#ifdef _WIN32 // TODO: Remove this block when migrating the release process to Visual Studio 2022.
// Prior to Visual Studio 2022, std::filesystem::symlink_status would return a misleading InvalidArgument if the path is
// found but located on a FAT32 disk. If the file is not found, it works as expected. This behavior is fixed when compiling
// with VS2022, see https://developercommunity.visualstudio.com/t/std::filesystem::is_symlink-is-broken-on/1638272
if (ioError == IoError::InvalidArgument && !Utility::isNtfs(path)) {
ChristopheLarchier marked this conversation as resolved.
Show resolved Hide resolved
(void) std::filesystem::status(
path, ec); // Symlink are only supported on NTFS on Windows, there is no risk to follow a symlink.
ioError = stdError2ioError(ec);
if (ioError == IoError::NoSuchFileOrDirectory) {
ioError = IoError::Success;
return true;
}
}
#endif

exists = ioError != IoError::NoSuchFileOrDirectory;
return isExpectedError(ioError) || ioError == IoError::Success;
Expand Down
16 changes: 8 additions & 8 deletions src/libcommonserver/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ void Utility::logGenericServerError(const log4cplus::Logger &logger, const std::
#ifdef _WIN32
static std::unordered_map<std::string, bool> rootFsTypeMap;

bool Utility::isNtfs(const SyncPath &dirPath) {
auto it = rootFsTypeMap.find(dirPath.root_name().string());
bool Utility::isNtfs(const SyncPath &targetPath) {
auto it = rootFsTypeMap.find(targetPath.root_name().string());
if (it == rootFsTypeMap.end()) {
std::string fsType = Utility::fileSystemName(dirPath);
auto val = rootFsTypeMap.insert({dirPath.root_name().string(), fsType == NTFS});
std::string fsType = Utility::fileSystemName(targetPath);
auto val = rootFsTypeMap.insert({targetPath.root_name().string(), fsType == NTFS});
if (!val.second) {
// Failed to insert into map
return false;
Expand All @@ -311,25 +311,25 @@ bool Utility::isNtfs(const SyncPath &dirPath) {
}
#endif

std::string Utility::fileSystemName(const SyncPath &dirPath) {
std::string Utility::fileSystemName(const SyncPath &targetPath) {
#if defined(__APPLE__)
struct statfs stat;
if (statfs(dirPath.root_path().native().c_str(), &stat) == 0) {
if (statfs(targetPath.root_path().native().c_str(), &stat) == 0) {
return stat.f_fstypename;
}
#elif defined(_WIN32)
TCHAR szFileSystemName[MAX_PATH + 1];
DWORD dwMaxFileNameLength = 0;
DWORD dwFileSystemFlags = 0;

if (GetVolumeInformation(dirPath.root_path().c_str(), NULL, 0, NULL, &dwMaxFileNameLength, &dwFileSystemFlags,
if (GetVolumeInformation(targetPath.root_path().c_str(), NULL, 0, NULL, &dwMaxFileNameLength, &dwFileSystemFlags,
szFileSystemName, sizeof(szFileSystemName)) == TRUE) {
return Utility::ws2s(szFileSystemName);
} else {
// Not all the requested information is retrieved
DWORD dwError = GetLastError();
LOGW_WARN(logger(),
L"Error in GetVolumeInformation for " << Path2WStr(dirPath.root_name()).c_str() << L" (" << dwError << L")");
L"Error in GetVolumeInformation for " << Path2WStr(targetPath.root_name()).c_str() << L" (" << dwError << L")");

// !!! File system name can be OK or not !!!
return Utility::ws2s(szFileSystemName);
Expand Down
4 changes: 2 additions & 2 deletions src/libcommonserver/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ struct COMMONSERVER_EXPORT Utility {
std::istream &inputStream, const Poco::Net::HTTPResponse &httpResponse);

#ifdef _WIN32
static bool isNtfs(const SyncPath &dirPath);
static bool isNtfs(const SyncPath &targetPath);
#endif
static std::string fileSystemName(const SyncPath &dirPath);
static std::string fileSystemName(const SyncPath &targetPath);
static bool startsWith(const std::string &str, const std::string &prefix);
static bool startsWithInsensitive(const std::string &str, const std::string &prefix);
static bool endsWith(const std::string &str, const std::string &suffix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static const char forbiddenFilenameChars[] = {'/', '\0'};

namespace KDC {

#ifdef WIN32
#ifdef _WIN32
static const std::unordered_set<std::string> reservedWinNames = {
"CON", "PRN", "AUX", "NUL", "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5",
"COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"};
Expand All @@ -64,7 +64,7 @@ SyncName PlatformInconsistencyCheckerUtility::generateNewValidName(const SyncPat
SyncName suffix = generateSuffix(suffixType);
SyncName sub = name.stem().native().substr(0, MAX_NAME_LENGTH - suffix.size() - name.extension().native().size());

#ifdef WIN32
#ifdef _WIN32
SyncName nameStr(name.native());
// Can't finish with a space or a '.'
if (nameStr.back() == ' ' || nameStr.back() == '.') {
Expand Down Expand Up @@ -150,7 +150,7 @@ bool PlatformInconsistencyCheckerUtility::checkReservedNames(const SyncName &nam
return true;
}

#ifdef WIN32
#ifdef _WIN32
// Can't have only dots
if (std::ranges::count(name, '.') == name.size()) {
return true;
Expand Down
Loading