Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
5af3c4e2
C
Cloudreve
项目概览
hexbee
/
Cloudreve
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cloudreve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5af3c4e2
编写于
5月 19, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix: directory renaming should not be limited by file extensions (#395)
上级
4c458df6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
2 deletion
+31
-2
.github/workflows/build.yml
.github/workflows/build.yml
+2
-0
pkg/filesystem/manage.go
pkg/filesystem/manage.go
+1
-1
pkg/filesystem/manage_test.go
pkg/filesystem/manage_test.go
+28
-1
未找到文件。
.github/workflows/build.yml
浏览文件 @
5af3c4e2
...
...
@@ -48,6 +48,8 @@ jobs:
with
:
clean
:
false
submodules
:
'
recursive'
-
run
:
|
git fetch --prune --unshallow --tags
-
name
:
Get dependencies and build
run
:
|
...
...
pkg/filesystem/manage.go
浏览文件 @
5af3c4e2
...
...
@@ -32,7 +32,7 @@ type Object struct {
// Rename 重命名对象
func
(
fs
*
FileSystem
)
Rename
(
ctx
context
.
Context
,
dir
,
file
[]
uint
,
new
string
)
(
err
error
)
{
// 验证新名字
if
!
fs
.
ValidateLegalName
(
ctx
,
new
)
||
!
fs
.
ValidateExtension
(
ctx
,
new
)
{
if
!
fs
.
ValidateLegalName
(
ctx
,
new
)
||
(
len
(
file
)
>
0
&&
!
fs
.
ValidateExtension
(
ctx
,
new
)
)
{
return
ErrIllegalObjectName
}
...
...
pkg/filesystem/manage_test.go
浏览文件 @
5af3c4e2
...
...
@@ -707,12 +707,39 @@ func TestFileSystem_Rename(t *testing.T) {
asserts
.
Equal
(
ErrPathNotExist
,
err
)
}
// 新名字不合法
// 新名字
是目录,
不合法
{
err
:=
fs
.
Rename
(
ctx
,
[]
uint
{
10
},
[]
uint
{},
"ne/w"
)
asserts
.
Error
(
err
)
asserts
.
Equal
(
ErrIllegalObjectName
,
err
)
}
// 新名字是文件,不合法
{
err
:=
fs
.
Rename
(
ctx
,
[]
uint
{},
[]
uint
{
10
},
"ne/w"
)
asserts
.
Error
(
err
)
asserts
.
Equal
(
ErrIllegalObjectName
,
err
)
}
// 新名字是文件,扩展名不合法
{
fs
.
User
.
Policy
.
OptionsSerialized
.
FileType
=
[]
string
{
"txt"
}
err
:=
fs
.
Rename
(
ctx
,
[]
uint
{},
[]
uint
{
10
},
"1.jpg"
)
asserts
.
Error
(
err
)
asserts
.
Equal
(
ErrIllegalObjectName
,
err
)
}
// 新名字是目录,不应该检测扩展名
{
fs
.
User
.
Policy
.
OptionsSerialized
.
FileType
=
[]
string
{
"txt"
}
mock
.
ExpectQuery
(
"SELECT(.+)folders(.+)"
)
.
WithArgs
(
10
,
1
)
.
WillReturnRows
(
sqlmock
.
NewRows
([]
string
{
"id"
,
"name"
}))
err
:=
fs
.
Rename
(
ctx
,
[]
uint
{
10
},
[]
uint
{},
"new"
)
asserts
.
NoError
(
mock
.
ExpectationsWereMet
())
asserts
.
Error
(
err
)
asserts
.
Equal
(
ErrPathNotExist
,
err
)
}
}
func
TestFileSystem_SaveTo
(
t
*
testing
.
T
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录