Message:
Hello golan...@googlegroups.com,
I'd like you to review this change to
http://go.googlecode.com/hg/
Description:
path: work for windows.
added IsDirSep, IsVolumeSep, IsSame.
Please review this at http://codereview.appspot.com/3989064/
Affected files:
M src/pkg/path/match.go
M src/pkg/path/match_test.go
M src/pkg/path/path.go
M src/pkg/path/path_test.go
M src/pkg/path/path_unix.go
M src/pkg/path/path_windows.go
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/match.go#newcode23
src/pkg/path/match.go:23: // '\\' c matches character c
I am concerned about using patterns with backslashes in Match. For
example, Match("C:\\*", "C:\autoexec.bat") will not match because "\\*"
matches a literal star, no?
I am not sure how to solve this.
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go
File src/pkg/path/path.go (right):
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode85
src/pkg/path/path.go:85: buf[w] = DirSeps[0]
Is it really necessary to replace a literal slash with DirSeps[0]?
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode119
src/pkg/path/path.go:119: return Clean(strings.Join(elem[i:],
string(DirSeps[0])))
same as above
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode208
src/pkg/path/path.go:208: // IsVolumeSep return true if VolumeSeps
include the letter.
IsVolumeSep returns true if c is a volume separator character.
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode213
src/pkg/path/path.go:213: // IsDirSep return true if DirSeps include the
letter.
IsDirSep returns true if c is a directory separator character.
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_test.go
File src/pkg/path/path_test.go (right):
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_test.go#newcode326
src/pkg/path/path_test.go:326: var basetests []CleanTest
remove, basetests is defined above.
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_unix.go
File src/pkg/path/path_unix.go (right):
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_unix.go#newcode20
src/pkg/path/path_unix.go:20: return lhs == rhs
On Mac OS X, there are case-insensitive file systems. Should IsSame do
case-insensitive matching in this case?
(If yes, this would be for another CL.)
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_windows.go
File src/pkg/path/path_windows.go (right):
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_windows.go#newcode37
src/pkg/path/path_windows.go:37: // note that this function don't
normalize paths.
s/n/N/
s/don't/does not/
IMHO, the doc comment should mention that it uses different rules on
POSIX and Windows (case-insensitive, forward slash equal to backslash).
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode85
src/pkg/path/path.go:85: buf[w] = DirSeps[0]
This become normalizer replacing slash to backslash for win32.
c:/go/src/package/runtime to c:\go\src\package\runtime
On 2011/02/04 09:38:47, bsiegert wrote:
> Is it really necessary to replace a literal slash with DirSeps[0]?
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode119
src/pkg/path/path.go:119: return Clean(strings.Join(elem[i:],
string(DirSeps[0])))
on win32, DirSeps[0] is backslash. but slash for unix.
On 2011/02/04 09:38:47, bsiegert wrote:
> same as above
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode208
src/pkg/path/path.go:208: // IsVolumeSep return true if VolumeSeps
include the letter.
On 2011/02/04 09:38:47, bsiegert wrote:
> IsVolumeSep returns true if c is a volume separator character.
Done.
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode213
src/pkg/path/path.go:213: // IsDirSep return true if DirSeps include the
letter.
On 2011/02/04 09:38:47, bsiegert wrote:
> IsDirSep returns true if c is a directory separator character.
Done.
On 2011/02/04 09:38:47, bsiegert wrote:
> http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/match.go
> File src/pkg/path/match.go (right):
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/match.go#newcode23
> src/pkg/path/match.go:23: // '\\' c matches character c
> I am concerned about using patterns with backslashes in Match. For
example,
> Match("C:\\*", "C:\autoexec.bat") will not match because "\\*" matches
a literal
> star, no?
> I am not sure how to solve this.
> http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go
> File src/pkg/path/path.go (right):
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode85
> src/pkg/path/path.go:85: buf[w] = DirSeps[0]
> Is it really necessary to replace a literal slash with DirSeps[0]?
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode119
> src/pkg/path/path.go:119: return Clean(strings.Join(elem[i:],
> string(DirSeps[0])))
> same as above
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode208
> src/pkg/path/path.go:208: // IsVolumeSep return true if VolumeSeps
include the
> letter.
> IsVolumeSep returns true if c is a volume separator character.
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode213
> src/pkg/path/path.go:213: // IsDirSep return true if DirSeps include
the letter.
> IsDirSep returns true if c is a directory separator character.
I didn't fix all. X-(
Not sure if this is a good idea. Does c:\go\src\package\runtime still
match "c:/go/src/package/*"?
--Benny.
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/match.go#newcode23
src/pkg/path/match.go:23: // '\\' c matches character c
This is pattern, developer should know / will be match backslash and
backslash are escape. He shouldn't use backslash as path separator.
On 2011/02/04 09:38:47, bsiegert wrote:
> I am concerned about using patterns with backslashes in Match. For
example,
> Match("C:\\*", "C:\autoexec.bat") will not match because "\\*" matches
a literal
> star, no?
> I am not sure how to solve this.
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_test.go
File src/pkg/path/path_test.go (right):
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_test.go#newcode326
src/pkg/path/path_test.go:326: var basetests []CleanTest
On 2011/02/04 09:38:47, bsiegert wrote:
> remove, basetests is defined above.
Done.
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_unix.go
File src/pkg/path/path_unix.go (right):
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path_unix.go#newcode20
src/pkg/path/path_unix.go:20: return lhs == rhs
Yes, I'll path to another CL.
Thanks for notice.
Argument of Match is not path. it's patter. We shouldn't treat pattern
as path.
On 2011/02/04 10:02:55, bsiegert wrote:
> On Fri, Feb 4, 2011 at 10:54, <mailto:matt...@gmail.com> wrote:
> >
http://codereview.appspot.com/3989064/diff/6001/src/pkg/path/path.go#newcode85
> > src/pkg/path/path.go:85: buf[w] = DirSeps[0]
> > This become normalizer replacing slash to backslash for win32.
> >
> > c:/go/src/package/runtime to c:\go\src\package\runtime
> Not sure if this is a good idea. Does c:\go\src\package\runtime still
> match "c:/go/src/package/*"?
> --Benny.
I always have the following case in mind: you write a program that
accepts file name arguments, and the user gives you "C:\*" as an arg.
On Unix, the shell expands this for you, on Windows you have to call
path.Glob (which uses path.Match internally). How do you treat the
user input? Do you replace backslashes by slashes?
$text =~ /\Q$text\E/
On 2011/02/04 10:21:27, bsiegert wrote:
Russ
How about adding a function to path in order to change the default separator?
--Benny.
> I'd like you to review this change to
> http://go.googlecode.com/hg/
Please, note http://code.google.com/p/go/issues/detail?id=1483.
Perhaps, you should add "Fixes issue 1483." at the end of your CL
description, if you're planning to resolve it.
Alex
You need to write it the way the tools expect.
Fixes issue 1483.
Fixes issue 1107.
Fixes issue 1423.
-rob
On Feb 7, 2011, at 3:57 PM, mattn wrote:
> ok, I added "fix issue 1107, 1423, 1483".
>
> On Tuesday, February 8, 2011 8:36:29 AM UTC+9, brainman wrote:
> On 2011/02/04 06:30:52, mattn wrote:
> > Hello mailto:gola...@googlegroups.com,
> > I'd like you to review this change to
> > http://go.googlecode.com/hg/
>
> Please, note http://code.google.com/p/go/issues/detail?id=1483.
>
> Perhaps, you should add "Fixes issue 1483." at the end of your CL
> description, if you're planning to resolve it.
It sounds like everyone thinks that package path
should be an OS-specific package. I might as well
go along, since path.Walk has set the precedent.
But before we just toss in every function you can
think of, I would like to see some discussion via email
to golang-dev, not via looking at code on the codereview
server, of what the final API is going to be.
Right now it feels like a midden heap of Windows artifacts.
Russ
Russ
I proposed a long time ago to loosely follow the well-established API
of File::Spec in Perl. The nice thing about this API is its symmetry
-- the functions operating on paths have a corresponding reverse
function. Comparing File::Spec, to path, we have:
canonpath - similar to path.Clean
catdir, catfile, join - path.Join (I figure that the separation in the
Perl functions is needed on VMS)
splitdir - path.Split (but see below)
curdir, rootdir, updir - I don't think we need these
file_name_is_absolute - path.IsAbs
tmpdir, devnull - in other packages in Go
splitpath - path.Split. However, splitpath returns *three* values:
"Splits a path in to volume, directory, and filename portions. On
systems with no concept of volume, returns '' for volume."
For symmetry, there is also catpath: "Takes volume, directory and file
portions and returns an entire path. Under Unix, $volume is ignored,
and directory and file are concatenated. A '/' is inserted if need be.
On other OSes, $volume is significant."
Then, there are two functions that would be very useful IMHO:
abs2rel: Takes a destination path and an optional base path returns a
relative path from the base path to the destination path.
rel2abs: Converts a relative path to an absolute path.
The following two might also be interesting to have:
case_tolerant: Returns a true or false value indicating, respectively,
that alphabetic case is not or is significant when comparing file
specifications.
no_upwards: Given a list of file names, strip out those that refer to
a parent directory.
--Benny.
Clean("C:/") returned "C:"
On 2011/02/10 00:42:46, mattn wrote:
> Hello mailto:golan...@googlegroups.com, bsiegert, r, rsc, brainman,
r2 (cc:
> mailto:golan...@googlegroups.com),
* renamed IsSame to isSame
This is not needed for go user.
* fixed problem that Clean("C:/") return "C:"
On 2011/02/10 01:02:06, mattn wrote:
> Hello mailto:golan...@googlegroups.com, bsiegert, r, rsc, brainman,
r2 (cc:
> mailto:golan...@googlegroups.com),
> Please take another look.
You're claiming this CL fixes these issues:
Fixes issue 1483.
Fixes issue 1107.
Fixes issue 1423.
But I don't think either 1483 or 1423 are fixed. After your patch this
program:
package main
import (
"path"
"fmt"
)
func main() {
fmt.Println(path.Join("directory", "file"))
println(path.IsAbs("C:\\hello.txt"))
}
prints this:
directory/file
false
Regardless, I think, you should always try and include reported issues
to the package tests, if possible.
Alex
directory\file
true
> directory\file
> true
You're right, I'm wrong. It works.
LGTM.
http://codereview.appspot.com/3989064/diff/38001/src/pkg/path/path_test.go
File src/pkg/path/path_test.go (right):
http://codereview.appspot.com/3989064/diff/38001/src/pkg/path/path_test.go#newcode332
src/pkg/path/path_test.go:332:
Please, add test for above mentioned
path.Join("directory", "file")
and
path.IsAbs("C:\\hello.txt")
http://codereview.appspot.com/3989064/diff/38001/src/pkg/path/path_unix.go
File src/pkg/path/path_unix.go (right):
http://codereview.appspot.com/3989064/diff/38001/src/pkg/path/path_unix.go#newcode6
src/pkg/path/path_unix.go:6:
import "strings"
Please take another look.
http://codereview.appspot.com/3989064/diff/38001/src/pkg/path/path_test.go#newcode332
src/pkg/path/path_test.go:332:
On 2011/02/16 05:02:31, brainman wrote:
> Please, add test for above mentioned
> path.Join("directory", "file")
> and
> path.IsAbs("C:\\hello.txt")
Done.
http://codereview.appspot.com/3989064/diff/38001/src/pkg/path/path_unix.go
File src/pkg/path/path_unix.go (right):
http://codereview.appspot.com/3989064/diff/38001/src/pkg/path/path_unix.go#newcode6
src/pkg/path/path_unix.go:6:
On 2011/02/16 05:02:31, brainman wrote:
> import "strings"
Done.
Russ