From 4d1c59f8e959279cdb2984c5c3f6039c8644c208 Mon Sep 17 00:00:00 2001 From: Gunhan Gulsoy Date: Fri, 3 Jan 2020 03:46:54 -0800 Subject: [PATCH] Fix the IsDirectory method for windows filesystem for drive root. PiperOrigin-RevId: 287971081 Change-Id: Ie3dfefa58c4bd464b28302f444b77a5ce8837244 --- .../core/platform/windows/windows_file_system.cc | 11 ++++++++++- .../core/platform/windows/windows_file_system.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tensorflow/core/platform/windows/windows_file_system.cc b/tensorflow/core/platform/windows/windows_file_system.cc index d7a9ac56943..a75f10822d7 100644 --- a/tensorflow/core/platform/windows/windows_file_system.cc +++ b/tensorflow/core/platform/windows/windows_file_system.cc @@ -490,6 +490,15 @@ Status WindowsFileSystem::GetFileSize(const string& fname, uint64* size) { return result; } +Status WindowsFileSystem::IsDirectory(const string& fname) { + TF_RETURN_IF_ERROR(FileExists(fname)); + std::wstring ws_translated_fname = Utf8ToWideChar(TranslateName(fname)); + if (PathIsDirectoryW(ws_translated_fname.c_str())) { + return Status::OK(); + } + return Status(tensorflow::error::FAILED_PRECONDITION, "Not a directory"); +} + Status WindowsFileSystem::RenameFile(const string& src, const string& target) { Status result; // rename() is not capable of replacing the existing file as on Linux @@ -531,7 +540,7 @@ Status WindowsFileSystem::Stat(const string& fname, FileStatistics* stat) { } else { stat->mtime_nsec = sbuf.st_mtime * 1e9; stat->length = sbuf.st_size; - stat->is_directory = PathIsDirectoryW(ws_translated_fname.c_str()); + stat->is_directory = IsDirectory(fname).ok(); } return result; } diff --git a/tensorflow/core/platform/windows/windows_file_system.h b/tensorflow/core/platform/windows/windows_file_system.h index 2e0de725762..8c2b000fef9 100644 --- a/tensorflow/core/platform/windows/windows_file_system.h +++ b/tensorflow/core/platform/windows/windows_file_system.h @@ -62,6 +62,8 @@ class WindowsFileSystem : public FileSystem { Status GetFileSize(const string& fname, uint64* size) override; + Status IsDirectory(const string& fname) override; + Status RenameFile(const string& src, const string& target) override; string TranslateName(const string& name) const override { return name; }