Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
no-src
gofs
提交
c903adf2
G
gofs
项目概览
no-src
/
gofs
9 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gofs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
c903adf2
编写于
8月 08, 2023
作者:
M
mstmdev
提交者:
GitHub
8月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Symlink, Lstat and ReadLink function for the Driver interface (#229)
上级
d446cdf9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
3 deletion
+55
-3
driver/driver.go
driver/driver.go
+7
-1
driver/minio/minio.go
driver/minio/minio.go
+21
-0
driver/sftp/sftp.go
driver/sftp/sftp.go
+27
-2
未找到文件。
driver/driver.go
浏览文件 @
c903adf2
...
@@ -17,6 +17,8 @@ type Driver interface {
...
@@ -17,6 +17,8 @@ type Driver interface {
MkdirAll
(
path
string
)
error
MkdirAll
(
path
string
)
error
// Create creates the named file
// Create creates the named file
Create
(
path
string
)
(
err
error
)
Create
(
path
string
)
(
err
error
)
// Symlink create a symbolic link
Symlink
(
oldname
,
newname
string
)
error
// Remove removes the specified file or directory
// Remove removes the specified file or directory
Remove
(
path
string
)
error
Remove
(
path
string
)
error
// Rename renames a file
// Rename renames a file
...
@@ -27,10 +29,14 @@ type Driver interface {
...
@@ -27,10 +29,14 @@ type Driver interface {
WalkDir
(
root
string
,
fn
fs
.
WalkDirFunc
)
error
WalkDir
(
root
string
,
fn
fs
.
WalkDirFunc
)
error
// Open opens the named file for reading
// Open opens the named file for reading
Open
(
path
string
)
(
f
http
.
File
,
err
error
)
Open
(
path
string
)
(
f
http
.
File
,
err
error
)
// Stat returns the os.FileInfo describing the named file
// Stat returns the os.FileInfo describing the named file
, if path is a symbolic link, read the real file
Stat
(
path
string
)
(
fi
os
.
FileInfo
,
err
error
)
Stat
(
path
string
)
(
fi
os
.
FileInfo
,
err
error
)
// Lstat returns the os.FileInfo describing the named file, if path is a symbolic link, read the symbolic link info
Lstat
(
path
string
)
(
fi
os
.
FileInfo
,
err
error
)
// GetFileTime get the creation time, last access time, last modify time of the path
// GetFileTime get the creation time, last access time, last modify time of the path
GetFileTime
(
path
string
)
(
cTime
time
.
Time
,
aTime
time
.
Time
,
mTime
time
.
Time
,
err
error
)
GetFileTime
(
path
string
)
(
cTime
time
.
Time
,
aTime
time
.
Time
,
mTime
time
.
Time
,
err
error
)
// Write write src file to dest file
// Write write src file to dest file
Write
(
src
string
,
dest
string
)
error
Write
(
src
string
,
dest
string
)
error
// ReadLink returns the destination of the named symbolic link
ReadLink
(
path
string
)
(
string
,
error
)
}
}
driver/minio/minio.go
浏览文件 @
c903adf2
...
@@ -18,6 +18,7 @@ import (
...
@@ -18,6 +18,7 @@ import (
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/s3utils"
"github.com/minio/minio-go/v7/pkg/s3utils"
"github.com/no-src/gofs/driver"
"github.com/no-src/gofs/driver"
nsfs
"github.com/no-src/gofs/fs"
"github.com/no-src/gofs/internal/rate"
"github.com/no-src/gofs/internal/rate"
"github.com/no-src/gofs/retry"
"github.com/no-src/gofs/retry"
"github.com/no-src/log"
"github.com/no-src/log"
...
@@ -144,6 +145,18 @@ func (c *minIODriver) Create(path string) (err error) {
...
@@ -144,6 +145,18 @@ func (c *minIODriver) Create(path string) (err error) {
return
err
return
err
}
}
func
(
c
*
minIODriver
)
Symlink
(
oldname
,
newname
string
)
(
err
error
)
{
if
err
=
c
.
Remove
(
newname
);
err
!=
nil
{
return
err
}
err
=
c
.
reconnectIfLost
(
func
()
error
{
content
:=
nsfs
.
SymlinkText
(
oldname
)
_
,
err
=
c
.
client
.
PutObject
(
c
.
ctx
,
c
.
bucketName
,
newname
,
bytes
.
NewReader
([]
byte
(
content
)),
int64
(
len
(
content
)),
minio
.
PutObjectOptions
{})
return
err
})
return
err
}
func
(
c
*
minIODriver
)
Remove
(
path
string
)
(
err
error
)
{
func
(
c
*
minIODriver
)
Remove
(
path
string
)
(
err
error
)
{
return
c
.
reconnectIfLost
(
func
()
error
{
return
c
.
reconnectIfLost
(
func
()
error
{
infoChan
:=
c
.
client
.
ListObjects
(
c
.
ctx
,
c
.
bucketName
,
minio
.
ListObjectsOptions
{
infoChan
:=
c
.
client
.
ListObjects
(
c
.
ctx
,
c
.
bucketName
,
minio
.
ListObjectsOptions
{
...
@@ -250,6 +263,10 @@ func (c *minIODriver) Stat(path string) (fi os.FileInfo, err error) {
...
@@ -250,6 +263,10 @@ func (c *minIODriver) Stat(path string) (fi os.FileInfo, err error) {
return
fi
,
err
return
fi
,
err
}
}
func
(
c
*
minIODriver
)
Lstat
(
path
string
)
(
fi
os
.
FileInfo
,
err
error
)
{
return
c
.
Stat
(
path
)
}
func
(
c
*
minIODriver
)
GetFileTime
(
path
string
)
(
cTime
time
.
Time
,
aTime
time
.
Time
,
mTime
time
.
Time
,
err
error
)
{
func
(
c
*
minIODriver
)
GetFileTime
(
path
string
)
(
cTime
time
.
Time
,
aTime
time
.
Time
,
mTime
time
.
Time
,
err
error
)
{
err
=
c
.
reconnectIfLost
(
func
()
error
{
err
=
c
.
reconnectIfLost
(
func
()
error
{
var
info
minio
.
ObjectInfo
var
info
minio
.
ObjectInfo
...
@@ -288,6 +305,10 @@ func (c *minIODriver) Client() *minio.Client {
...
@@ -288,6 +305,10 @@ func (c *minIODriver) Client() *minio.Client {
return
c
.
client
return
c
.
client
}
}
func
(
c
*
minIODriver
)
ReadLink
(
path
string
)
(
string
,
error
)
{
return
path
,
nil
}
// fPutObject - Create an object in a bucket, with contents from file at filePath. Allows request cancellation.
// fPutObject - Create an object in a bucket, with contents from file at filePath. Allows request cancellation.
// Keep up to date with the minio.Client.FPutObject.
// Keep up to date with the minio.Client.FPutObject.
func
(
c
*
minIODriver
)
fPutObject
(
ctx
context
.
Context
,
bucketName
,
objectName
,
filePath
string
,
opts
minio
.
PutObjectOptions
)
(
info
minio
.
UploadInfo
,
err
error
)
{
func
(
c
*
minIODriver
)
fPutObject
(
ctx
context
.
Context
,
bucketName
,
objectName
,
filePath
string
,
opts
minio
.
PutObjectOptions
)
(
info
minio
.
UploadInfo
,
err
error
)
{
...
...
driver/sftp/sftp.go
浏览文件 @
c903adf2
...
@@ -172,9 +172,18 @@ func (sc *sftpDriver) Create(path string) (err error) {
...
@@ -172,9 +172,18 @@ func (sc *sftpDriver) Create(path string) (err error) {
return
err
return
err
}
}
func
(
sc
*
sftpDriver
)
Symlink
(
oldname
,
newname
string
)
error
{
if
err
:=
sc
.
Remove
(
newname
);
err
!=
nil
{
return
err
}
return
sc
.
reconnectIfLost
(
func
()
error
{
return
sc
.
client
.
Symlink
(
oldname
,
newname
)
})
}
func
(
sc
*
sftpDriver
)
Remove
(
path
string
)
error
{
func
(
sc
*
sftpDriver
)
Remove
(
path
string
)
error
{
return
sc
.
reconnectIfLost
(
func
()
error
{
return
sc
.
reconnectIfLost
(
func
()
error
{
f
,
err
:=
sc
.
client
.
S
tat
(
path
)
f
,
err
:=
sc
.
client
.
Ls
tat
(
path
)
if
os
.
IsNotExist
(
err
)
{
if
os
.
IsNotExist
(
err
)
{
return
nil
return
nil
}
}
...
@@ -260,10 +269,18 @@ func (sc *sftpDriver) Stat(path string) (fi os.FileInfo, err error) {
...
@@ -260,10 +269,18 @@ func (sc *sftpDriver) Stat(path string) (fi os.FileInfo, err error) {
return
fi
,
err
return
fi
,
err
}
}
func
(
sc
*
sftpDriver
)
Lstat
(
path
string
)
(
fi
os
.
FileInfo
,
err
error
)
{
err
=
sc
.
reconnectIfLost
(
func
()
error
{
fi
,
err
=
sc
.
client
.
Lstat
(
path
)
return
err
})
return
fi
,
err
}
func
(
sc
*
sftpDriver
)
GetFileTime
(
path
string
)
(
cTime
time
.
Time
,
aTime
time
.
Time
,
mTime
time
.
Time
,
err
error
)
{
func
(
sc
*
sftpDriver
)
GetFileTime
(
path
string
)
(
cTime
time
.
Time
,
aTime
time
.
Time
,
mTime
time
.
Time
,
err
error
)
{
err
=
sc
.
reconnectIfLost
(
func
()
error
{
err
=
sc
.
reconnectIfLost
(
func
()
error
{
var
fi
os
.
FileInfo
var
fi
os
.
FileInfo
fi
,
err
=
sc
.
client
.
S
tat
(
path
)
fi
,
err
=
sc
.
client
.
Ls
tat
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -315,6 +332,14 @@ func (sc *sftpDriver) Write(src string, dest string) (err error) {
...
@@ -315,6 +332,14 @@ func (sc *sftpDriver) Write(src string, dest string) (err error) {
return
err
return
err
}
}
func
(
sc
*
sftpDriver
)
ReadLink
(
path
string
)
(
realPath
string
,
err
error
)
{
err
=
sc
.
reconnectIfLost
(
func
()
error
{
realPath
,
err
=
sc
.
client
.
ReadLink
(
path
)
return
err
})
return
realPath
,
err
}
type
statDirEntry
struct
{
type
statDirEntry
struct
{
info
fs
.
FileInfo
info
fs
.
FileInfo
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录