Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
eecc7663
Commit
eecc7663
authored
Mar 10, 2017
by
Jeromy Johnson
Committed by
GitHub
Mar 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3328 from djdv/win-driveroot-fix
add: [Windows] Drive root parse fix
parents
56bbcc9f
b29945e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
3 deletions
+49
-3
commands/cli/parse.go
commands/cli/parse.go
+49
-3
No files found.
commands/cli/parse.go
View file @
eecc7663
...
...
@@ -6,13 +6,14 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"sort"
"strings"
cmds
"github.com/ipfs/go-ipfs/commands"
files
"github.com/ipfs/go-ipfs/commands/files"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
osh
"gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
u
"gx/ipfs/QmZuY8aV7zbNXVy6DyN9SmnuH3o9nG852F4aTiSBpts8d1/go-ipfs-util"
)
...
...
@@ -260,7 +261,7 @@ const msgStdinInfo = "ipfs: Reading from %s; send Ctrl-d to stop."
func
parseArgs
(
inputs
[]
string
,
stdin
*
os
.
File
,
argDefs
[]
cmds
.
Argument
,
recursive
,
hidden
bool
,
root
*
cmds
.
Command
)
([]
string
,
[]
files
.
File
,
error
)
{
// ignore stdin on Windows
if
runtime
.
GOOS
==
"w
indows
"
{
if
osh
.
IsW
indows
()
{
stdin
=
nil
}
...
...
@@ -399,8 +400,20 @@ func getArgDef(i int, argDefs []cmds.Argument) *cmds.Argument {
const
notRecursiveFmtStr
=
"'%s' is a directory, use the '-%s' flag to specify directories"
const
dirNotSupportedFmtStr
=
"Invalid path '%s', argument '%s' does not support directories"
const
winDriveLetterFmtStr
=
"%q is a drive letter, not a drive path"
func
appendFile
(
fpath
string
,
argDef
*
cmds
.
Argument
,
recursive
,
hidden
bool
)
(
files
.
File
,
error
)
{
// resolve Windows relative dot paths like `X:.\somepath`
if
osh
.
IsWindows
()
{
if
len
(
fpath
)
>=
3
&&
fpath
[
1
:
3
]
==
":."
{
var
err
error
fpath
,
err
=
filepath
.
Abs
(
fpath
)
if
err
!=
nil
{
return
nil
,
err
}
}
}
if
fpath
==
"."
{
cwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
...
...
@@ -413,7 +426,7 @@ func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (fi
fpath
=
cwd
}
fpath
=
filepath
.
ToSlash
(
filepath
.
Clean
(
fpath
)
)
fpath
=
filepath
.
Clean
(
fpath
)
stat
,
err
:=
os
.
Lstat
(
fpath
)
if
err
!=
nil
{
...
...
@@ -429,6 +442,10 @@ func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (fi
}
}
if
osh
.
IsWindows
()
{
return
windowsParseFile
(
fpath
,
hidden
,
stat
)
}
return
files
.
NewSerialFile
(
path
.
Base
(
fpath
),
fpath
,
hidden
,
stat
)
}
...
...
@@ -481,3 +498,32 @@ func (r *messageReader) Read(b []byte) (int, error) {
func
(
r
*
messageReader
)
Close
()
error
{
return
r
.
r
.
Close
()
}
func
windowsParseFile
(
fpath
string
,
hidden
bool
,
stat
os
.
FileInfo
)
(
files
.
File
,
error
)
{
// special cases for Windows drive roots i.e. `X:\` and their long form `\\?\X:\`
// drive path must be preserved as `X:\` (or it's longform) and not converted to `X:`, `X:.`, `\`, or `/` here
switch
len
(
fpath
)
{
case
3
:
// `X:` is cleaned to `X:.` which may not be the expected behaviour by the user, they'll need to provide more specific input
if
fpath
[
1
:
3
]
==
":."
{
return
nil
,
fmt
.
Errorf
(
winDriveLetterFmtStr
,
fpath
[
:
2
])
}
// `X:\` needs to preserve the `\`, path.Base(filepath.ToSlash(fpath)) results in `X:` which is not valid
if
fpath
[
1
:
3
]
==
":
\\
"
{
return
files
.
NewSerialFile
(
fpath
,
fpath
,
hidden
,
stat
)
}
case
6
:
// `\\?\X:` long prefix form of `X:`, still ambiguous
if
fpath
[
:
4
]
==
"
\\\\
?
\\
"
&&
fpath
[
5
]
==
':'
{
return
nil
,
fmt
.
Errorf
(
winDriveLetterFmtStr
,
fpath
)
}
case
7
:
// `\\?\X:\` long prefix form is translated into short form `X:\`
if
fpath
[
:
4
]
==
"
\\\\
?
\\
"
&&
fpath
[
5
]
==
':'
&&
fpath
[
6
]
==
'\\'
{
fpath
=
string
(
fpath
[
4
])
+
":
\\
"
return
files
.
NewSerialFile
(
fpath
,
fpath
,
hidden
,
stat
)
}
}
return
files
.
NewSerialFile
(
path
.
Base
(
filepath
.
ToSlash
(
fpath
)),
fpath
,
hidden
,
stat
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment