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

Follow symlinks when creating archive #183

Merged
merged 26 commits into from
Jun 7, 2023
Merged

Conversation

bendbennett
Copy link
Contributor

Closes: #6

@moajo as the archive provider has now been migrated from SDKv2 to the Terraform Plugin Framework, I have incorporated your changes from #73 into this PR and added you as a coauthor on the commit as the vast majority of the changes were in your original PR. The only significant change I have made was in the handling of symbolic links that are using an absolute path. If you would rather rebase your original PR on the latest main then please go ahead and I will close out this PR. Thank you very much for your contribution.

@bendbennett bendbennett added this to the v2.4.0 milestone Jan 26, 2023
@bendbennett bendbennett requested a review from a team as a code owner January 26, 2023 13:06
@bendbennett bendbennett mentioned this pull request Jan 26, 2023
Copy link

@otisskipper-carbondirect otisskipper-carbondirect left a comment

Choose a reason for hiding this comment

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

Approving but mainly to get eyes back on this (since I'm not an approving reviewer).
@bendbennett looks like it timed out on the Tests / Acc. Tests (OS: windows-latest / TF: 0.14.*) (pull_request) test after 15 mins.

@@ -137,11 +144,29 @@ func (a *ZipArchiver) ArchiveDir(indirname string, excludes []string) error {
return err
}

if info.Mode()&os.ModeSymlink == os.ModeSymlink {
realPath, err := readSymlinkRecursive(path, maxRecursion)
Copy link
Member

Choose a reason for hiding this comment

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

I commented above about the maxRecursion variable and decided to do a little more digging and found that the standard library has a function filepath.EvalSymlinks that, after a quick glance, looks very similar to this readSymlinkRecursive function (with some additional OS specific edge-cases to boot).

We may want to consider using this standard library function if it is providing the same functionality.

Fun fact, the magic number in the standard library is 255 symlinks! 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sweet! Nice find, thanks. I've refactored to switch to using filepath.EvalSymlinks. Looks like the functionality meets our requirements and it handles symlinks to absolute paths correctly out of the box. 👍

Copy link
Member

Choose a reason for hiding this comment

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

We have some unit tests below for symlinks, but do we also want to add a scenario to the data source and resource tests here for symlinks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! Have added a couple of tests for the archive_file resource and data source. These are currently leveraging helper functions (i.e., ensureContents() and ensureFileMode()) that were created for use with unit tests. Using these helper functions within acceptance tests looks a little strange as we're passing t *testing.T into the function. Happy to refactor the helper functions to just return an error and then update the unit tests and acceptance tests accordingly. Let me know your thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have any strong feelings for refactoring vs. not, I think what you have looks good 👍🏻

@github-actions github-actions bot added size/XL and removed size/L labels Jun 2, 2023
Copy link
Member

@bflad bflad left a comment

Choose a reason for hiding this comment

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

One potential consideration for the testing, otherwise looks good to me. 🚀

var fileSize string
r.ParallelTest(t, r.TestCase{
ProtoV5ProviderFactories: protoV5ProviderFactories(),
Steps: []r.TestStep{
Copy link
Member

Choose a reason for hiding this comment

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

Would this testing be a little easier to read/grok/parallelize if each test step was treated as its own unit test? This would help ensure there is a separate t.TempDir() for each archive and there could be code comments explaining what should (or shouldn't) be expected for each test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a good idea. Have separated each of the test steps into an individual test and added comments to clarify the expectations.

@bendbennett bendbennett merged commit c03e0a6 into main Jun 7, 2023
30 checks passed
@bendbennett bendbennett deleted the bendbennett/issues-6 branch June 7, 2023 13:09
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot archive directories with symbolic links (symlinks)
4 participants