mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-07 22:02:12 +08:00
fileutils: improve Windows hard link file handling
Fix file access issues when reading hard links on Windows by: - Adding explicit share mode (_SH_DENYNO) to allow reading files opened elsewhere - Using binary mode to ensure consistent behavior with hard links This resolves issues with reading hard linked files on Windows while maintaining behavior on other platforms. https://git.jami.net/savoirfairelinux/jami-client-qt/-/issues/1899 Change-Id: I2adc0f29db46d5bf5b69762018e7a5e677ec3d04
This commit is contained in:
@ -275,9 +275,18 @@ std::string
|
|||||||
loadTextFile(const std::filesystem::path& path, const std::filesystem::path& default_dir)
|
loadTextFile(const std::filesystem::path& path, const std::filesystem::path& default_dir)
|
||||||
{
|
{
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
std::ifstream file(getFullPath(default_dir, path));
|
auto fullPath = getFullPath(default_dir, path);
|
||||||
|
|
||||||
|
// Open with explicit share mode to allow reading even if file is opened elsewhere
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::ifstream file(fullPath, std::ios::in | std::ios::binary, _SH_DENYNO);
|
||||||
|
#else
|
||||||
|
std::ifstream file(fullPath);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
throw std::runtime_error("Unable to read file: " + path.string());
|
throw std::runtime_error("Unable to read file: " + path.string());
|
||||||
|
|
||||||
file.seekg(0, std::ios::end);
|
file.seekg(0, std::ios::end);
|
||||||
auto size = file.tellg();
|
auto size = file.tellg();
|
||||||
if (size > std::numeric_limits<unsigned>::max())
|
if (size > std::numeric_limits<unsigned>::max())
|
||||||
|
Reference in New Issue
Block a user