aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/platform/file_system.cc
diff options
context:
space:
mode:
authorGravatar Jonathan Hseu <jhseu@google.com>2016-11-04 11:53:50 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-11-04 13:05:51 -0700
commit879e0accd1c833771c8058d3eb5f2d4f06f895d4 (patch)
tree81635e1bd758cd8a8e5ec760db70fc72f6480c66 /tensorflow/core/platform/file_system.cc
parenta2c8e99777cc0b961fb42106af5bd527a43e76f7 (diff)
Change FileExists to return tensorflow::Status.
Also done separately by @llhe at github.com/tensorflow/tensorflow/pull/5370. We needed to do this change internally to fix all callers. Motivation: The existing FileExists interface doesn't allow callers to distinguish between file not found vs. filesystem errors. Semantics changes: - gfile.Exists in Python now throws an exception for filesystem errors. It continues to return true/false if it can accurately determine whether a file exists. - RecursivelyCreateDir now returns errors for filesystem errors when calling FileExists. Change: 138224013
Diffstat (limited to 'tensorflow/core/platform/file_system.cc')
-rw-r--r--tensorflow/core/platform/file_system.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/tensorflow/core/platform/file_system.cc b/tensorflow/core/platform/file_system.cc
index 6f55880a1d..1692398b97 100644
--- a/tensorflow/core/platform/file_system.cc
+++ b/tensorflow/core/platform/file_system.cc
@@ -61,9 +61,7 @@ string FileSystem::TranslateName(const string& name) const {
Status FileSystem::IsDirectory(const string& name) {
// Check if path exists.
- if (!FileExists(name)) {
- return Status(tensorflow::error::NOT_FOUND, "Path not found");
- }
+ TF_RETURN_IF_ERROR(FileExists(name));
FileStatistics stat;
TF_RETURN_IF_ERROR(Stat(name, &stat));
if (stat.is_directory) {
@@ -143,9 +141,10 @@ Status FileSystem::DeleteRecursively(const string& dirname,
*undeleted_files = 0;
*undeleted_dirs = 0;
// Make sure that dirname exists;
- if (!FileExists(dirname)) {
+ Status exists_status = FileExists(dirname);
+ if (!exists_status.ok()) {
(*undeleted_dirs)++;
- return Status(error::NOT_FOUND, "Directory doesn't exist");
+ return exists_status;
}
std::deque<string> dir_q; // Queue for the BFS
std::vector<string> dir_list; // List of all dirs discovered
@@ -201,8 +200,14 @@ Status FileSystem::RecursivelyCreateDir(const string& dirname) {
StringPiece scheme, host, remaining_dir;
io::ParseURI(dirname, &scheme, &host, &remaining_dir);
std::vector<StringPiece> sub_dirs;
- while (!FileExists(io::CreateURI(scheme, host, remaining_dir)) &&
- !remaining_dir.empty()) {
+ while (!remaining_dir.empty()) {
+ Status status = FileExists(io::CreateURI(scheme, host, remaining_dir));
+ if (status.ok()) {
+ break;
+ }
+ if (status.code() != error::Code::NOT_FOUND) {
+ return status;
+ }
// Basename returns "" for / ending dirs.
if (!remaining_dir.ends_with("/")) {
sub_dirs.push_back(io::Basename(remaining_dir));