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

Kdesktop 774 implementation of set rights method. #68

Merged
merged 74 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
6f31ec7
Bug fix.
herve-er Apr 22, 2024
3ff0ce2
Add method definition.
herve-er Apr 22, 2024
09299f3
Add description to getRights method definition.
herve-er Apr 22, 2024
9846184
Add Linux implementation of setRights.
herve-er Apr 22, 2024
b65de93
Add implementation for macOS.
herve-er Apr 22, 2024
2aac874
Add Windows implementation.
herve-er Apr 22, 2024
d28cf25
Put MacOS and Linux implementation in the common ioHelper file to avo…
herve-er Apr 22, 2024
ea2c4cf
Reduce code duplication and cognitive complexity.
herve-er Apr 22, 2024
13799f2
Windows implementation.
herve-er Apr 23, 2024
40be3d4
Sentry compliant.
herve-er Apr 23, 2024
8e5111b
Sentry compliance.
herve-er Apr 23, 2024
63a7e9e
Sentry compliance.
herve-er Apr 23, 2024
556ef05
Sentry compliance.
herve-er Apr 23, 2024
abf61b6
Sentry compliance.
herve-er Apr 23, 2024
8d00f13
Apply review suggestion.
herve-er Apr 24, 2024
a161da5
Replace Path2WStr by Utility::formatSyncPath in log generation.
herve-er Apr 24, 2024
442f5be
Update log message in case of getItemType Fail.
herve-er Apr 24, 2024
2b8086f
Update log message in case of getItemType Fail.
herve-er Apr 24, 2024
9ecc25e
edit last commit.
herve-er Apr 24, 2024
48b7839
Unwanted Cmake files push [REVERT]
herve-er Apr 24, 2024
98f6661
Bug fix mac.
herve-er Apr 24, 2024
65a761e
Replace the redundant type with "auto". [SENTRY]
herve-er Apr 24, 2024
bc898cf
Remove useless old style array. [SENTRY]
herve-er Apr 24, 2024
080c6dd
Add comment.
herve-er Apr 24, 2024
e5c9ae4
Enhance readability by renamming function and reducing iohelper.h
herve-er Apr 24, 2024
0b90353
Correct some problems revealed by the test implementation.
herve-er Apr 24, 2024
d459a4e
Test implementation
herve-er Apr 24, 2024
796d1a3
Add verbose to test to help debug.
herve-er Apr 24, 2024
7207973
Force rigths to predefined state for linux and mac when testing.
herve-er Apr 24, 2024
306bb4e
Add verbose to help debug.
herve-er Apr 24, 2024
8687a1f
Fix mac and inux tests.
herve-er Apr 24, 2024
986c6fb
Fix mac and linux tests.
herve-er Apr 24, 2024
d100b71
Merge branch 'KDESKTOP-774-Implementation-of-setRights-method' of htt…
herve-er Apr 24, 2024
350c409
Add verbose to debug.
herve-er Apr 24, 2024
60be97d
Add verbose for debug.
herve-er Apr 24, 2024
a0bb606
Replace the 'W' function by auto select between ANSI or unicode funct…
herve-er Apr 24, 2024
1457664
Replace the way we fetch the user SID, the old version wasn't working…
herve-er Apr 24, 2024
283fd9d
Remove all the verbose.
herve-er Apr 24, 2024
d28ad57
Refactor this code to not nest more than 3 if|for|do|while|switch sta…
herve-er Apr 24, 2024
e520eda
Remove debug verbose.
herve-er Apr 25, 2024
93349d6
Remove old static member.
herve-er Apr 25, 2024
1f4e936
Update windows.yml
herve-er Apr 25, 2024
06fb0c4
Revert last commit.
herve-er Apr 25, 2024
1b8060c
Merge branch 'KDESKTOP-774-Implementation-of-setRights-method' of htt…
herve-er Apr 25, 2024
8ee8029
Remove artifact upload + remove static int _getAndSetRightsMe…
herve-er Apr 25, 2024
fa69288
Replace _setRightsStandard by _setRightsStd
herve-er Apr 25, 2024
9ea157f
Replace setRightsApiWindows by setRightsWindowsApi.
herve-er Apr 25, 2024
e7585ae
Remove empty lines and improve comments.
herve-er Apr 25, 2024
f12af12
use CPPUNIT_ASSERT_EQUAL instead of CPPUNIT_ASSERT(... == ...)
herve-er Apr 25, 2024
c435db8
Change rightsSet to Rightset and add a constructor with an int as input.
herve-er Apr 25, 2024
dd6b5a0
Remove useless .string
herve-er Apr 25, 2024
d35a39f
Apply suggestions from code review (LOG)
herve-er Apr 25, 2024
83c98ab
Apply suggestions from code review (LOG)
herve-er Apr 25, 2024
cd58e75
Merge branch 'KDESKTOP-774-Implementation-of-setRights-method' of htt…
herve-er Apr 25, 2024
6472cc9
Minor change for a safer implementation.
herve-er Apr 25, 2024
99cfbb6
idem.
herve-er Apr 25, 2024
a5c903d
Update some log messages.
herve-er Apr 25, 2024
2d3286e
Code optimization.
herve-er Apr 25, 2024
3debdbc
Re implement fallback method + Add sentry event in cas of fail with w…
herve-er Apr 25, 2024
0df63ad
Replace PSID _psid with an unique_ptr
herve-er Apr 25, 2024
de432db
Fix error with non existing path.
herve-er Apr 25, 2024
1503b4d
Add a check on each test for windos to ensure all the call the window…
herve-er Apr 25, 2024
4314bed
Revert unwanted push of CMAKE file.
herve-er Apr 25, 2024
f1535f9
Correct variable naming.
herve-er Apr 26, 2024
7958bc9
Remove exists and set back the _isExpected error in get/set rights.
herve-er Apr 29, 2024
26a456a
Implement with isExpected Error on mac and Linux.
herve-er Apr 29, 2024
6052e47
bug fix on mac.
herve-er Apr 29, 2024
8076d7f
Apply suggestions from code review
herve-er Apr 30, 2024
5b1ece6
Correct setRightsWindowsApi behaviour in case of error and free(pDesc…
herve-er Apr 30, 2024
a4fd7e3
Complete previous commit.
herve-er Apr 30, 2024
60c9716
Minor code refactor.
herve-er Apr 30, 2024
cc6ce47
Merge branch 'develop' into KDESKTOP-774-Implementation-of-setRights-…
herve-er Apr 30, 2024
27625cf
Update error message to show only DWORD when dealing with win API.
herve-er May 1, 2024
14d6bde
Merge branch 'develop' into KDESKTOP-774-Implementation-of-setRights-…
herve-er May 1, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ jobs:

- name: Run common tests
run: ./build-Release/install/bin/kDrive_test_common.exe

- name: Clean-up generated code
run : powershell ./infomaniak-build-tools/windows/build-drive.ps1 -clean all
32 changes: 32 additions & 0 deletions src/libcommonserver/io/iohelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,36 @@ bool IoHelper::createSymlink(const SyncPath &targetPath, const SyncPath &path, I

return ioError == IoErrorSuccess;
}

#ifndef _WIN32
//See iohelper_win.cpp for the Windows implementation
bool IoHelper::setRights(const SyncPath &path, bool read, bool write, bool exec, IoError &ioError) noexcept {
return _setRightsStd(path, read, write, exec, ioError);
}
#endif

bool IoHelper::_setRightsStd(const SyncPath &path, bool read, bool write, bool exec, IoError &ioError) noexcept {
ioError = IoErrorSuccess;
std::filesystem::perms perms = std::filesystem::perms::none;
if (read) {
perms |= std::filesystem::perms::owner_read;
}
if (write) {
perms |= std::filesystem::perms::owner_write;
}
if (exec) {
perms |= std::filesystem::perms::owner_exec;
}

std::error_code ec;
std::filesystem::permissions(path, perms, ec);
if (ec) {
ioError = posixError2ioError(ec.value());
return _isExpectedError(ioError);
}

return true;
}


} // namespace KDC
30 changes: 25 additions & 5 deletions src/libcommonserver/io/iohelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

