From f6ca336621ef08da783c3a133bece40ce411d16a Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Wed, 28 May 2025 23:27:08 +0300 Subject: [PATCH] Fix bug 73852 --- ChromiumBasedEditors/lib/src/fileconverter.h | 7 +++ ChromiumBasedEditors/lib/src/filelocker.cpp | 51 +++++++++++++++++--- ChromiumBasedEditors/lib/src/filelocker.h | 2 + 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/ChromiumBasedEditors/lib/src/fileconverter.h b/ChromiumBasedEditors/lib/src/fileconverter.h index 1a01a846..6d6888ea 100644 --- a/ChromiumBasedEditors/lib/src/fileconverter.h +++ b/ChromiumBasedEditors/lib/src/fileconverter.h @@ -611,8 +611,12 @@ public: } } + bool bIsCopied = false; if (sLocalFilePath != sDestinationPath) + { NSFile::CFileBinary::Copy(sLocalFilePath, sDestinationPath); + bIsCopied = true; + } bool bIsTestFile = true; if (!NSFile::CFileBinary::Exists(sDestinationPath)) @@ -636,6 +640,9 @@ public: return 0; } + if (bIsCopied && (m_oInfo.m_nCurrentFileFormat == AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF || m_oInfo.m_nCurrentFileFormat == AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDFA)) + NSSystem::CFileLocker::RemoveRestrictionFlags(sDestinationPath); + std::wstring sNameInfo = m_oInfo.m_sRecoveryDir + L"/asc_name.info"; if (NSFile::CFileBinary::Exists(sNameInfo)) NSFile::CFileBinary::Remove(sNameInfo); diff --git a/ChromiumBasedEditors/lib/src/filelocker.cpp b/ChromiumBasedEditors/lib/src/filelocker.cpp index 2938c464..c9594656 100644 --- a/ChromiumBasedEditors/lib/src/filelocker.cpp +++ b/ChromiumBasedEditors/lib/src/filelocker.cpp @@ -186,6 +186,7 @@ namespace NSSystem #include #include +#include namespace NSSystem { @@ -536,19 +537,19 @@ namespace NSSystem CFileLocker* CFileLocker::Create(const std::wstring& file) { - #ifdef _WIN32 + #ifdef _WIN32 return new NSSystem::CFileLockerWin(file); - #endif + #endif - #ifdef _LINUX - #ifndef _MAC + #ifdef _LINUX + #ifndef _MAC if (IsLocalFile(file)) return new NSSystem::CFileLockerFCNTL(file); else return new NSSystem::CFileLockerGIO(file); - #else + #else return new NSSystem::CFileLockerEmpty(file); - #endif + #endif #endif // ERROR!!! @@ -572,4 +573,42 @@ namespace NSSystem { return CHandlesMonitor::Instance().IsExist(file); } + + bool CFileLocker::RemoveRestrictionFlags(const std::wstring& file) + { +#ifdef _LINUX + std::wstring fileA = U_TO_UTF8(file); + struct stat fileStat; + if (stat(fileA.c_str, &fileStat) != 0) + { + return false; + } + + if (fileStat.st_mode & S_IWUSR) + return true; + + if (chmod(filename, fileStat.st_mode | S_IWUSR) != 0) + { + return false; + } + return true; +#else + DWORD attrs = GetFileAttributesW(file.c_str()); + if (attrs == INVALID_FILE_ATTRIBUTES) + { + return false; + } + + if (0 == (attrs & FILE_ATTRIBUTE_READONLY)) + return true; + + if (!SetFileAttributesW(file.c_str(), attrs &= ~FILE_ATTRIBUTE_READONLY)) + { + return false; + } + + return true; +#endif + + } } diff --git a/ChromiumBasedEditors/lib/src/filelocker.h b/ChromiumBasedEditors/lib/src/filelocker.h index 2eb87e29..83af91bf 100644 --- a/ChromiumBasedEditors/lib/src/filelocker.h +++ b/ChromiumBasedEditors/lib/src/filelocker.h @@ -68,6 +68,8 @@ namespace NSSystem static CFileLocker* Create(const std::wstring& file); static bool IsHandled(const std::wstring& file); + + static bool RemoveRestrictionFlags(const std::wstring& file); }; }