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

Path normalization or equality check #2910

Open
harendra-kumar opened this issue Dec 18, 2024 · 1 comment
Open

Path normalization or equality check #2910

harendra-kumar opened this issue Dec 18, 2024 · 1 comment
Milestone

Comments

@harendra-kumar
Copy link
Member

The following potential operations are possible on paths which can be used as building blocks. These operations just split path on separators.

  • splitPath :: Path -> Stream m Path
  • foldComponents :: Stream m Char -> Fold m Char a -> Stream m a
  • components :: Stream m Char -> Stream m Path

On top of these we then need to:

  • filter empty components to remove duplicate separators like //. Or we can use uniq to remove consecutive separators in the input stream.
  • filter out /./ components

The next set of operations is to build a Path from path components:

  • combineComponents :: Stream m Path -> m Path

Note, for windows we may need to first split the path into drive and the remaining path. And then split the remaining path into components like posix.

We do not need a normalize operation, we need a good path equality check operation. We can do that by creating normalized path component streams for both paths and compare those.

@harendra-kumar harendra-kumar added this to the 0.11.0 milestone Dec 18, 2024
@adithyaov
Copy link
Member

There are a few things to consider in path normalization:

Splitting of the drive itself.

  • This is straightforward for posix. The only drive is /
  • Much more complex for windows.

While splitting Path into its components we need to consider a few things.

  1. Does the path end with a /?
  2. Does the path end with a /.?
  3. /home/user/ and /home/user are 2 different paths

Path normalization will include the following:

  1. Split the path into drive and the remaining path
  2. Normalize the drive
  3. Normalize the remaining path
  4. While normalizing the remaining path, consider how the path ends.

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

No branches or pull requests

2 participants