Skip to content

Commit

Permalink
fix: skip dirs with no permissions (#4121)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro authored Nov 1, 2023
1 parent 7f73821 commit c270084
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/scripts/setup-hdfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ echo "hello world" > /tmp/testfile
cd ~/app/hadoop-${HADOOP_VERSION}/bin
./hdfs dfs -put /tmp/testfile /
./hdfs dfs -rm /testfile
./hdfs dfs -chmod 777 /

echo "hdfs started successfully"
5 changes: 3 additions & 2 deletions .github/workflows/dockerfile-sftp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM debian:stretch-slim
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
FROM debian:stable-slim
RUN apt-get clean
RUN apt-get update

Expand All @@ -9,5 +8,7 @@ RUN mkdir /run/sshd
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
RUN echo "root:password"|chpasswd
RUN useradd -m testUser1
RUN echo "testUser1:password"|chpasswd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
4 changes: 2 additions & 2 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
GLUSTER_VOLUME: jfstest/gv0
DISPLAY_PROGRESSBAR: false
HDFS_ADDR: localhost:8020
SFTP_HOST: localhost:2222:/upload/
SFTP_USER: root
SFTP_HOST: localhost:2222:/home/testUser1/upload/
SFTP_USER: testUser1
SFTP_PASS: password
WEBDAV_TEST_BUCKET: 127.0.0.1:9007
TIKV_ADDR: 127.0.0.1
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ func (d *filestore) List(prefix, marker, delimiter string, limit int64, followLi
}
entries, err := readDirSorted(dir, followLink)
if err != nil {
if os.IsPermission(err) {
logger.Warnf("skip %s: %s", dir, err)
return nil, nil
}
if os.IsNotExist(err) {
return nil, nil
}
Expand Down
32 changes: 30 additions & 2 deletions pkg/object/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestHDFS2(t *testing.T) { //skip mutate
if os.Getenv("HDFS_ADDR") == "" {
t.Skip()
}
dfs, _ := newHDFS(os.Getenv("HDFS_ADDR"), "", "", "")
dfs, _ := newHDFS(os.Getenv("HDFS_ADDR"), "testUser1", "", "")
testFileSystem(t, dfs)
}

Expand All @@ -78,7 +78,7 @@ func testFileSystem(t *testing.T, s ObjectStorage) {
}
// initialize directory tree
for _, key := range keys {
if err := s.Put(key, bytes.NewReader([]byte{})); err != nil {
if err := s.Put(key, bytes.NewReader([]byte{'a', 'b'})); err != nil {
t.Fatalf("PUT object `%s` failed: %q", key, err)
}
}
Expand Down Expand Up @@ -125,6 +125,34 @@ func testFileSystem(t *testing.T, s ObjectStorage) {
t.Fatalf("testKeysEqual fail: %s", err)
}

if ss, ok := s.(FileSystem); ok {
for _, mode := range []uint32{0022, 0122, 0422} {
t.Logf("test mode %o", os.FileMode(mode))
err := ss.Chmod("x/", os.FileMode(mode))
if err != nil {
t.Fatalf("chmod %ofailed: %s", mode, err)
}

objs, err = listAll(s, "x", "", 100, true)
if err != nil {
t.Fatalf("list failed: %s mode %o", err, mode)
}
expectedKeys = []string{"x/", "xy.txt", "xyz/", "xyz/xyz.txt"}
if mode == 0422 {
if _, ok := ss.(*gluster); ok {
expectedKeys = []string{"x/", "x/x.txt", "xy.txt", "xyz/", "xyz/xyz.txt"}
}
}
if err = testKeysEqual(objs, expectedKeys); err != nil {
t.Fatalf("testKeysEqual fail: %s mode %o", err, mode)
}
err = ss.Chmod("x/", os.FileMode(0777))
if err != nil {
t.Fatalf("chmod %o failed: %s", mode, err)
}
}
}

objs, err = listAll(s, "xy", "", 100, true)
if err != nil {
t.Fatalf("list failed: %s", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/gluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ func (d *gluster) List(prefix, marker, delimiter string, limit int64, followLink
}
entries, err := d.readDirSorted(dir, followLink)
if err != nil {
if os.IsPermission(err) {
logger.Warnf("skip %s: %s", dir, err)
return nil, nil
}
if os.IsNotExist(err) {
return nil, nil
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/object/gluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ func TestGluster(t *testing.T) {
}
b, _ := newGluster(os.Getenv("GLUSTER_VOLUME"), "", "", "")
testStorage(t, b)

}

func TestGluster2(t *testing.T) {
if os.Getenv("GLUSTER_VOLUME") == "" {
t.SkipNow()
}
b, _ := newGluster(os.Getenv("GLUSTER_VOLUME"), "", "", "")
testFileSystem(t, b)
}
4 changes: 4 additions & 0 deletions pkg/object/hdfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ func (h *hdfsclient) List(prefix, marker, delimiter string, limit int64, followL
entries, err = file.Readdir(0)
}
if err != nil {
if os.IsPermission(err) {
logger.Warnf("skip %s: %s", dir, err)
return nil, nil
}
if os.IsNotExist(err) {
return nil, nil
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ func (n *nfsStore) List(prefix, marker, delimiter string, limit int64, followLin
}
entries, err := n.readDirSorted(dir, followLink)
if err != nil {
if os.IsPermission(err) {
logger.Warnf("skip %s: %s", dir, err)
return nil, nil
}
if os.IsNotExist(err) {
return nil, nil
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/object/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ func (f *sftpStore) List(prefix, marker, delimiter string, limit int64, followLi
}
infos, err := c.sftpClient.ReadDir(dir)
if err != nil {
if os.IsPermission(err) {
logger.Warnf("skip %s: %s", dir, err)
return nil, nil
}
if os.IsNotExist(err) {
return nil, nil
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/object/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ func (w *webdav) List(prefix, marker, delimiter string, limit int64, followLink

infos, err := w.c.ReadDir(root)
if err != nil {
if os.IsNotExist(err) {
if gowebdav.IsErrCode(err, http.StatusForbidden) {
logger.Warnf("skip %s: %s", root, err)
return nil, nil
}
if gowebdav.IsErrNotFound(err) {
return nil, nil
}
return nil, err
Expand Down

0 comments on commit c270084

Please sign in to comment.