Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9c7604fe
Commit
9c7604fe
authored
Apr 05, 2018
by
Di Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix incompatible file type checking on Windows
parent
a5c3c8d1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
50 deletions
+37
-50
mount.go
pkg/util/mount/mount.go
+35
-0
mount_linux.go
pkg/util/mount/mount_linux.go
+1
-25
mount_windows.go
pkg/util/mount/mount_windows.go
+1
-25
No files found.
pkg/util/mount/mount.go
View file @
9c7604fe
...
...
@@ -19,6 +19,7 @@ limitations under the License.
package
mount
import
(
"fmt"
"os"
"path/filepath"
"strings"
...
...
@@ -337,3 +338,37 @@ func startsWithBackstep(rel string) bool {
// normalize to / and check for ../
return
rel
==
".."
||
strings
.
HasPrefix
(
filepath
.
ToSlash
(
rel
),
"../"
)
}
// getFileType checks for file/directory/socket and block/character devices
func
getFileType
(
pathname
string
)
(
FileType
,
error
)
{
var
pathType
FileType
info
,
err
:=
os
.
Stat
(
pathname
)
if
os
.
IsNotExist
(
err
)
{
return
pathType
,
fmt
.
Errorf
(
"path %q does not exist"
,
pathname
)
}
// err in call to os.Stat
if
err
!=
nil
{
return
pathType
,
err
}
// checks whether the mode is the target mode
isSpecificMode
:=
func
(
mode
,
targetMode
os
.
FileMode
)
bool
{
return
mode
&
targetMode
==
targetMode
}
mode
:=
info
.
Mode
()
if
mode
.
IsDir
()
{
return
FileTypeDirectory
,
nil
}
else
if
mode
.
IsRegular
()
{
return
FileTypeFile
,
nil
}
else
if
isSpecificMode
(
mode
,
os
.
ModeSocket
)
{
return
FileTypeSocket
,
nil
}
else
if
isSpecificMode
(
mode
,
os
.
ModeDevice
)
{
if
isSpecificMode
(
mode
,
os
.
ModeCharDevice
)
{
return
FileTypeCharDev
,
nil
}
return
FileTypeBlockDev
,
nil
}
return
pathType
,
fmt
.
Errorf
(
"only recognise file, directory, socket, block device and character device"
)
}
pkg/util/mount/mount_linux.go
View file @
9c7604fe
...
...
@@ -423,31 +423,7 @@ func (mounter *Mounter) MakeRShared(path string) error {
}
func
(
mounter
*
Mounter
)
GetFileType
(
pathname
string
)
(
FileType
,
error
)
{
var
pathType
FileType
finfo
,
err
:=
os
.
Stat
(
pathname
)
if
os
.
IsNotExist
(
err
)
{
return
pathType
,
fmt
.
Errorf
(
"path %q does not exist"
,
pathname
)
}
// err in call to os.Stat
if
err
!=
nil
{
return
pathType
,
err
}
mode
:=
finfo
.
Sys
()
.
(
*
syscall
.
Stat_t
)
.
Mode
switch
mode
&
syscall
.
S_IFMT
{
case
syscall
.
S_IFSOCK
:
return
FileTypeSocket
,
nil
case
syscall
.
S_IFBLK
:
return
FileTypeBlockDev
,
nil
case
syscall
.
S_IFCHR
:
return
FileTypeCharDev
,
nil
case
syscall
.
S_IFDIR
:
return
FileTypeDirectory
,
nil
case
syscall
.
S_IFREG
:
return
FileTypeFile
,
nil
}
return
pathType
,
fmt
.
Errorf
(
"only recognise file, directory, socket, block device and character device"
)
return
getFileType
(
pathname
)
}
func
(
mounter
*
Mounter
)
MakeDir
(
pathname
string
)
error
{
...
...
pkg/util/mount/mount_windows.go
View file @
9c7604fe
...
...
@@ -201,31 +201,7 @@ func (mounter *Mounter) MakeRShared(path string) error {
// GetFileType checks for sockets/block/character devices
func
(
mounter
*
Mounter
)
GetFileType
(
pathname
string
)
(
FileType
,
error
)
{
var
pathType
FileType
info
,
err
:=
os
.
Stat
(
pathname
)
if
os
.
IsNotExist
(
err
)
{
return
pathType
,
fmt
.
Errorf
(
"path %q does not exist"
,
pathname
)
}
// err in call to os.Stat
if
err
!=
nil
{
return
pathType
,
err
}
mode
:=
info
.
Sys
()
.
(
*
syscall
.
Win32FileAttributeData
)
.
FileAttributes
switch
mode
&
syscall
.
S_IFMT
{
case
syscall
.
S_IFSOCK
:
return
FileTypeSocket
,
nil
case
syscall
.
S_IFBLK
:
return
FileTypeBlockDev
,
nil
case
syscall
.
S_IFCHR
:
return
FileTypeCharDev
,
nil
case
syscall
.
S_IFDIR
:
return
FileTypeDirectory
,
nil
case
syscall
.
S_IFREG
:
return
FileTypeFile
,
nil
}
return
pathType
,
fmt
.
Errorf
(
"only recognise file, directory, socket, block device and character device"
)
return
getFileType
(
pathname
)
}
// MakeFile creates a new directory
...
...
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