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

Fix inconsistent trees from getindex and merge. #40

Merged
merged 2 commits into from
Feb 12, 2021
Merged

Fix inconsistent trees from getindex and merge. #40

merged 2 commits into from
Feb 12, 2021

Conversation

DrChainsaw
Copy link
Collaborator

Fixes #39

Testing revealed that the root issue is that getindex for both globs and regexps returns a tree where the children of the root does not have the root as parent. Same thing also happens after merge.

Not sure if this is intentional, but it seems to me that a tree like this is inconsistent and should be considered invalid. Another option could be to add a call to setparent in the convenience “copy” constructor for FileTree if one wants to be really strict about not allowing such trees.

It turned out that mv and cp (or in fact regex_rewrite_tree and attach) relied on this behavior to leave the root out of all processing. I first tried to change attach to not add the root node (i.e last line changed to merge(t, t1; combine=combine) and assume that path argument included the path to the root.

This did however cause problems when root node is a subdirectory as it would change the tree to use the root of the root node as, uhm, root (i.e if root node has path a/b then the returned tree would have a as root and b as its child). This also had the adverse consequence that the public API for mv and cp would break as regexes where now matched against the whole path including the root node. Both these problems where caught by the mv tests in taxi.jl.

Instead I resorted to just truncating the canonical path from behind in regex_rewrite_tree. Not sure if this is the most elegant way to do it.

@codecov-io
Copy link

codecov-io commented Jan 21, 2021

Codecov Report

Merging #40 (6e1ee98) into master (43d7baa) will increase coverage by 2.82%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #40      +/-   ##
==========================================
+ Coverage   84.22%   87.05%   +2.82%     
==========================================
  Files           6        6              
  Lines         317      363      +46     
==========================================
+ Hits          267      316      +49     
+ Misses         50       47       -3     
Impacted Files Coverage Δ
src/patterns.jl 84.09% <100.00%> (+8.41%) ⬆️
src/tree-ops.jl 83.17% <100.00%> (+2.12%) ⬆️
src/values.jl 97.61% <0.00%> (+0.32%) ⬆️
src/parallelism.jl 81.48% <0.00%> (+0.71%) ⬆️
src/datastructure.jl 88.73% <0.00%> (+2.78%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 43d7baa...6e1ee98. Read the comment docs.

@DrChainsaw
Copy link
Collaborator Author

@shashi Bump?

In case you have more pressing matters on your table or just don't want to context switch: I can work around the issue from the outside by just adding |> setparent after any getindex/mv/merge so this is just a bit of an inconvenience for me atm.

@@ -73,7 +73,7 @@ function _regex_map(yes, no, t::FileTree, regex::Regex, toplevel=true)
if isempty(cs)
return no(t)
else
return FileTree(t; children=cs)
return FileTree(t; children=cs) |> setparent
Copy link
Owner

Choose a reason for hiding this comment

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

Setparent here may copy sub trees more times than necessary. I’d suggest moving this to the place which calls _regex_map or _glob_map

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess you mean the getindex functions? Sure thing! Will commit once tests finish.

@shashi
Copy link
Owner

shashi commented Feb 9, 2021

Sorry about the delay here. This got drowned out in the other notifications. Thanks for pinging again! This looks good to me, except for that comment I left.

@DrChainsaw
Copy link
Collaborator Author

Thanks for checking!

Do you have an opinion on this:

Another option could be to add a call to setparent in the convenience “copy” constructor for FileTree if one wants to be really strict about not allowing such trees.

Is there some reason one should be able to create trees where nodes are not the parent of their children?

@shashi shashi merged commit c5b6dcd into shashi:master Feb 12, 2021
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.

Missing root when accessing by regex
3 participants