Skip to content
This repository has been archived by the owner on Feb 3, 2018. It is now read-only.

some saftey precautions for windows #142

Closed
wants to merge 1 commit into from
Closed

some saftey precautions for windows #142

wants to merge 1 commit into from

Conversation

jessfraz
Copy link

  • change all "path" to "filepath"
  • fix rename since syscall.Rename on windows cannot rename a directory

@@ -19,6 +19,14 @@ func renameWithFallback(src, dest string) error {
return err
}

// Windows cannot use syscall.Rename to rename a directory
Copy link
Owner

@sdboyer sdboyer Jan 14, 2017

Choose a reason for hiding this comment

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

OK forgive me for being obtuse about this, but I'm trying to understand the background on this limitation, and I've yet to turn up anything super clear. From what I can gather, Go relies on the MoveFile API in general; for syscall.Rename(), it calls MoveFile(), which I guess should be capable of handling dir renames.

os.Rename, otoh, also ultimately uses the MoveFile API to do its work - which means it should also be capable of dir renames? The only difference is that it uses MoveFileEx(), with the MOVEFILE_REPLACE_EXISTING flag (I believe that's maybe new as of Go 1.6?), which makes behavior generally more similar to POSIX systems than a pure MoveFile() call.

So yeah, I'm confused on this, and pointers to some explanation of the limitation here would be super appreciated.

Copy link
Author

@jessfraz jessfraz Jan 25, 2017

Choose a reason for hiding this comment

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

this is from the go 1.8 release notes:

On Unix systems, os.Rename will now return an error when used to rename a directory to an 
existing empty directory. Previously it would fail when renaming to a non-empty directory but 
succeed when renaming to an empty directory. This makes the behavior on Unix correspond to 
that of other systems.

https://tip.golang.org/doc/go1.8 so it will fail on unix in go 1.8 as well

Copy link
Owner

Choose a reason for hiding this comment

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

Right, but that doesn't say it fails when attempting to rename a directory, period - just that it fails if attempting to rename a directory to an existing empty directory. At this point, we haven't established yet whether the target dir exists, or (if it does) whether it's empty.

Copy link
Author

Choose a reason for hiding this comment

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

ah I see what you are saying

@sdboyer
Copy link
Owner

sdboyer commented Jan 14, 2017

man, how did i miss so many of these... 🤦‍♂️

thanks!

@sdboyer
Copy link
Owner

sdboyer commented Jan 14, 2017

Oh right, so...we have some failures because (HAPPY DAY!) at least some of those actually should be path.Join, not filepath.Join. When we're operating on import paths or URLs, it needs to be the former; when it's filesystem paths, it's the latter. Lemme review each one...

deduce.go Outdated
@@ -264,9 +264,9 @@ func (m gopkginDeducer) deduceSource(p string, u *url.URL) (maybeSource, error)
u.Host = "github.com"
if v[2] == "" {
elem := v[3][1:]
u.Path = path.Join("/go-"+elem, elem)
u.Path = filepath.Join("/go-"+elem, elem)
Copy link
Owner

Choose a reason for hiding this comment

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

import path or URL here, not fs, so path.Join() is right

deduce.go Outdated
} else {
u.Path = path.Join(v[2], v[3])
u.Path = filepath.Join(v[2], v[3])
Copy link
Owner

Choose a reason for hiding this comment

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

ditto

deduce.go Outdated
@@ -716,7 +716,7 @@ func normalizeURI(p string) (u *url.URL, newpath string, err error) {
if u.Host == "" {
newpath = p
} else {
newpath = path.Join(u.Host, u.Path)
newpath = filepath.Join(u.Host, u.Path)
Copy link
Owner

Choose a reason for hiding this comment

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

ditto

manager_test.go Outdated
@@ -446,7 +445,7 @@ func TestDeduceProjectRoot(t *testing.T) {
}

// Now do a subpath
sub := path.Join(in, "foo")
sub := filepath.Join(in, "foo")
Copy link
Owner

Choose a reason for hiding this comment

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

import path

manager_test.go Outdated
@@ -459,7 +458,7 @@ func TestDeduceProjectRoot(t *testing.T) {

// Now do a fully different root, but still on github
in2 := "github.com/bagel/lox"
sub2 := path.Join(in2, "cheese")
sub2 := filepath.Join(in2, "cheese")
Copy link
Owner

Choose a reason for hiding this comment

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

ditto

@sdboyer
Copy link
Owner

sdboyer commented Jan 14, 2017

i was gonna say that, when file:/// support is added (which is planned), it'll get even trickier to differentiate in situations where the string being dealt with could be an import path or URL, but thankfully that's apparently not the case

- change all "path" to "filepath"
- fix rename since syscall.Rename on windows cannot rename a directory

Signed-off-by: Jess Frazelle <[email protected]>
@codecov-io
Copy link

codecov-io commented Jan 25, 2017

Codecov Report

Merging #142 into master will increase coverage by -0.98%.

@@            Coverage Diff            @@
##           master    #142      +/-   ##
=========================================
- Coverage   78.88%   77.9%   -0.98%     
=========================================
  Files          24      24              
  Lines        3709    3703       -6     
=========================================
- Hits         2926    2885      -41     
- Misses        582     619      +37     
+ Partials      201     199       -2
Impacted Files Coverage Δ
util.go 33.33% <ø> (-2.82%)
result.go 70.83% <100%> (-5.36%)
source.go 35.67% <ø> (-3.51%)
vcs_source.go 76.01% <ø> (-1.64%)
source_manager.go 90.63% <ø> (-0.75%)
analysis.go 85.04% <ø> (-0.26%)
cmd.go
typed_radix.go 44.26% <ø> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f8d2e5...18c0694. Read the comment docs.

@sdboyer sdboyer force-pushed the master branch 2 times, most recently from 6fd33b5 to 4284958 Compare January 26, 2017 15:57
@sdboyer
Copy link
Owner

sdboyer commented Mar 22, 2017

Don't think this applies anymore - closing.

@sdboyer sdboyer closed this Mar 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants