Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
koko
Commits
2c841304
Commit
2c841304
authored
Jun 10, 2019
by
Eric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] rename variable
parent
9c9262dc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
155 additions
and
155 deletions
+155
-155
sftpvolume.go
pkg/httpd/sftpvolume.go
+155
-155
No files found.
pkg/httpd/sftpvolume.go
View file @
2c841304
...
...
@@ -86,48 +86,48 @@ func (u *UserVolume) Info(path string) (elfinder.FileDir, error) {
return
u
.
RootFileDir
(),
nil
}
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
path
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
if
host
Dir
.
hostPath
==
path
{
return
host
Dir
.
info
(),
nil
if
host
Vol
.
hostPath
==
path
{
return
host
Vol
.
info
(),
nil
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
if
path
==
sysUser
Dir
.
suPath
{
return
sysUser
Dir
.
info
(),
nil
if
path
==
sysUser
Vol
.
suPath
{
return
sysUser
Vol
.
info
(),
nil
}
realPath
:=
sysUser
Dir
.
ParsePath
(
path
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
realPath
:=
sysUser
Vol
.
ParsePath
(
path
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
dirname
:=
filepath
.
Dir
(
path
)
fileInfos
,
err
:=
sysUser
Dir
.
client
.
Stat
(
realPath
)
fileInfos
,
err
:=
sysUser
Vol
.
client
.
Stat
(
realPath
)
if
err
!=
nil
{
return
rest
,
err
}
...
...
@@ -160,46 +160,46 @@ func (u *UserVolume) List(path string) []elfinder.FileDir {
return
dirs
}
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
path
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
dirs
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
if
host
Dir
.
hostPath
==
path
{
dirs
=
make
([]
elfinder
.
FileDir
,
0
,
len
(
host
Dir
.
suMaps
))
for
_
,
item
:=
range
host
Dir
.
suMaps
{
if
host
Vol
.
hostPath
==
path
{
dirs
=
make
([]
elfinder
.
FileDir
,
0
,
len
(
host
Vol
.
suMaps
))
for
_
,
item
:=
range
host
Vol
.
suMaps
{
dirs
=
append
(
dirs
,
item
.
info
())
}
return
dirs
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
dirs
}
realPath
:=
sysUser
Dir
.
ParsePath
(
path
)
realPath
:=
sysUser
Vol
.
ParsePath
(
path
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
dirs
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
subFiles
,
err
:=
sysUser
Dir
.
client
.
ReadDir
(
realPath
)
subFiles
,
err
:=
sysUser
Vol
.
client
.
ReadDir
(
realPath
)
if
err
!=
nil
{
return
dirs
}
...
...
@@ -238,38 +238,38 @@ func (u *UserVolume) Parents(path string, dep int) []elfinder.FileDir {
func
(
u
*
UserVolume
)
GetFile
(
path
string
)
(
reader
io
.
ReadCloser
,
err
error
)
{
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
path
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
nil
,
os
.
ErrNotExist
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
nil
,
os
.
ErrNotExist
}
realPath
:=
sysUser
Dir
.
ParsePath
(
path
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
realPath
:=
sysUser
Vol
.
ParsePath
(
path
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
nil
,
os
.
ErrPermission
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
return
sysUser
Dir
.
client
.
Open
(
realPath
)
return
sysUser
Vol
.
client
.
Open
(
realPath
)
}
func
(
u
*
UserVolume
)
UploadFile
(
dir
,
filename
string
,
reader
io
.
Reader
)
(
elfinder
.
FileDir
,
error
)
{
...
...
@@ -282,44 +282,44 @@ func (u *UserVolume) UploadFile(dir, filename string, reader io.Reader) (elfinde
return
rest
,
os
.
ErrPermission
}
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
dir
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
if
host
Dir
.
hostPath
==
dir
{
if
host
Vol
.
hostPath
==
dir
{
return
rest
,
os
.
ErrPermission
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
realPath
:=
sysUser
Dir
.
ParsePath
(
dir
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
realPath
:=
sysUser
Vol
.
ParsePath
(
dir
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
realFilenamePath
:=
filepath
.
Join
(
realPath
,
filename
)
fd
,
err
:=
sysUser
Dir
.
client
.
Create
(
realFilenamePath
)
fd
,
err
:=
sysUser
Vol
.
client
.
Create
(
realFilenamePath
)
if
err
!=
nil
{
return
rest
,
err
}
...
...
@@ -358,43 +358,43 @@ func (u *UserVolume) MergeChunk(cid, total int, dirPath, filename string) (elfin
return
rest
,
os
.
ErrPermission
}
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
dirPath
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
if
host
Dir
.
hostPath
==
dirPath
{
if
host
Vol
.
hostPath
==
dirPath
{
return
rest
,
os
.
ErrPermission
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
realDirPath
:=
sysUser
Dir
.
ParsePath
(
dirPath
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
realDirPath
:=
sysUser
Vol
.
ParsePath
(
dirPath
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
filenamePath
:=
filepath
.
Join
(
realDirPath
,
filename
)
fd
,
err
:=
sysUser
Dir
.
client
.
OpenFile
(
filenamePath
,
os
.
O_WRONLY
|
os
.
O_APPEND
|
os
.
O_CREATE
|
os
.
O_TRUNC
)
fd
,
err
:=
sysUser
Vol
.
client
.
OpenFile
(
filenamePath
,
os
.
O_WRONLY
|
os
.
O_APPEND
|
os
.
O_CREATE
|
os
.
O_TRUNC
)
if
err
!=
nil
{
return
rest
,
err
}
...
...
@@ -441,41 +441,41 @@ func (u *UserVolume) MakeDir(dir, newDirname string) (elfinder.FileDir, error) {
return
rest
,
os
.
ErrPermission
}
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
dir
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
if
host
Dir
.
hostPath
==
dir
{
if
host
Vol
.
hostPath
==
dir
{
return
rest
,
os
.
ErrPermission
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
realPath
:=
sysUser
Dir
.
ParsePath
(
dir
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
realPath
:=
sysUser
Vol
.
ParsePath
(
dir
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
realDirPath
:=
filepath
.
Join
(
realPath
,
newDirname
)
err
:=
sysUser
Dir
.
client
.
MkdirAll
(
realDirPath
)
err
:=
sysUser
Vol
.
client
.
MkdirAll
(
realDirPath
)
if
err
!=
nil
{
return
rest
,
err
}
...
...
@@ -491,42 +491,42 @@ func (u *UserVolume) MakeFile(dir, newFilename string) (elfinder.FileDir, error)
return
rest
,
os
.
ErrPermission
}
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
dir
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
if
host
Dir
.
hostPath
==
dir
{
if
host
Vol
.
hostPath
==
dir
{
return
rest
,
os
.
ErrPermission
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
realPath
:=
sysUser
Dir
.
ParsePath
(
dir
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
realPath
:=
sysUser
Vol
.
ParsePath
(
dir
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
realFilePath
:=
filepath
.
Join
(
realPath
,
newFilename
)
_
,
err
:=
sysUser
Dir
.
client
.
Create
(
realFilePath
)
_
,
err
:=
sysUser
Vol
.
client
.
Create
(
realFilePath
)
if
err
!=
nil
{
return
rest
,
err
}
...
...
@@ -537,45 +537,45 @@ func (u *UserVolume) MakeFile(dir, newFilename string) (elfinder.FileDir, error)
func
(
u
*
UserVolume
)
Rename
(
oldNamePath
,
newname
string
)
(
elfinder
.
FileDir
,
error
)
{
var
rest
elfinder
.
FileDir
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
oldNamePath
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
if
sysUser
Dir
.
suPath
==
oldNamePath
{
if
sysUser
Vol
.
suPath
==
oldNamePath
{
return
rest
,
os
.
ErrPermission
}
realPath
:=
sysUser
Dir
.
ParsePath
(
oldNamePath
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
realPath
:=
sysUser
Vol
.
ParsePath
(
oldNamePath
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
dirpath
:=
filepath
.
Dir
(
realPath
)
newFilePath
:=
filepath
.
Join
(
dirpath
,
newname
)
err
:=
sysUser
Dir
.
client
.
Rename
(
oldNamePath
,
newFilePath
)
err
:=
sysUser
Vol
.
client
.
Rename
(
oldNamePath
,
newFilePath
)
if
err
!=
nil
{
return
rest
,
err
}
...
...
@@ -590,41 +590,41 @@ func (u *UserVolume) Remove(path string) error {
return
os
.
ErrPermission
}
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
path
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
os
.
ErrNotExist
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
os
.
ErrNotExist
}
if
sysUser
Dir
.
suPath
==
path
{
if
sysUser
Vol
.
suPath
==
path
{
return
os
.
ErrPermission
}
realPath
:=
sysUser
Dir
.
ParsePath
(
path
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
realPath
:=
sysUser
Vol
.
ParsePath
(
path
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
os
.
ErrPermission
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
return
sysUser
Dir
.
client
.
Remove
(
realPath
)
return
sysUser
Vol
.
client
.
Remove
(
realPath
)
}
func
(
u
*
UserVolume
)
Paste
(
dir
,
filename
,
suffix
string
,
reader
io
.
ReadCloser
)
(
elfinder
.
FileDir
,
error
)
{
...
...
@@ -636,46 +636,46 @@ func (u *UserVolume) Paste(dir, filename, suffix string, reader io.ReadCloser) (
return
rest
,
os
.
ErrPermission
}
pathNames
:=
strings
.
Split
(
strings
.
TrimPrefix
(
dir
,
"/"
),
"/"
)
host
Dir
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
host
Vol
,
ok
:=
u
.
hosts
[
pathNames
[
1
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
if
host
Dir
.
hostPath
==
dir
{
if
host
Vol
.
hostPath
==
dir
{
return
rest
,
os
.
ErrPermission
}
if
host
Dir
.
suMaps
==
nil
{
host
Dir
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Dir
.
asset
.
SystemUsers
if
host
Vol
.
suMaps
==
nil
{
host
Vol
.
suMaps
=
make
(
map
[
string
]
*
sysUserVolume
)
systemUsers
:=
host
Vol
.
asset
.
SystemUsers
for
i
,
sysUser
:=
range
systemUsers
{
host
Dir
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
host
Vol
.
suMaps
[
sysUser
.
Name
]
=
&
sysUserVolume
{
VID
:
u
.
ID
(),
hostpath
:
host
Dir
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Dir
.
hostPath
,
sysUser
.
Name
),
hostpath
:
host
Vol
.
hostPath
,
suPath
:
filepath
.
Join
(
host
Vol
.
hostPath
,
sysUser
.
Name
),
systemUser
:
&
systemUsers
[
i
],
rootPath
:
u
.
rootPath
,
}
}
}
sysUser
Dir
,
ok
:=
hostDir
.
suMaps
[
pathNames
[
2
]]
sysUser
Vol
,
ok
:=
hostVol
.
suMaps
[
pathNames
[
2
]]
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
realPath
:=
sysUser
Dir
.
ParsePath
(
dir
)
if
sysUser
Dir
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Dir
.
asset
,
sysUserDir
.
systemUser
)
realPath
:=
sysUser
Vol
.
ParsePath
(
dir
)
if
sysUser
Vol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
host
Vol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUser
Dir
.
client
=
sftClient
sysUser
Dir
.
conn
=
conn
sysUser
Vol
.
client
=
sftClient
sysUser
Vol
.
conn
=
conn
}
realFilePath
:=
filepath
.
Join
(
realPath
,
filename
)
_
,
err
:=
sysUser
Dir
.
client
.
Stat
(
realFilePath
)
_
,
err
:=
sysUser
Vol
.
client
.
Stat
(
realFilePath
)
if
err
==
nil
{
realPath
+=
suffix
}
fd
,
err
:=
sysUser
Dir
.
client
.
OpenFile
(
realPath
,
os
.
O_RDWR
|
os
.
O_CREATE
)
fd
,
err
:=
sysUser
Vol
.
client
.
OpenFile
(
realPath
,
os
.
O_RDWR
|
os
.
O_CREATE
)
if
err
!=
nil
{
return
rest
,
err
}
...
...
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