From: Hannah von Reth Date: Fri, 12 Feb 2021 12:06:13 +0000 (+0100) Subject: Fix Windows long path issue introduced in dd641fae997d71c8396b77def2fa25ad96fdf47f X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~18^2~278^2~23 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=789e0e45d5887e116b08cc1848b767f36a9fe228;p=nextcloud-desktop.git Fix Windows long path issue introduced in dd641fae997d71c8396b77def2fa25ad96fdf47f --- diff --git a/src/csync/vio/csync_vio_local_win.cpp b/src/csync/vio/csync_vio_local_win.cpp index 7aa07f4da..4ddd4f545 100644 --- a/src/csync/vio/csync_vio_local_win.cpp +++ b/src/csync/vio/csync_vio_local_win.cpp @@ -34,6 +34,7 @@ #include "csync.h" #include "vio/csync_vio_local.h" #include "common/filesystembase.h" +#include "common/utility.h" #include @@ -52,8 +53,6 @@ struct csync_vio_handle_t { QString path; // Always ends with '\' }; -static int _csync_vio_local_stat_mb(const QString &path, csync_file_stat_t *buf); - csync_vio_handle_t *csync_vio_local_opendir(const QString &name) { QScopedPointer handle(new csync_vio_handle_t{}); @@ -175,12 +174,9 @@ std::unique_ptr csync_vio_local_readdir(csync_vio_handle_t *h file_stat->size = (handle->ffd.nFileSizeHigh * ((int64_t)(MAXDWORD)+1)) + handle->ffd.nFileSizeLow; file_stat->modtime = FileTimeToUnixTime(&handle->ffd.ftLastWriteTime, &rem); - QString fullPath; - fullPath.reserve(handle->path.size() + std::wcslen(handle->ffd.cFileName)); - fullPath += handle->path; // path always ends with '\', by construction - fullPath += QString::fromWCharArray(handle->ffd.cFileName); + // path always ends with '\', by construction - if (_csync_vio_local_stat_mb(fullPath, file_stat.get()) < 0) { + if (csync_vio_local_stat(handle->path + QString::fromWCharArray(handle->ffd.cFileName), file_stat.get()) < 0) { // Will get excluded by _csync_detect_update. file_stat->type = ItemTypeSkip; } @@ -188,14 +184,7 @@ std::unique_ptr csync_vio_local_readdir(csync_vio_handle_t *h return file_stat; } - int csync_vio_local_stat(const QString &uri, csync_file_stat_t *buf) -{ - int rc = _csync_vio_local_stat_mb(uri, buf); - return rc; -} - -static int _csync_vio_local_stat_mb(const QString &path, csync_file_stat_t *buf) { /* Almost nothing to do since csync_vio_local_readdir already filled up most of the information But we still need to fetch the file ID. @@ -206,21 +195,19 @@ static int _csync_vio_local_stat_mb(const QString &path, csync_file_stat_t *buf) BY_HANDLE_FILE_INFORMATION fileInfo; ULARGE_INTEGER FileIndex; - const auto longPath = OCC::FileSystem::longWinPath(path); - - h = CreateFileW(longPath.toStdWString().data(), 0, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, - nullptr, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, - nullptr ); + h = CreateFileW(reinterpret_cast(OCC::FileSystem::longWinPath(uri).utf16()), 0, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, + NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, + NULL); if( h == INVALID_HANDLE_VALUE ) { - qCCritical(lcCSyncVIOLocal) << "CreateFileW failed on" << longPath; errno = GetLastError(); + qCCritical(lcCSyncVIOLocal) << "CreateFileW failed on" << uri << OCC::Utility::formatWinError(errno); return -1; } if(!GetFileInformationByHandle( h, &fileInfo ) ) { - qCCritical(lcCSyncVIOLocal) << "GetFileInformationByHandle failed on" << longPath; errno = GetLastError(); + qCCritical(lcCSyncVIOLocal) << "GetFileInformationByHandle failed on" << uri << OCC::Utility::formatWinError(errno); CloseHandle(h); return -1; } diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index af84f4d2f..7c4f5b626 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -115,7 +115,7 @@ static qint64 getSizeWithCsync(const QString &filename) if (csync_vio_local_stat(filename, &stat) != -1) { result = stat.size; } else { - qCWarning(lcFileSystem) << "Could not get size for" << filename << "with csync"; + qCWarning(lcFileSystem) << "Could not get size for" << filename << "with csync" << Utility::formatWinError(errno); } return result; }