Skip to content

Commit e28406f

Browse files
ZRHannj2rong4cnCopilot
authored
feat(webdav): implement Getter interface (#2421)
* feat(webdav): implement Getter interface * fix(webdav): update Get method to use correct path handling Co-authored-by: Copilot <copilot@github.com> * fix(s3): correct path handling in Get method for object retrieval --------- Co-authored-by: j2rong4cn <j2rong@qq.com> Co-authored-by: Copilot <copilot@github.com>
1 parent 9033b55 commit e28406f

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

drivers/s3/driver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ func (d *S3) GetDirectUploadInfo(ctx context.Context, _ string, dstDir model.Obj
249249
// implements driver.Getter interface
250250
func (d *S3) Get(ctx context.Context, path string) (model.Obj, error) {
251251
// try to get object as a file using HeadObject
252-
key := getKey(stdpath.Join(d.GetRootPath(), path), false)
252+
path = stdpath.Join(d.GetRootPath(), path)
253+
key := getKey(path, false)
253254
headInput := &s3.HeadObjectInput{
254255
Bucket: &d.Bucket,
255256
Key: &key,
@@ -303,7 +304,7 @@ func (d *S3) Get(ctx context.Context, path string) (model.Obj, error) {
303304
return nil, fmt.Errorf("unsupported ListObjectVersion: %s", d.ListObjectVersion)
304305
}
305306
if len(contents) > 0 || len(commonPrefixes) > 0 {
306-
dirName := stdpath.Base(path + "/")
307+
dirName := stdpath.Base(path)
307308
return &model.Object{
308309
Name: dirName,
309310
Modified: d.Modified,

drivers/webdav/driver.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,22 @@ func (d *WebDav) Put(ctx context.Context, dstDir model.Obj, s model.FileStreamer
125125
return err
126126
}
127127

128+
// implements driver.Getter interface
129+
func (d *WebDav) Get(ctx context.Context, _path string) (model.Obj, error) {
130+
_path = path.Join(d.GetRootPath(), _path)
131+
info, err := d.client.Stat(_path)
132+
if err != nil {
133+
return nil, err
134+
}
135+
136+
return &model.Object{
137+
Name: info.Name(),
138+
Size: info.Size(),
139+
Modified: info.ModTime(),
140+
IsFolder: info.IsDir(),
141+
Path: _path,
142+
}, nil
143+
}
144+
128145
var _ driver.Driver = (*WebDav)(nil)
146+
var _ driver.Getter = (*WebDav)(nil)

0 commit comments

Comments
 (0)