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

Remove chmod and duplicated permissions functions #3782

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Sploder12
Copy link
Contributor

@Sploder12 Sploder12 commented Nov 18, 2024

This PR removes chmod from Platform.h as well as functions that are similar in file_ops.h. They have all been changed to use MP_PLATFORM.set_permissions. This should not change behavior on Unix systems. On Windows this changes the behavior to modify ACLs as well as DOS permissions instead of just DOS permissions.

MULTI-1420

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.99%. Comparing base (cbcb5e7) to head (48de023).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/platform/platform_unix.cpp 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3782      +/-   ##
==========================================
- Coverage   89.02%   88.99%   -0.04%     
==========================================
  Files         255      255              
  Lines       14583    14579       -4     
==========================================
- Hits        12982    12974       -8     
- Misses       1601     1605       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Sploder12 Sploder12 marked this pull request as draft December 17, 2024 15:29
@Sploder12 Sploder12 force-pushed the fix-platform-specific-functions-in-abstraction branch from 6c58cd2 to a5015cd Compare December 17, 2024 20:13
@Sploder12 Sploder12 marked this pull request as ready for review December 17, 2024 20:39
@Sploder12 Sploder12 marked this pull request as draft December 20, 2024 22:00
@Sploder12 Sploder12 force-pushed the fix-platform-specific-functions-in-abstraction branch from 5b088d8 to d50d4e4 Compare January 6, 2025 22:11
@Sploder12 Sploder12 marked this pull request as ready for review January 8, 2025 21:02
Copy link
Contributor

@sharder996 sharder996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for cleaning this up and using the std::filesystem! Just a few things to clean up and it should be good.

return ::chmod(path, mode);
}
std::error_code ec{};
std::filesystem::permissions(path, permissions, ec);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe do something with the error code instead of throwing it away? Maybe log or change the signature to return the code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, std::error_code overloads the bool operator, so you shouldn't need the static cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the signature wouldn't work since Windows can fail for reasons that don't create or map to an error_code. But logging sounds like a good idea!

@@ -296,15 +296,15 @@ mp::Path mp::Utils::make_dir(const QDir& a_dir, const QString& name, QFileDevice
throw std::runtime_error(fmt::format("unable to create directory '{}'", dir_path));
}

if (permissions)
if (permissions != std::filesystem::perms::none)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permissions is an enum where std::filesystem::perms::none is 0, so this isn't strictly necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enum is not implicitly convertible to bool, I prefer this over an explicit cast to bool

EXPECT_CALL(*mock_file_ops, permissions(_)).WillOnce(Return(QFileDevice::ReadOwner | QFileDevice::WriteOwner));
EXPECT_CALL(*mock_file_ops, setPermissions(_, _)).WillOnce(Return(true));
EXPECT_CALL(*mock_file_ops, get_permissions(_))
.WillOnce(Return(std::filesystem::perms::owner_read | std::filesystem::perms::owner_write));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're not testing the permissions and its a mock, you should be able to just Return(), no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return() won't work since get_permissions doesn't return void, I chose owner read write since that's how the test was originally with QPermissions. But any std perms should be fine.

EXPECT_CALL(*mock_file_ops, permissions(_)).WillOnce(Return(QFileDevice::ReadOwner | QFileDevice::WriteOwner));
EXPECT_CALL(*mock_file_ops, setPermissions(_, _)).WillOnce(Return(false));
EXPECT_CALL(*mock_file_ops, get_permissions(_))
.WillOnce(Return(std::filesystem::perms::owner_read | std::filesystem::perms::owner_write));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@Sploder12 Sploder12 marked this pull request as draft January 16, 2025 15:43
@Sploder12 Sploder12 force-pushed the fix-platform-specific-functions-in-abstraction branch from 024baf7 to 48de023 Compare January 17, 2025 21:10
@Sploder12 Sploder12 marked this pull request as ready for review January 17, 2025 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants