From c35518a865deb6fd6107e07f88b67c1363949a98 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 17 Sep 2017 11:05:30 +0200 Subject: [PATCH] Azure/GS: Remove ReadDir() --- internal/backend/azure/azure.go | 57 --------------------------------- internal/backend/gs/gs.go | 54 ------------------------------- 2 files changed, 111 deletions(-) diff --git a/internal/backend/azure/azure.go b/internal/backend/azure/azure.go index a59f1e1eb..b0aa3141f 100644 --- a/internal/backend/azure/azure.go +++ b/internal/backend/azure/azure.go @@ -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) diff --git a/internal/backend/gs/gs.go b/internal/backend/gs/gs.go index 3fc6cf1f7..743dd6d74 100644 --- a/internal/backend/gs/gs.go +++ b/internal/backend/gs/gs.go @@ -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)