Skip to content

Refactor path handling code to use pathlib instead of strings #391

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

Closed
przadka opened this issue May 11, 2023 · 1 comment
Closed

Refactor path handling code to use pathlib instead of strings #391

przadka opened this issue May 11, 2023 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@przadka
Copy link
Contributor

przadka commented May 11, 2023

In various parts of our codebase, we are handling paths as string objects. It is recommended to use the pathlib module when dealing with paths as it provides a more readable and reliable way to handle filesystem paths. It also makes the code more object-oriented and less error-prone.

Here is an example of the current code that should be refactored:

def fix_windows_path_limit(path):
    """
    Prefix paths when running on Windows to overcome 260 character path length limit.
    See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath

    :param path: a path to prefix
    :type path: str
    :return: a prefixed path
    :rtype: str
    """
    if platform.system() == 'Windows':
        if path.startswith('\\\\'):
            # UNC network path
            return '\\\\?\\UNC\\' + path[2:]
        elif os.path.isabs(path):
            # local absolute path
            return '\\\\?\\' + path
        else:
            # relative path, don't alter
            return path
    else:
        return path

The following classes and methods are known to require this refactor:

  • def fix_windows_path_limit(path)
  • class AbstractFolder and its subclasses
  • class ProgressReport (potentially)
  • class AbstractPath and its subclasses
  • class ScanPoliciesManager
  • class AbstractAction and its subclasses

This issue's resolution would involve replacing the current string path handling with pathlib objects, ensuring all related functionality remains intact.

@ppolewicz ppolewicz added the help wanted Extra attention is needed label May 11, 2023
@mjurbanski-reef
Copy link
Contributor

better described, but still a duplicated of #239

@mjurbanski-reef mjurbanski-reef closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants