Skip to content

Commit

Permalink
Solve conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
herve-er committed Dec 20, 2024
2 parents c12d432 + 0cb30a0 commit b54fd59
Show file tree
Hide file tree
Showing 68 changed files with 1,154 additions and 632,993 deletions.
6 changes: 3 additions & 3 deletions src/gui/adddrivelocalfolderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ void AddDriveLocalFolderWidget::updateUI() {
_folderCompatibleWithLiteSync = (virtualFileMode == VirtualFileMode::Win && fsName == "NTFS") ||
(virtualFileMode == VirtualFileMode::Mac && fsName == "apfs");
if (!_folderCompatibleWithLiteSync) {
_warningLabel->setText(tr(R"(This folder is not compatible with Lite Sync.<br>"
"Please select another folder or if you continue Lite Sync will be disabled.<br>"
"<a style="%1" href="%2">Learn more</a>)")
_warningLabel->setText(tr(R"(This folder is not compatible with Lite Sync.<br>
Please select another folder. If you continue Lite Sync will be disabled.<br>
<a style="%1" href="%2">Learn more</a>)")
.arg(CommonUtility::linkStyle, KDC::GuiUtility::learnMoreLink));
_warningWidget->setVisible(true);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/gui/localfolderdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ void LocalFolderDialog::updateUI() {
_folderCompatibleWithLiteSync = ((virtualFileMode == VirtualFileMode::Win && fsName == "NTFS") ||
(virtualFileMode == VirtualFileMode::Mac && fsName == "apfs"));
if (!_folderCompatibleWithLiteSync) {
_warningLabel->setText(tr(R"(This folder is not compatible with Lite Sync.<br>"
"Please select another folder or if you continue Lite Sync will be disabled.<br>"
"<a style="%1" href="%2">Learn more</a>)")
_warningLabel->setText(tr(R"(This folder is not compatible with Lite Sync.<br>
Please select another folder. If you continue Lite Sync will be disabled.<br>
<a style="%1" href="%2">Learn more</a>)")
.arg(CommonUtility::linkStyle, KDC::GuiUtility::learnMoreLink));
_warningWidget->setVisible(true);
} else {
Expand Down
28 changes: 14 additions & 14 deletions src/gui/parametersdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,45 +670,45 @@ QString ParametersDialog::getInconsistencyText(InconsistencyType inconsistencyTy
QString text;
if (bitWiseEnumToBool(inconsistencyType & InconsistencyType::Case)) {
text +=
tr("An existing file/directory has an identical name with the same case options (same upper and lower case "
tr("An existing item has an identical name with the same case options (same upper and lower case "
"letters).<br>"
"The file/directory has been temporarily blacklisted.");
"It has been temporarily blacklisted.");
}
if (bitWiseEnumToBool(inconsistencyType & InconsistencyType::ForbiddenChar)) {
text += (text.isEmpty() ? "" : "\n");
text +=
tr("The file/directory name contains an unsupported character.<br>"
"The file/directory has been temporarily blacklisted.");
tr("The item name contains an unsupported character.<br>"
"It has been temporarily blacklisted.");
}
if (bitWiseEnumToBool(inconsistencyType & InconsistencyType::ReservedName)) {
text += (text.isEmpty() ? "" : "\n");
text +=
tr("This file/directory name is reserved by your operating system.<br>"
"The file/directory has been temporarily blacklisted.");
tr("This item name is reserved by your operating system.<br>"
"It has been temporarily blacklisted.");
}
if (bitWiseEnumToBool(inconsistencyType & InconsistencyType::NameLength)) {
text += (text.isEmpty() ? "" : "\n");
text +=
tr("The file/directory name is too long.<br>"
"The file/directory has been temporarily blacklisted.");
tr("The item name is too long.<br>"
"It has been temporarily blacklisted.");
}
if (bitWiseEnumToBool(inconsistencyType & InconsistencyType::PathLength)) {
text += (text.isEmpty() ? "" : "\n");
text +=
tr("The file/directory path is too long.<br>"
"The file/directory is ignored.");
tr("The item path is too long.<br>"
"It has been ignored.");
}
if (bitWiseEnumToBool(inconsistencyType & InconsistencyType::NotYetSupportedChar)) {
text += (text.isEmpty() ? "" : "\n");
text +=
tr("The file/directory name contains a recent UNICODE character not yet supported by your filesystem.<br>"
"The parent directory has been excluded from synchronization.");
tr("The item name contains a recent UNICODE character not yet supported by your filesystem.<br>"
"It has been excluded from synchronization.");
}
if (bitWiseEnumToBool(inconsistencyType & InconsistencyType::DuplicateNames)) {
text += (text.isEmpty() ? "" : "\n");
text +=
tr("The file/directory name coincides with the name of another item in the same directory.<br>"
"This item is temporarily blacklisted. Consider removing duplicate items.");
tr("The item name coincides with the name of another item in the same directory.<br>"
"It has been temporarily blacklisted. Consider removing duplicate items.");
}

return text;
Expand Down
7 changes: 7 additions & 0 deletions src/libcommon/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,13 @@ void CommonUtility::clearSignalFile(const AppType appType, const SignalCategory
}
}

#ifdef _WIN32
std::string CommonUtility::toUnsafeStr(const SyncName &name) {
std::string unsafeName(name.begin(), name.end());
return unsafeName;
}
#endif

#ifdef __APPLE__
bool CommonUtility::isLiteSyncExtEnabled() {
QProcess *process = new QProcess();
Expand Down
4 changes: 4 additions & 0 deletions src/libcommon/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ struct COMMON_EXPORT CommonUtility {
return utility_base::isLikeFileNotFoundError(ec);
};


#ifdef _WIN32
// Converts a std::wstring to std::string assuming that it contains only mono byte chars
static std::string toUnsafeStr(const SyncName &name);

static std::wstring getErrorMessage(DWORD errorMessageId) { return utility_base::getErrorMessage(errorMessageId); }
static std::wstring getLastErrorMessage() { return utility_base::getLastErrorMessage(); };
static bool isLikeFileNotFoundError(DWORD dwError) noexcept { return utility_base::isLikeFileNotFoundError(dwError); };
Expand Down
19 changes: 12 additions & 7 deletions src/libcommongui/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ static void kdriveLogCatcher(QtMsgType type, const QMessageLogContext &ctx, cons
if (qtMsgTypeLevel[type] < logger->minLogLevel()) return;

// Create new context
const char *fileName = ctx.file;
if (fileName) {
const char *lastDirSep = strrchr(fileName, '/');
if (lastDirSep) {
fileName = lastDirSep + 1;
}
SyncName fileName;
if (ctx.file) {
const SyncPath filePath(ctx.file);
fileName = filePath.filename();
}
QMessageLogContext ctxNew(fileName, ctx.line, ctx.function, ctx.category);
#ifdef _WIN32
// For performance purposes, assume that the file name contains only mono byte chars
std::string unsafeFileName(CommonUtility::toUnsafeStr(fileName));
const char *fileNamePtr = unsafeFileName.c_str();
#else
const char *fileNamePtr = fileName.c_str();
#endif
QMessageLogContext ctxNew(fileNamePtr, ctx.line, ctx.function, ctx.category);

if (!logger->isNoop()) {
logger->doLog(qFormatLogMessage(type, ctxNew, message));
Expand Down
3 changes: 1 addition & 2 deletions src/libcommonserver/db/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ bool Db::exists() {
bool exists = false;
IoError ioError = IoError::Success;
if (!IoHelper::checkIfPathExists(_dbPath, exists, ioError)) {
LOGW_WARN(_logger,
L"Error in IoHelper::checkIfPathExists for path=" << Utility::formatIoError(_dbPath, ioError).c_str());
LOGW_WARN(_logger, L"Error in IoHelper::checkIfPathExists: " << Utility::formatIoError(_dbPath, ioError));
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcommonserver/db/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class COMMONSERVER_EXPORT Db {
int extendedErrorCode() const;

bool init(const std::string &version);
virtual std::string dbType() const { return "Unknown"; };
virtual std::string dbType() const { return "Unknown"; }

virtual bool create(bool &retry) = 0;
virtual bool prepare() = 0;
Expand Down
33 changes: 19 additions & 14 deletions src/libcommonserver/io/iohelper_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/filesystembase.h"

#include "libcommonserver/io/filestat.h"
#include "libcommonserver/io/iohelper.h"
#include "libcommonserver/io/iohelper_win.h"
Expand Down Expand Up @@ -119,6 +117,14 @@ time_t FileTimeToUnixTime(LARGE_INTEGER filetime, DWORD *remainder) {
return FileTimeToUnixTime(&ft, remainder);
}

uint64_t computeNodeId(const _FILE_ID_FULL_DIR_INFORMATION *pFileInfo) {
// We keep `long long` type cast for legacy reason.
auto longLongId =
(static_cast<long long>(pFileInfo->FileId.HighPart) << 32) + static_cast<long long>(pFileInfo->FileId.LowPart);

return static_cast<uint64_t>(longLongId);
}

} // namespace

int IoHelper::_getAndSetRightsMethod = -1; // -1: not initialized, 0: Windows API, 1: std::filesystem
Expand All @@ -133,12 +139,12 @@ IoError IoHelper::stdError2ioError(int error) noexcept {

bool IoHelper::getNodeId(const SyncPath &path, NodeId &nodeId) noexcept {
// Get parent folder handle
HANDLE hParent;
hParent = CreateFileW(path.parent_path().wstring().c_str(), FILE_LIST_DIRECTORY, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, NULL);
HANDLE hParent = CreateFileW(path.parent_path().wstring().c_str(), FILE_LIST_DIRECTORY, FILE_SHARE_READ, nullptr,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);

if (hParent == INVALID_HANDLE_VALUE) {
LOGW_INFO(logger(), L"Error in CreateFileW: " << Utility::formatSyncPath(path.parent_path()).c_str());
LOGW_INFO(logger(), L"Error in CreateFileW: " << Utility::formatSyncPath(path.parent_path()) << L", "
<< CommonUtility::getLastErrorMessage());
return false;
}

Expand All @@ -161,7 +167,8 @@ bool IoHelper::getNodeId(const SyncPath &path, NodeId &nodeId) noexcept {
(PZW_QUERY_DIRECTORY_FILE) GetProcAddress(GetModuleHandle(L"ntdll.dll"), "ZwQueryDirectoryFile");

if (zwQueryDirectoryFile == 0) {
LOGW_WARN(logger(), L"Error in GetProcAddress: " << Utility::formatSyncPath(path.parent_path()).c_str());
LOGW_WARN(logger(), L"Error in GetProcAddress: " << Utility::formatSyncPath(path.parent_path()) << L", "
<< CommonUtility::getLastErrorMessage());
return false;
}

Expand All @@ -174,7 +181,7 @@ bool IoHelper::getNodeId(const SyncPath &path, NodeId &nodeId) noexcept {
}

// Get the Windows file id as an inode replacement.
nodeId = std::to_string(((long long) pFileInfo->FileId.HighPart << 32) + (long long) pFileInfo->FileId.LowPart);
nodeId = std::to_string(computeNodeId(pFileInfo));

CloseHandle(hParent);
return true;
Expand Down Expand Up @@ -260,7 +267,7 @@ bool IoHelper::getFileStat(const SyncPath &path, FileStat *filestat, IoError &io
}

// Get the Windows file id as an inode replacement.
filestat->inode = ((long long) pFileInfo->FileId.HighPart << 32) + (long long) pFileInfo->FileId.LowPart;
filestat->inode = computeNodeId(pFileInfo);
filestat->size = ((long long) pFileInfo->EndOfFile.HighPart << 32) + (long long) pFileInfo->EndOfFile.LowPart;

DWORD rem;
Expand Down Expand Up @@ -304,10 +311,8 @@ bool IoHelper::_checkIfIsHiddenFile(const SyncPath &filepath, bool &isHidden, Io

void IoHelper::setFileHidden(const SyncPath &path, bool hidden) noexcept {
// TODO: move KDC::FileSystem::longWinPath to IoHelper and use it here.
DWORD dwAttrs;

const wchar_t *fName = path.c_str();
dwAttrs = GetFileAttributesW(fName);
DWORD dwAttrs = GetFileAttributesW(fName);

if (dwAttrs != INVALID_FILE_ATTRIBUTES) {
if (hidden && !(dwAttrs & FILE_ATTRIBUTE_HIDDEN)) {
Expand Down Expand Up @@ -631,7 +636,7 @@ bool IoHelper::getRights(const SyncPath &path, bool &read, bool &write, bool &ex
}
LOGW_WARN(logger(), L"Failed to get rights using Windows API, falling back to std::filesystem.");
sentry::Handler::captureMessage(sentry::Level::Warning, "IoHelper",
"Failed to get rights using Windows API, falling back to std::filesystem.");
"Failed to get rights using Windows API, falling back to std::filesystem.");

IoHelper::getTrustee().ptstrName = nullptr;
_getAndSetRightsMethod = 1;
Expand Down Expand Up @@ -707,7 +712,7 @@ bool IoHelper::setRights(const SyncPath &path, bool read, bool write, bool exec,

LOGW_WARN(logger(), L"Failed to set rights using Windows API, falling back to std::filesystem.");
sentry::Handler::captureMessage(sentry::Level::Warning, "IoHelper",
"Failed to set rights using Windows API, falling back to std::filesystem.");
"Failed to set rights using Windows API, falling back to std::filesystem.");
IoHelper::getTrustee().ptstrName = nullptr;
_getAndSetRightsMethod = 1;
}
Expand Down
Loading

0 comments on commit b54fd59

Please sign in to comment.