From 2d0c38e39455f7dc9ea70dd6432b28c443331b68 Mon Sep 17 00:00:00 2001 From: Zhuo Peng Date: Mon, 6 Feb 2023 15:59:57 -0800 Subject: [PATCH] fix (#1767) --- .../core/filesystems/http/http_filesystem.cc | 9 +++++++-- tests/test_http.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tensorflow_io/core/filesystems/http/http_filesystem.cc b/tensorflow_io/core/filesystems/http/http_filesystem.cc index 88a871804..26a652a15 100644 --- a/tensorflow_io/core/filesystems/http/http_filesystem.cc +++ b/tensorflow_io/core/filesystems/http/http_filesystem.cc @@ -782,8 +782,13 @@ static bool IsDirectory(const TF_Filesystem* filesystem, const char* path, return false; } - TF_SetStatus(status, TF_OK, ""); - return stats.is_directory; + if (stats.is_directory) { + TF_SetStatus(status, TF_OK, ""); + return true; + } + + TF_SetStatus(status, TF_FAILED_PRECONDITION, "not a directory"); + return false; } static int GetChildren(const TF_Filesystem* filesystem, const char* path, diff --git a/tests/test_http.py b/tests/test_http.py index 3443ede7f..67e4efcd4 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -106,5 +106,18 @@ def test_gfile_tell(local_content, remote_filename): assert remote_gfile.tell() == 100 +@pytest.mark.skipif( + sys.platform in ("darwin", "win32"), reason="macOS/Windows fails now" +) +def test_gfile_isdir(remote_filename): + """Test case for isdir()""" + + # A valid http link is not a dir. + assert not tf.io.gfile.isdir(remote_filename) + # An invalid http link is not a dir either. + assert not tf.io.gfile.isdir("https://not-a-valid-domain/tfio-test") + + + if __name__ == "__main__": tf.test.main()