-
Notifications
You must be signed in to change notification settings - Fork 1k
Deprecated filepath.HasPrefix #296
Comments
@adg could you speak to this one? |
@sdboyer I don't remember this being deprecated, but I can see why it is. The places where we use it were once a simple We should probably replace such occurrences with our own function that uses filepath.Abs to canonicalize the paths before comparing them. |
It's just Either way, yeah, we should write our own implementation. |
I'd be very happy if you did! Thank you.
…On 9 March 2017 at 15:08, ankitm123 ***@***.***> wrote:
@adg <https://github.com/adg>, @sdboyer <https://github.com/sdboyer>, I
can work on it this weekend, if it is ok.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#296 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AIDildDSds8wTdzxLUfzydN11cPVLJsfks5rj3s-gaJpZM4MVkXI>
.
|
@ankitm123 Are you still working on this? I might take a look at it if you don't have time. |
@zacps, I should have it done within 2 days. |
any update on this? |
I'll do it tomorrow unless @ankitm123 has a pull in. |
@sdboyer, @zacps Sorry for the delay, I am in the process of joining a new job and relocating! I will use the os.pathseparator in the hasSuffix function, to make it cross platform. |
Honestly, I'm not sure if that works or not, because I don't know what "not respecting path boundaries" means in those comments on the windows |
Should we expand special paths/environment variables/UNC paths? I think it makes sense for this: You also shouldn't use |
@sdboyer, I think what they mean by path boundaries is just path separator (/ in linux and \ in windows) @zacps, Thanks for the suggestion. Using strings.Compare is not the ideal way to compare. I will change it to ==. Also, I think we can check is the filepath has ~ (say ~/file), and then use the os.environ function to replace it with /home/. I will include the changes, and we can see how it works. Thanks! |
OHH, I see. Yeah, I've been dealing with respecting path element boundaries for some time now - it just came up in #271, but there's a handful of funcs in gps that deal with it, too. That part definitely makes sense. Looking at the links, and recalling from the earlier issue that introduced this, here's some thoughts:
There's also this unexported func in stdlib that might provide some guidance. |
@sdboyer Looks like
|
@zacps,Doesn't filepath.VolumeName() only work for windows system? It returns empty strings for other OS, isn't it? |
@ankitm123 Yeah, which is what we want right? We can compare the value of this to check the volume. On windows it'll work properly with UNC paths and drive names and on other systems, where those aren't relevant it'll always succeed ( |
@zacps that was what I'd figured about case sensitivity until recently, as well. But it's a filesystem property, not an OS one. See rsc's comment on the CL @ankitm123 linked to. |
@rsc Yeah ok it looks like it's possible to change it on windows, I don't think we can just write a file somewhere though, you wouldn't expect a path comparison function to write to the filesystem. We might not even have permission to. Are any windows systems case sensitive by default? It looked like it was an obscure config option. Just assuming per OS is far from perfect but I think it's definitely better than writing to the filesystem. |
Yep. I think I abbreviated my first thought on this too much. Allow me to expand. Given that:
If we had to write a file somewhere, then the tail dir in cwd has to be writeable anyway, so that's the place to do it. But, I also think we could do one better and avoid writing altogether (as I agree, it would be quite unexpected to do that in a func like this). Say that cwd is
Have I missed something? |
Nope, I think that looks good to me. So checklist is:
|
We're running into issues with this over in #379, as well. It seems like we have a TODO list now - I'm hoping someone has the time to tackle an implementation? |
(maybe we'll just convert that issue to be the PR that fixes this) |
I will take a look at it this weekend. |
@ankitm123 OK - @Civil also indicated they might try over the weekend. Neither of you fully committed, but just wanted to give you both a heads-up. |
The HasPrefix function determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This addresses issue golang#296. In the current state it does not really fix it because it needs support and testing for non-Unix platforms. Signed-off-by: Marcelo E. Magallon <[email protected]>
I would appreciate it if you guys can take a look at the PR and provide feedback. This was done very very quickly. At least the tests need fixing. |
The hasFilepathPrefix function determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This addresses issue golang#296. In the current state it does not really fix because the existing code that uses filepath.HasPrefix needs to be modified. Signed-off-by: Marcelo E. Magallon <[email protected]>
The hasFilepathPrefix function determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This addresses issue golang#296. In the current state it does not really fix because the existing code that uses filepath.HasPrefix needs to be modified. Signed-off-by: Marcelo E. Magallon <[email protected]>
# Ignore the deprecation warning about filepath.HasPrefix (SA1019). This flag
# can be removed when issue #296 is resolved.
- staticcheck -ignore='github.com/golang/dep/context.go:SA1019 github.com/golang/dep/cmd/dep/init.go:SA1019' $PKGS If you're submitting a PR for this, would you be so kind as to delete that flag (and the comment above) from the |
The hasFilepathPrefix function determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This addresses issue golang#296. In the current state it does not really fix because the existing code that uses filepath.HasPrefix needs to be modified. Signed-off-by: Marcelo E. Magallon <[email protected]>
The hasFilepathPrefix function determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This addresses issue golang#296. In the current state it does not really fix because the existing code that uses filepath.HasPrefix needs to be modified. Signed-off-by: Marcelo E. Magallon <[email protected]>
internal.HasFilepathPrefix determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This fixes issue golang#296. Signed-off-by: Marcelo E. Magallon <[email protected]>
internal.HasFilepathPrefix determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This fixes issue golang#296. Signed-off-by: Marcelo E. Magallon <[email protected]>
internal.HasFilepathPrefix determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This fixes issue golang#296. Signed-off-by: Marcelo E. Magallon <[email protected]>
internal.HasFilepathPrefix determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This fixes issue golang#296. Signed-off-by: Marcelo E. Magallon <[email protected]>
#395 is merged, so this should now be fixed. Closing this out 😄 |
internal.HasFilepathPrefix determines whether a given path is contained in another, being careful to take into account that "/foo" doesn't contain "/foobar" and that there are case-sensitive and case-insensitive fileystems out there. This fixes issue golang#296. Signed-off-by: Marcelo E. Magallon <[email protected]>
While trying to solve the issue #290, I took a look at the dep source code. I see multiple instances of filepath.HasPrefix. The function is deprecated, so should we not remove/replace it from the source code? Take a look at this link:
https://golang.org/pkg/path/filepath/#HasPrefix
Ankit
The text was updated successfully, but these errors were encountered: