Azure/GS: Remove ReadDir()
This commit is contained in:
parent
c784a15aaa
commit
c35518a865
2 changed files with 0 additions and 111 deletions
|
@ -7,7 +7,6 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/storage"
|
||||
"github.com/restic/restic/internal/backend"
|
||||
|
@ -96,62 +95,6 @@ func (be *Backend) Join(p ...string) string {
|
|||
return path.Join(p...)
|
||||
}
|
||||
|
||||
type fileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
modTime time.Time
|
||||
isDir bool
|
||||
}
|
||||
|
||||
func (fi fileInfo) Name() string { return fi.name } // base name of the file
|
||||
func (fi fileInfo) Size() int64 { return fi.size } // length in bytes for regular files; system-dependent for others
|
||||
func (fi fileInfo) Mode() os.FileMode { return fi.mode } // file mode bits
|
||||
func (fi fileInfo) ModTime() time.Time { return fi.modTime } // modification time
|
||||
func (fi fileInfo) IsDir() bool { return fi.isDir } // abbreviation for Mode().IsDir()
|
||||
func (fi fileInfo) Sys() interface{} { return nil } // underlying data source (can return nil)
|
||||
|
||||
// ReadDir returns the entries for a directory.
|
||||
func (be *Backend) ReadDir(dir string) (list []os.FileInfo, err error) {
|
||||
debug.Log("ReadDir(%v)", dir)
|
||||
|
||||
// make sure dir ends with a slash
|
||||
if dir[len(dir)-1] != '/' {
|
||||
dir += "/"
|
||||
}
|
||||
|
||||
obj, err := be.container.ListBlobs(storage.ListBlobsParameters{Prefix: dir, Delimiter: "/"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, item := range obj.BlobPrefixes {
|
||||
entry := fileInfo{
|
||||
name: strings.TrimPrefix(item, dir),
|
||||
isDir: true,
|
||||
mode: os.ModeDir | 0755,
|
||||
}
|
||||
if entry.name != "" {
|
||||
list = append(list, entry)
|
||||
}
|
||||
}
|
||||
|
||||
for _, item := range obj.Blobs {
|
||||
entry := fileInfo{
|
||||
name: strings.TrimPrefix(item.Name, dir),
|
||||
isDir: false,
|
||||
mode: 0644,
|
||||
size: item.Properties.ContentLength,
|
||||
modTime: time.Time(item.Properties.LastModified),
|
||||
}
|
||||
if entry.name != "" {
|
||||
list = append(list, entry)
|
||||
}
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Location returns this backend's location (the container name).
|
||||
func (be *Backend) Location() string {
|
||||
return be.Join(be.container.Name, be.prefix)
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/restic/restic/internal/backend"
|
||||
|
@ -134,59 +133,6 @@ func (be *Backend) Join(p ...string) string {
|
|||
return path.Join(p...)
|
||||
}
|
||||
|
||||
type fileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
modTime time.Time
|
||||
isDir bool
|
||||
}
|
||||
|
||||
func (fi fileInfo) Name() string { return fi.name } // base name of the file
|
||||
func (fi fileInfo) Size() int64 { return fi.size } // length in bytes for regular files; system-dependent for others
|
||||
func (fi fileInfo) Mode() os.FileMode { return fi.mode } // file mode bits
|
||||
func (fi fileInfo) ModTime() time.Time { return fi.modTime } // modification time
|
||||
func (fi fileInfo) IsDir() bool { return fi.isDir } // abbreviation for Mode().IsDir()
|
||||
func (fi fileInfo) Sys() interface{} { return nil } // underlying data source (can return nil)
|
||||
|
||||
// ReadDir returns the entries for a directory.
|
||||
func (be *Backend) ReadDir(dir string) (list []os.FileInfo, err error) {
|
||||
debug.Log("ReadDir(%v)", dir)
|
||||
|
||||
// make sure dir ends with a slash
|
||||
if dir[len(dir)-1] != '/' {
|
||||
dir += "/"
|
||||
}
|
||||
|
||||
obj, err := be.service.Objects.List(be.bucketName).Prefix(dir).Delimiter("/").Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, item := range obj.Prefixes {
|
||||
entry := fileInfo{
|
||||
name: strings.TrimPrefix(item, dir),
|
||||
isDir: true,
|
||||
mode: os.ModeDir | 0755,
|
||||
}
|
||||
list = append(list, entry)
|
||||
}
|
||||
for _, item := range obj.Items {
|
||||
entry := fileInfo{
|
||||
name: strings.TrimPrefix(item.Name, dir),
|
||||
isDir: false,
|
||||
mode: 0644,
|
||||
size: int64(item.Size),
|
||||
//modTime: item.Updated,
|
||||
}
|
||||
if entry.name != "" {
|
||||
list = append(list, entry)
|
||||
}
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Location returns this backend's location (the bucket name).
|
||||
func (be *Backend) Location() string {
|
||||
return be.Join(be.bucketName, be.prefix)
|
||||
|
|
Loading…
Reference in a new issue