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

feat: option to have File store preserve permissions when extracting #891

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

Conversation

sammy-da
Copy link

@sammy-da sammy-da commented Feb 14, 2025

This PR takes care of #886, or rather part of it.
It adds an option to the File store that's similar to tar's --preserve-permissions.

closes #886

@sammy-da sammy-da force-pushed the file-store-preserve-perms branch 3 times, most recently from 9f93f59 to f9f1baa Compare February 14, 2025 05:44
@sammy-da sammy-da marked this pull request as ready for review February 14, 2025 05:44
@sammy-da sammy-da force-pushed the file-store-preserve-perms branch 3 times, most recently from 454df67 to 830c0a9 Compare February 14, 2025 05:50
Signed-off-by: Sammy Abed <sammy.abed@digitalasset.com>
@sammy-da sammy-da force-pushed the file-store-preserve-perms branch from 830c0a9 to 0b55f28 Compare February 14, 2025 05:57
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.

Project coverage is 80.19%. Comparing base (58c3801) to head (f7118da).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
content/file/utils.go 70.00% 2 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (72.72%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #891      +/-   ##
==========================================
- Coverage   80.20%   80.19%   -0.02%     
==========================================
  Files          63       63              
  Lines        6043     6053      +10     
==========================================
+ Hits         4847     4854       +7     
- Misses        858      860       +2     
- Partials      338      339       +1     

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

@sammy-da sammy-da force-pushed the file-store-preserve-perms branch from 3a904ee to bafe923 Compare February 20, 2025 14:20
Signed-off-by: Sammy Abed <sammy.abed@digitalasset.com>
@sammy-da sammy-da force-pushed the file-store-preserve-perms branch from bafe923 to 5560c4d Compare February 20, 2025 14:24
@@ -23,6 +23,7 @@ var (
ErrPathTraversalDisallowed = errors.New("path traversal disallowed")
ErrOverwriteDisallowed = errors.New("overwrite disallowed")
ErrStoreClosed = errors.New("store already closed")
ErrPreservePermissions = errors.New("failed to restore permission during unpacking")
Copy link
Member

Choose a reason for hiding this comment

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

Since this error is file store specific, it should be put the file package.
BTW, should it be "restore permissions" in the error message?

Copy link
Author

@sammy-da sammy-da Feb 22, 2025

Choose a reason for hiding this comment

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

this is the file package. (?)

BTW, should it be "restore permissions" in the error message?

yep, typo

Copy link
Author

@sammy-da sammy-da Feb 22, 2025

Choose a reason for hiding this comment

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

btw, not sure how to increase the code coverage for this.
To do that, i think i would need to test the chmod error case. It isn't obvious to me how to trigger such failure, other than by concurrently trying to delete a file before it gets chmod'ed, i.e. trigger a race, but that would be flaky test

Copy link
Member

Choose a reason for hiding this comment

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

this is the file package. (?)

Oh sorry I was blind😂
Yeah it would be very tricky to test the chmod error case... I think we can bypass it. /cc @shizhMSFT

Signed-off-by: Sammy Abed <sammy.abed@digitalasset.com>
@sammy-da sammy-da force-pushed the file-store-preserve-perms branch 3 times, most recently from 28c3052 to 26443ab Compare February 22, 2025 09:30
Co-authored-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
Signed-off-by: sammy-da <sammy.abed@digitalasset.com>
Signed-off-by: Sammy Abed <sammy.abed@digitalasset.com>
@sammy-da sammy-da force-pushed the file-store-preserve-perms branch from 26443ab to 9bf6f31 Compare February 22, 2025 09:33
@sammy-da sammy-da requested a review from Wwwsylvia February 22, 2025 10:07
Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

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

LGTM. Just a nit.

@Wwwsylvia Wwwsylvia changed the title option to have File store preserve permsissions when extracting feat: option to have File store preserve permissions when extracting Feb 24, 2025
@Wwwsylvia
Copy link
Member

@sammy-da Could you also link the PR to the issue using GitHub keywords?

@sammy-da
Copy link
Author

Could you also link the PR to the issue using GitHub keywords?

It doesn't fully close it though. This will only take care of files that end up getting packed.
I guess i'll mark this as closing the issue anyway 🤷

@sammy-da sammy-da requested a review from Wwwsylvia February 24, 2025 10:41
@@ -476,3 +476,39 @@ func TestStore_Dir_OverwriteSymlink_RemovalFailed(t *testing.T) {
t.Fatal("error calling Chmod(), error =", err)
}
}

func Test_extractTarDirectory_PreservePermissions(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Forgot to mention, since this function is defined in utils.go, it's better to test it in utils_unix_test.go instead of file_unix_test.go.
A side note: we need to include the oras copyright header at the beginning of each file.

// Restore full mode bits
if preservePermissions && (header.Typeflag == tar.TypeReg || header.Typeflag == tar.TypeDir) {
if err := os.Chmod(filePath, os.FileMode(header.Mode)); err != nil {
return fmt.Errorf("%w: %w", ErrPreservePermissions, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think we need ErrPreservePermissions. It should be fine just returning err. BTW, double %w won't work.

@shizhMSFT
Copy link
Contributor

@sammy-da DCO checking is failing. Could you fix it?

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.

file permissions are not retained
4 participants