Skip to content

Commit 132aa68

Browse files
committed
PropagateDownloadFile/FileSystem: Improve previous commit (by mainly undoing it)
Instead of copying the permissions on the symlink, use the default permissions in that case. Otherwise, the newly downloaded files might become executable since symlinks often have with all permissions set. Signed-off-by: Tamino Bauknecht <dev@tb6.eu>
1 parent 5e4fe3a commit 132aa68

3 files changed

Lines changed: 5 additions & 39 deletions

File tree

src/libsync/filesystem.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include "filesystem.h"
1616

17-
#include <filesystem>
18-
1917
#include "common/utility.h"
2018
#include <QFile>
2119
#include <QFileInfo>
@@ -142,31 +140,6 @@ qint64 FileSystem::getSize(const QString &filename)
142140
return info.size();
143141
}
144142

145-
QFile::Permissions FileSystem::getPermissions(const QString &filename)
146-
{
147-
using qtStdFilePermissionsMapping = std::pair<QFile::Permission, std::filesystem::perms>;
148-
constexpr std::array<qtStdFilePermissionsMapping, 9> qtStdFilePermissionsMappings = {
149-
std::make_pair(QFileDevice::ReadOwner, std::filesystem::perms::owner_read),
150-
{QFileDevice::WriteOwner, std::filesystem::perms::owner_write},
151-
{QFileDevice::ExeOwner, std::filesystem::perms::owner_exec},
152-
{QFileDevice::ReadGroup, std::filesystem::perms::group_read},
153-
{QFileDevice::WriteGroup, std::filesystem::perms::group_write},
154-
{QFileDevice::ExeGroup, std::filesystem::perms::group_exec},
155-
{QFileDevice::ReadOther, std::filesystem::perms::others_read},
156-
{QFileDevice::WriteOther, std::filesystem::perms::others_write},
157-
{QFileDevice::ExeOther, std::filesystem::perms::others_exec}};
158-
159-
auto fileStatus = std::filesystem::symlink_status(filename.toStdString());
160-
auto permissions = fileStatus.permissions();
161-
162-
QFile::Permissions resultPermissions;
163-
for (auto [qtPermissionFlag, stdPermissionFlag] : qtStdFilePermissionsMappings) {
164-
auto isPermissionSet = (permissions & stdPermissionFlag) != std::filesystem::perms::none;
165-
resultPermissions.setFlag(qtPermissionFlag, isPermissionSet);
166-
}
167-
return resultPermissions;
168-
}
169-
170143
// Code inspired from Qt5's QDir::removeRecursively
171144
bool FileSystem::removeRecursively(const QString &path, const std::function<void(const QString &path, bool isDir)> &onDeleted, QStringList *errors)
172145
{

src/libsync/filesystem.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ namespace FileSystem {
6363
*/
6464
qint64 OWNCLOUDSYNC_EXPORT getSize(const QString &filename);
6565

66-
/**
67-
* @brief Get permissions for a file
68-
*
69-
* If the file is a symlink, the permissions for the symlink are returned.
70-
*/
71-
QFile::Permissions OWNCLOUDSYNC_EXPORT getPermissions(const QString &filename);
72-
7366
/**
7467
* @brief Retrieve a file inode with csync
7568
*/

src/libsync/propagatedownload.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,12 +1220,12 @@ void PropagateDownloadFile::downloadFinished()
12201220

12211221
auto previousFileExists = FileSystem::fileExists(filename) && _item->_instruction != CSYNC_INSTRUCTION_CASE_CLASH_CONFLICT;
12221222
if (previousFileExists) {
1223-
// Preserve the existing file permissions.
1224-
auto previousPermissions = FileSystem::getPermissions(filename);
1225-
if (previousPermissions != FileSystem::getPermissions(_tmpFile.fileName())) {
1226-
_tmpFile.setPermissions(previousPermissions);
1223+
// Preserve the existing file permissions (except it was a symlink)
1224+
const auto existingFile = QFileInfo{filename};
1225+
if (!existingFile.isSymLink() && existingFile.permissions() != _tmpFile.permissions()) {
1226+
_tmpFile.setPermissions(existingFile.permissions());
12271227
}
1228-
preserveGroupOwnership(_tmpFile.fileName(), QFileInfo(filename));
1228+
preserveGroupOwnership(_tmpFile.fileName(), existingFile);
12291229

12301230
// Make the file a hydrated placeholder if possible
12311231
const auto result = propagator()->syncOptions()._vfs->convertToPlaceholder(_tmpFile.fileName(), *_item, filename);

0 commit comments

Comments
 (0)