Skip to content

Commit

Permalink
fix gluster apis
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD committed Jun 30, 2023
1 parent b3b7f00 commit f4732e9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
5 changes: 4 additions & 1 deletion pkg/object/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,11 @@ func readDirSorted(dirname string) ([]*mEntry, error) {
}
defer f.Close()
entries, err := f.ReadDir(-1)
mEntries := make([]*mEntry, len(entries))
if err != nil {
return nil, err
}

mEntries := make([]*mEntry, len(entries))
for i, e := range entries {
if e.IsDir() {
mEntries[i] = &mEntry{e, e.Name() + dirSuffix, nil, false}
Expand Down
38 changes: 28 additions & 10 deletions pkg/object/gluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sort"
"strconv"
"strings"
"time"

"github.com/juicedata/gogfapi/gfapi"
)
Expand Down Expand Up @@ -142,6 +143,9 @@ func (c *gluster) Put(key string, in io.Reader) error {

func (c *gluster) Delete(key string) error {
err := c.vol.Unlink(key)
if err != nil && strings.Contains(err.Error(), "is a directory") {
err = c.vol.Rmdir(key)
}
if os.IsNotExist(err) {
err = nil
}
Expand All @@ -157,25 +161,31 @@ func (d *gluster) readDirSorted(dirname string) ([]*mEntry, error) {
}
defer f.Close()
entries, err := f.Readdir(0)
mEntries := make([]*mEntry, len(entries))
if err != nil {
return nil, err
}

for i, e := range entries {
mEntries := make([]*mEntry, 0, len(entries))
for _, e := range entries {
name := e.Name()
if name == "." || name == ".." {
continue
}
if e.IsDir() {
mEntries[i] = &mEntry{nil, e.Name() + dirSuffix, e, false}
mEntries = append(mEntries, &mEntry{nil, name + dirSuffix, e, false})
} else if !e.Mode().IsRegular() {
// follow symlink
fi, err := os.Stat(filepath.Join(dirname, e.Name()))
fi, err := os.Stat(filepath.Join(dirname, name))
if err != nil {
mEntries[i] = &mEntry{nil, e.Name(), e, true}
mEntries = append(mEntries, &mEntry{nil, name, e, true})
continue
}
name := e.Name()
if fi.IsDir() {
name = e.Name() + dirSuffix
name += dirSuffix
}
mEntries[i] = &mEntry{nil, name, fi, true}
mEntries = append(mEntries, &mEntry{nil, name, fi, true})
} else {
mEntries[i] = &mEntry{nil, e.Name(), e, false}
mEntries = append(mEntries, &mEntry{nil, name, e, false})
}
}
sort.Slice(mEntries, func(i, j int) bool { return mEntries[i].Name() < mEntries[j].Name() })
Expand Down Expand Up @@ -203,7 +213,7 @@ func (d *gluster) List(prefix, marker, delimiter string, limit int64) ([]Object,
}
objs = append(objs, obj)
}
entries, err := readDirSorted(dir)
entries, err := d.readDirSorted(dir)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
Expand Down Expand Up @@ -233,10 +243,18 @@ func (d *gluster) List(prefix, marker, delimiter string, limit int64) ([]Object,
return objs, nil
}

func (d *gluster) Chtimes(path string, mtime time.Time) error {
return notSupported
}

func (d *gluster) Chmod(path string, mode os.FileMode) error {
return d.vol.Chmod(path, mode)
}

func (d *gluster) Chown(path string, owner, group string) error {
return notSupported
}

func newGluster(endpoint, ak, sk, token string) (ObjectStorage, error) {
if !strings.Contains(endpoint, "://") {
endpoint = fmt.Sprintf("gluster://%s", endpoint)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ func checkSum(src, dst object.ObjectStorage, key string, size int64) (bool, erro
return equal, err
}

var streamRead = map[string]struct{}{"file": {}, "hdfs": {}, "sftp": {}}
var streamWrite = map[string]struct{}{"file": {}, "hdfs": {}, "sftp": {}, "gs": {}, "wasb": {}, "ceph": {}, "swift": {}, "webdav": {}, "upyun": {}, "jfs": {}}
var streamRead = map[string]struct{}{"file": {}, "hdfs": {}, "sftp": {}, "gluster": {}}
var streamWrite = map[string]struct{}{"file": {}, "hdfs": {}, "sftp": {}, "gs": {}, "wasb": {}, "ceph": {}, "swift": {}, "webdav": {}, "upyun": {}, "jfs": {}, "gluster": {}}
var readInMem = map[string]struct{}{"mem": {}, "etcd": {}, "redis": {}, "tikv": {}, "mysql": {}, "postgres": {}, "sqlite3": {}}

func inMap(obj object.ObjectStorage, m map[string]struct{}) bool {
Expand Down

0 comments on commit f4732e9

Please sign in to comment.