mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 13:05:51 +03:00
Merge pull request #7283 from nextcloud/backport/7282/stable-3.14
[stable-3.14] properly catch std::filesystem exceptions
This commit is contained in:
commit
86d7d2f44c
2 changed files with 53 additions and 20 deletions
|
@ -115,6 +115,7 @@ void FileSystem::setFileReadOnly(const QString &filename, bool readonly)
|
|||
if (!fileExists(filename)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const auto permissions = filePermissionsWin(filename);
|
||||
|
||||
std::filesystem::perms allWritePermissions = std::filesystem::perms::_All_write;
|
||||
|
@ -126,6 +127,11 @@ void FileSystem::setFileReadOnly(const QString &filename, bool readonly)
|
|||
std::filesystem::permissions(filename.toStdString(), defaultWritePermissions, std::filesystem::perm_options::add);
|
||||
}
|
||||
}
|
||||
catch (std::filesystem::filesystem_error e)
|
||||
{
|
||||
qCWarning(lcFileSystem()) << filename << (readonly ? "readonly" : "read write") << e.what();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
QFile file(filename);
|
||||
QFile::Permissions permissions = file.permissions();
|
||||
|
@ -155,6 +161,7 @@ bool FileSystem::setFileReadOnlyWeak(const QString &filename, bool readonly)
|
|||
{
|
||||
#ifdef Q_OS_WIN
|
||||
if (isLnkFile(filename)) {
|
||||
try {
|
||||
const auto permissions = filePermissionsWin(filename);
|
||||
|
||||
if (!readonly && static_cast<bool>((permissions & std::filesystem::perms::owner_write))) {
|
||||
|
@ -164,6 +171,12 @@ bool FileSystem::setFileReadOnlyWeak(const QString &filename, bool readonly)
|
|||
setFileReadOnly(filename, readonly);
|
||||
return true;
|
||||
}
|
||||
catch (std::filesystem::filesystem_error e)
|
||||
{
|
||||
qCWarning(lcFileSystem()) << filename << (readonly ? "readonly" : "read write") << e.what();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
QFile file(filename);
|
||||
QFile::Permissions permissions = file.permissions();
|
||||
|
@ -446,9 +459,16 @@ bool FileSystem::isWritable(const QString &filename, const QFileInfo &fileInfo)
|
|||
{
|
||||
#ifdef Q_OS_WIN
|
||||
if (isLnkFile(filename)) {
|
||||
try {
|
||||
const auto permissions = filePermissionsWin(filename);
|
||||
return static_cast<bool>((permissions & std::filesystem::perms::owner_write));
|
||||
}
|
||||
catch (std::filesystem::filesystem_error e)
|
||||
{
|
||||
qCWarning(lcFileSystem()) << filename << e.what();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
bool re = fileInfo.isWritable();
|
||||
// if the filename is different from the filename in fileInfo, the fileInfo is
|
||||
|
@ -465,9 +485,16 @@ bool FileSystem::isReadable(const QString &filename, const QFileInfo &fileInfo)
|
|||
{
|
||||
#ifdef Q_OS_WIN
|
||||
if (isLnkFile(filename)) {
|
||||
try {
|
||||
const auto permissions = filePermissionsWin(filename);
|
||||
return static_cast<bool>((permissions & std::filesystem::perms::owner_read));
|
||||
}
|
||||
catch (std::filesystem::filesystem_error e)
|
||||
{
|
||||
qCWarning(lcFileSystem()) << filename << e.what();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
bool re = fileInfo.isReadable();
|
||||
// if the filename is different from the filename in fileInfo, the fileInfo is
|
||||
|
|
|
@ -1205,11 +1205,17 @@ void PropagateDownloadFile::downloadFinished()
|
|||
// Preserve the existing file permissions.
|
||||
const auto existingFile = QFileInfo{filename};
|
||||
#ifdef Q_OS_WIN
|
||||
try {
|
||||
const auto existingPermissions = FileSystem::filePermissionsWin(filename);
|
||||
const auto tmpFilePermissions = FileSystem::filePermissionsWin(_tmpFile.fileName());
|
||||
if (existingPermissions != tmpFilePermissions) {
|
||||
FileSystem::setFilePermissionsWin(_tmpFile.fileName(), existingPermissions);
|
||||
}
|
||||
}
|
||||
catch (std::filesystem::filesystem_error e)
|
||||
{
|
||||
qCWarning(lcPropagateDownload()) << _item->_instruction << _item->_file << e.what();
|
||||
}
|
||||
#else
|
||||
if (existingFile.permissions() != _tmpFile.permissions()) {
|
||||
_tmpFile.setPermissions(existingFile.permissions());
|
||||
|
|
Loading…
Reference in a new issue