question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Targets' `add_target(s)` methods do not correctly check passed paths

See original GitHub issue

Description of issue or feature request:

Judging from the docstrings and comments, add_target and add_targets are expected to update a Targets object with passed target paths, if they are relative to a targets directory base path (i.e. self._targets_directory).

However, they don’t seem to take into account that Python’s os.path.join ignores all path component arguments prior to a component that looks like an absolute path.

Current behavior:

  • Works as expected (?) if passed target path is relative to a targets directory base path or absolute but falls into the targets directory:
# repo._targets_directory == "/path/to/repo/targets"
repo.targets.add_target("foo.txt")
repo.targets.add_target("/path/to/repo/targets/bar.txt)
# Successfully adds "foo.txt" and "bar.txt" 
  • Fails if the passed target path is not absolute and does not exist relative to targets directory base path “/path/to/repo/targets”.
# repo._targets_directory == "/path/to/repo/targets"
repo.targets.add_target("repo/targets/foo.txt")
# Fails with "'/path/to/repo/targets/repo/targets/foo.txt' is not a valid file in the repository's targets directory"
  • Fails if the passed target path is absolute and does not exist
#repo._targets_directory == "/path/to/repo/targets"
repo.targets.add_target("/path/does/not/exist/foo.txt")
# Fails with "'/path/does/not/exist/foo.txt' is not a valid file in the repository's targets directory"
  • Has unexpected behavior if the passed path is absolute and exists!

Expected behavior: Revise intended behavior, update implementation accordingly.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
joshuaglcommented, Mar 4, 2020

add_target could just add any paths passed to the internal representation of targets metadata, checking that they are relative (and maybe don’t contain “…”?). And only later, when the corresponding files are actually needed, i.e. to generate hashes, should it fail gracefully if any of the paths can’t be resolved into a file relative to the targets directory base path.

This feels like a sensible approach, that handles @lukpueh’s least-surprise concerns above and we can address my debugability concern with appropriate logging.

1reaction
lukpuehcommented, Nov 29, 2019

I agree with your debugging concern, @joshuagl. I am concerned with least surprise. 😃

To me, and this should answer your other question, none of above cases seems fully surprise-free. Here are some concerns:

  • Why can I pass an absolute path, if the spec says that targetpaths should be relative?
  • Why should I pass an absolute path, if it must be relative to an “unknown” base path (i.e. self._targets_directory), whose portion in the path gets stripped anyway?
  • Why must a relative path be relative to an “unknown” base path, and not relative to my cwd?
Read more comments on GitHub >

github_iconTop Results From Across the Web

Target groups for your Application Load Balancers
Each target group is used to route requests to one or more registered targets. ... The load balancer does not validate these certificates....
Read more >
swift - Different behavior between addTarget and ...
Adding a target to something like UIGestureRecognizer or UIButton only passes one parameter to the selected function.
Read more >
addTarget:action:forControlEvents - Apple Developer
Associates a target object and action method with the control.
Read more >
2 Discovering, Promoting, and Adding Targets
From the Setup menu, select Manage Cloud Control, and then click Agents. Click the required Management Agent. Verify whether the Management Agent is...
Read more >
When to use target="_blank" | CSS-Tricks
Anchor links1 may have a target attribute which controls what happens when that link is clicked. One of the possible values of that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found