aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yong Tang <yong.tang.github@outlook.com>2018-03-13 22:13:38 -0700
committerGravatar Frank Chen <frankchn@gmail.com>2018-03-13 22:13:38 -0700
commit10be1f2377bf7aad1a4cfa306277c53e44493a57 (patch)
tree883318b19fc14e0af473713bc833b31be114dc80
parentdacedd7f028134e61e57cb836060ef712b274209 (diff)
Fix issue of tf.gfile.Exists with Unicode on Windows (#17697)
* Fix issue of tf.gfile.Exists with Unicode on Windows This fix tries to address the issue raised in 17695 where tf.gfile.Exists with Unicode on Windows does not work as expected. The issuse comes from the usage of `_access` (vs. _waccess). This fix adds a test and fixes the issue. This fix fixes 17695. Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Replace _access with _waccess on Windows. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
-rw-r--r--tensorflow/core/platform/windows/windows_file_system.cc3
-rw-r--r--tensorflow/python/lib/io/file_io_test.py5
2 files changed, 7 insertions, 1 deletions
diff --git a/tensorflow/core/platform/windows/windows_file_system.cc b/tensorflow/core/platform/windows/windows_file_system.cc
index b6b3722caa..682e46e0fc 100644
--- a/tensorflow/core/platform/windows/windows_file_system.cc
+++ b/tensorflow/core/platform/windows/windows_file_system.cc
@@ -382,7 +382,8 @@ Status WindowsFileSystem::NewReadOnlyMemoryRegionFromFile(
Status WindowsFileSystem::FileExists(const string& fname) {
constexpr int kOk = 0;
- if (_access(TranslateName(fname).c_str(), kOk) == 0) {
+ std::wstring ws_translated_fname = Utf8ToWideChar(TranslateName(fname));
+ if (_waccess(ws_translated_fname.c_str(), kOk) == 0) {
return Status::OK();
}
return errors::NotFound(fname, " not found");
diff --git a/tensorflow/python/lib/io/file_io_test.py b/tensorflow/python/lib/io/file_io_test.py
index a751607aaa..223858edfa 100644
--- a/tensorflow/python/lib/io/file_io_test.py
+++ b/tensorflow/python/lib/io/file_io_test.py
@@ -485,6 +485,11 @@ class FileIoTest(test.TestCase):
f.flush()
self.assertEqual(content, f.read(len(content) + 1))
+ def testUTF8StringPathExists(self):
+ file_path = os.path.join(self._base_dir, "UTF8测试_file_exist")
+ file_io.write_string_to_file(file_path, "testing")
+ v = file_io.file_exists(file_path)
+ self.assertEqual(v, True)
if __name__ == "__main__":
test.main()