Fix #337: Enable use of TarArchive.RootPath for files under working directory #769
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change fixes #337 . I recently encountered this issue, and saw that #392 had been blocked for a while, and so I decided to take a crack at it.
This does not implement this feature using a feature flag as of writing, as suggested in the thread, but does preserve the existing behavior of adding files under the CurrentDirectory in most cases. When the RootPath is set, and is a child path of CurrentDirectory, the CurrentDirectory is removed from the RootPath, to match the behavior of TarEntry.
My main motivation for changing this behavior in TarArchive, instead of TarEntry, is so that the interface of TarEntry remains unchanged.
The existing behavior works like this: (
{workingDirectory}
is not a child of/absolute/path/
){workingDirectory}/temp
{workingDirectory}/temp/file.txt
temp/file.txt
{workingDirectory}/temp/file.txt
temp/file.txt
temp
{workingDirectory}/temp/file.txt
file.txt
/absolute/path/
/absolute/path/file.txt
file.txt
/absolute/path/file.txt
/absolute/path/file.txt
Instead, per #337 the behavior should be:
{workingDirectory}/temp
{workingDirectory}/temp/file.txt
file.txt
{workingDirectory}/temp/file.txt
temp/file.txt
temp
{workingDirectory}/temp/file.txt
file.txt
/absolute/path/
/absolute/path/file.txt
file.txt
/absolute/path/file.txt
/absolute/path/file.txt
An attempt was made to implement this change without additional string manipulation. This could be done with a modified IndexOf, that enables searching for a substring of the pattern within the target substring. This may improve performance.
I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the SharpZipLib open source product (the "Contribution"). My Contribution is licensed under the MIT License.