This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author zbysz
Recipients eric.smith, eryksun, serhiy.storchaka, veky, zbysz
Date 2021-06-27.17:57:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1624816630.02.0.555203131921.issue44452@roundup.psfhosted.org>
In-reply-to
Content
> I can see the need for generalized 'drive' support that sets an arbitrary path prefix as the 'drive'. For example, if "/var/tmp/instroot" is a 'drive', then joining it to "/some/path" returns "/var/tmp/instroot/some/path". However, subsequently joining that result to "/suffix" would return "/var/tmp/instroot/suffix".

I think that the "drive concept" only makes sense on Windows. With POSIX paths, the expectation is that you can concatenate paths recursively, and consistency is much more useful than the drive concept.

One special case where you might concat multiple levels of paths is when the paths are generated through some configuration mechanism, and an occasional absolute path might sneak in, but we still want to use the same "relative" concatenation.

For example:
def path_to_some_binary_in_container(container, usr_merge_was_done=True):
  """Construct a path with support for systems with /usr/bin and legacy systems
     with /bin (https://fedoraproject.org/wiki/Features/UsrMove).
  """
  path_to_containers = '/var/lib/machines'
  prefix = 'usr/' if usr_merge_was_done else '/'
  suffix = 'bin/some-binary'
  return path_to_containers / container / prefix / suffix

path_to_some_binary('cont1') returns PosixPath('/var/lib/machines/cont1/usr/bin/some-binary'), but path_to_some_binary('cont1', False) returns PosixPath('/bin/some-binary'). The "bug" is that '/' was used instead of ''. This is exactly the
pitfall that I want to avoid:
  return path_to_containers // container // prefix // suffix
will do the expected thing.
History
Date User Action Args
2021-06-27 17:57:10zbyszsetrecipients: + zbysz, eric.smith, serhiy.storchaka, eryksun, veky
2021-06-27 17:57:10zbyszsetmessageid: <1624816630.02.0.555203131921.issue44452@roundup.psfhosted.org>
2021-06-27 17:57:10zbyszlinkissue44452 messages
2021-06-27 17:57:09zbyszcreate