Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly catch std::filesystem exceptions #7282

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions src/common/filesystembase.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/common/filesystembase.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/common/filesystembase.cpp

File src/common/filesystembase.cpp does not conform to Custom style guidelines. (lines 129, 130, 173, 174, 465, 466, 491, 492)
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -115,15 +115,21 @@
if (!fileExists(filename)) {
return;
}
const auto permissions = filePermissionsWin(filename);
try {
const auto permissions = filePermissionsWin(filename);

std::filesystem::perms allWritePermissions = std::filesystem::perms::_All_write;
static std::filesystem::perms defaultWritePermissions = std::filesystem::perms::others_write;
std::filesystem::perms allWritePermissions = std::filesystem::perms::_All_write;
static std::filesystem::perms defaultWritePermissions = std::filesystem::perms::others_write;

std::filesystem::permissions(filename.toStdString(), allWritePermissions, std::filesystem::perm_options::remove);
std::filesystem::permissions(filename.toStdString(), allWritePermissions, std::filesystem::perm_options::remove);

if (!readonly) {
std::filesystem::permissions(filename.toStdString(), defaultWritePermissions, std::filesystem::perm_options::add);
if (!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
Expand Down Expand Up @@ -155,14 +161,21 @@
{
#ifdef Q_OS_WIN
if (isLnkFile(filename)) {
const auto permissions = filePermissionsWin(filename);
try {
const auto permissions = filePermissionsWin(filename);

if (!readonly && static_cast<bool>((permissions & std::filesystem::perms::owner_write))) {
return false; // already writable enough
}
if (!readonly && static_cast<bool>((permissions & std::filesystem::perms::owner_write))) {
return false; // already writable enough
}

setFileReadOnly(filename, readonly);
return true;
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);
Expand Down Expand Up @@ -446,8 +459,15 @@
{
#ifdef Q_OS_WIN
if (isLnkFile(filename)) {
const auto permissions = filePermissionsWin(filename);
return static_cast<bool>((permissions & std::filesystem::perms::owner_write));
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();
Expand All @@ -465,8 +485,15 @@
{
#ifdef Q_OS_WIN
if (isLnkFile(filename)) {
const auto permissions = filePermissionsWin(filename);
return static_cast<bool>((permissions & std::filesystem::perms::owner_read));
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();
Expand Down
14 changes: 10 additions & 4 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/libsync/propagatedownload.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/libsync/propagatedownload.cpp

File src/libsync/propagatedownload.cpp does not conform to Custom style guidelines. (lines 1214, 1215)
* Copyright (C) by Olivier Goffart <ogoffart@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -12,7 +12,7 @@
* for more details.
*/

#include "config.h"

Check failure on line 15 in src/libsync/propagatedownload.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/propagatedownload.cpp:15:10 [clang-diagnostic-error]

'config.h' file not found
#include "owncloudpropagator_p.h"
#include "propagatedownload.h"
#include "networkjobs.h"
Expand Down Expand Up @@ -1205,10 +1205,16 @@
// Preserve the existing file permissions.
const auto existingFile = QFileInfo{filename};
#ifdef Q_OS_WIN
const auto existingPermissions = FileSystem::filePermissionsWin(filename);
const auto tmpFilePermissions = FileSystem::filePermissionsWin(_tmpFile.fileName());
if (existingPermissions != tmpFilePermissions) {
FileSystem::setFilePermissionsWin(_tmpFile.fileName(), existingPermissions);
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()) {
Expand Down
Loading