#include "libcommon/utility/types.h"
#include "libcommonserver/log/log.h"
#ifdef _WIN32
#include <AccCtrl.h>
#endif

namespace KDC {

Expand All @@ -31,10 +34,6 @@ struct IoHelper {

inline static void setLogger(log4cplus::Logger logger) { _logger = logger; }

#ifdef _WIN32
static int _getRightsMethod;
#endif

static IoError stdError2ioError(int error) noexcept;
static IoError stdError2ioError(const std::error_code &ec) noexcept;
static IoError posixError2ioError(int error) noexcept;
Expand Down Expand Up @@ -255,9 +254,28 @@ struct IoHelper {
*/
static bool checkIfFileIsDehydrated(const SyncPath &path, bool &isDehydrated, IoError &ioError) noexcept;

// TODO: docstring and unit tests
//! Get the rights of the item indicated by `path`.
/*!
\param path is the file system path of the item.
\param read is a boolean indicating whether the item is readable.
\param write is a boolean indicating whether the item is writable.
\param exec is a boolean indicating whether the item is executable.
\param exists is a boolean indicating whether the item exists.
\return true if no unexpected error occurred, false otherwise.
*/
static bool getRights(const SyncPath &path, bool &read, bool &write, bool &exec, bool &exists) noexcept;

//! Set the rights of the item indicated by `path`.
/*!
\param path is the file system path of the item.
\param read is a boolean indicating whether the item should be readable.
\param write is a boolean indicating whether the item should be writable.
\param exec is a boolean indicating whether the item should be executable.
\param ioError holds the error returned when an underlying OS API call fails.
\return true if no unexpected error occurred, false otherwise.
*/
static bool setRights(const SyncPath &path, bool read, bool write, bool exec, IoError &ioError) noexcept;

protected:
// These functions default to the std::filesystem functions.
// They can be modified in tests.
Expand All @@ -283,6 +301,8 @@ struct IoHelper {
#endif
static bool _setTargetType(ItemType &itemType) noexcept;
static bool _checkIfIsHiddenFile(const SyncPath &path, bool &isHidden, IoError &ioError) noexcept;

static bool _setRightsStd(const SyncPath &path, bool read, bool write, bool exec, IoError &ioError) noexcept;
};

} // namespace KDC
1 change: 0 additions & 1 deletion src/libcommonserver/io/iohelper_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,4 @@ bool IoHelper::getRights(const SyncPath &path, bool &read, bool &write, bool &ex
return true;
}


} // namespace KDC
5 changes: 2 additions & 3 deletions src/libcommonserver/io/iohelper_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,14 @@ bool IoHelper::getRights(const SyncPath &path, bool &read, bool &write, bool &ex
ItemType itemType;
const bool success = getItemType(path, itemType);
if (!success) {
LOGW_WARN(logger(),
L"Failed to check if the item is a symlink: " << Utility::formatIoError(path, itemType.ioError).c_str());
LOGW_WARN(logger(), L"Failed to get item type - " << Utility::formatIoError(path, itemType.ioError).c_str());
ClementKunz marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
exists = itemType.ioError != IoErrorNoSuchFileOrDirectory;
if (!exists) {
return true;
}
const bool isSymlink = itemType.linkType = LinkTypeSymlink;
const bool isSymlink = itemType.linkType == LinkTypeSymlink;
ClementKunz marked this conversation as resolved.
Show resolved Hide resolved

std::error_code ec;
std::filesystem::perms perms =
Expand Down
Loading
Loading