Skip to content

Some tweaks and updates for the next release #18

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

Merged
merged 1 commit into from
Jul 28, 2016

Conversation

garyb
Copy link
Member

@garyb garyb commented Jun 28, 2016

Resolves #14, will resolve #5.

Wanted to get a few things in before we tag a new version 😄

@@ -505,20 +527,32 @@ module Data.Path.Pathy
instance eqPath :: Eq (Path a b s) where
eq p1 p2 = canonicalize p1 `identicalPath` canonicalize p2

instance showFileName :: Show FileName where
show (FileName name) = "FileName " <> show name
instance ordPath :: Ord (Path a b s) where
Copy link
Member

Choose a reason for hiding this comment

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

How could this be used? "./" < "/" < "../foo" < "/foo/" < "/foo" 😕

Copy link
Member Author

Choose a reason for hiding this comment

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

It's so you can use paths in dictionaries and the like, the ordering isn't meaningful.

Copy link
Member

Choose a reason for hiding this comment

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

Ah! I see. I don't know if it makes sense but why not something like this?

instance ordPath :: Ord (Path a b s) where 
  compare p1 p2 = compare (unsafePrintPath p1) (unsafePrintPath p2) 

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm allergic to strings 😆. In all seriousness, I think that would be less efficient, as the escaper runs for every path segment when you convert it to a string vs just checking the structure.

Copy link
Member

Choose a reason for hiding this comment

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

Ok 😄

@garyb garyb force-pushed the updates branch 2 times, most recently from 830bda3 to 1e872ed Compare June 28, 2016 14:17
@garyb garyb changed the title [WIP] Some tweaks and updates for the next release Some tweaks and updates for the next release Jun 28, 2016
@garyb
Copy link
Member Author

garyb commented Jun 28, 2016

Ok, this is ready to review now. As well as fixing the linked issues and adding some new basic instances there's a new function:

-- | Marks an absolute path as sandboxed without sandboxing to a particular
-- | location.
sandboxAbs :: forall b. Path Abs b Unsandboxed -> Path Abs b Sandboxed

as we end up using a coercion to that effect all the time. I did consider making it Path a b Unsandboxed -> Path Abs b Sandboxed so it could turn any path into an absolute sandboxed path, but I'm not sure if that's a bit more questionable?

Also updated the formatting to be more consistent with how we do it everywhere else.

Also fixed some links in the docs to a non-existant examples file.

@jdegoes
Copy link
Contributor

jdegoes commented Jun 28, 2016

@garyb That function is not safe and defeats the point of sandboxing. You can change the signature to return Maybe (Path Abs b Sandboxed) and then return Nothing in the case where the parent path node (..) appears in the path.

@garyb
Copy link
Member Author

garyb commented Jun 29, 2016

@jdegoes you mean the version of sandboxAbs that works with any path? The current version doesn't have that problem, as you can't do that in an Abs path, can you?

If so, yeah, that's why I said it was questionable. I was going to handle Rel cases by doing something like p relativeTo rootDir with a fromMaybe rootDir, etc. but it's already possible to easily do that without resorting to hacks, but making an Abs path sandboxed and still Abs is pretty tedious currently.

@jdegoes
Copy link
Contributor

jdegoes commented Jun 29, 2016

you mean the version of sandboxAbs that works with any path? The current version doesn't have that problem, as you can't do that in an Abs path, can you?

An absolute path may contain relative entries. Meaning that the signature of sandboxAbs is incorrect, in the sense you can produce a "sandboxed" path which attempts to access a directory higher than the root directory (which does not make any sense).

@garyb
Copy link
Member Author

garyb commented Jun 29, 2016

Ah ok, I see now.

@garyb
Copy link
Member Author

garyb commented Jul 19, 2016

I've removed the offending sandboxAbs.

I think fixing #5 should fix slamdata/slamdata#928 since that seems to be arising due to dir "." not being escaped, so when it is printed and re-parsed it is read as currentDir.

@garyb
Copy link
Member Author

garyb commented Jul 19, 2016

We'll have to release this as v2.0.0 as it didn't make the v1.0.0 cut - making the left/right stuff consistent means the API has a breaking change. Possibly changing things to escape properly could be considered a breaking change too, given the behaviour above with dir ".".

@garyb
Copy link
Member Author

garyb commented Jul 28, 2016

Any objections to me merging this as it is @jdegoes?

@jdegoes
Copy link
Contributor

jdegoes commented Jul 28, 2016

Looks good. 👍

@garyb garyb merged commit cd9cee6 into purescript-contrib:master Jul 28, 2016
@garyb garyb deleted the updates branch July 28, 2016 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Left/Right consistency unsafePrintPath' does not use the provided Escaper
3 participants