Fix the IsDirectory method for windows filesystem for drive root.

PiperOrigin-RevId: 287971081
Change-Id: Ie3dfefa58c4bd464b28302f444b77a5ce8837244
This commit is contained in:
Gunhan Gulsoy 2020-01-03 03:46:54 -08:00 committed by TensorFlower Gardener
parent c042ddcbb1
commit 4d1c59f8e9
2 changed files with 12 additions and 1 deletions

View File

@ -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;
}

View File

@ -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; }