diff options
author | Jonathan Hseu <jhseu@google.com> | 2016-11-02 17:57:50 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-11-02 19:12:29 -0700 |
commit | 9113b25790bfc4e2da1876a78d74382f776bf02a (patch) | |
tree | f7cf347a24bb7db02c62c1813a172846e0450a4b /tensorflow/core/platform/file_system.cc | |
parent | 7117b4f5b0bbd1d27506ae59f8abfa132be20f42 (diff) |
Change path functions to operate on URIs rather than paths.
- Move the URI parsing and creation functions to path.h so that we don't
depend on core/platform from core/lib/io.
- Fixes https://github.com/tensorflow/tensorflow/issues/5316
Change: 138023841
Diffstat (limited to 'tensorflow/core/platform/file_system.cc')
-rw-r--r-- | tensorflow/core/platform/file_system.cc | 44 |
1 files changed, 3 insertions, 41 deletions
diff --git a/tensorflow/core/platform/file_system.cc b/tensorflow/core/platform/file_system.cc index d71ff80143..400835aa07 100644 --- a/tensorflow/core/platform/file_system.cc +++ b/tensorflow/core/platform/file_system.cc @@ -22,7 +22,6 @@ limitations under the License. #include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/lib/io/path.h" -#include "tensorflow/core/lib/strings/scanner.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/env.h" @@ -79,43 +78,6 @@ WritableFile::~WritableFile() {} FileSystemRegistry::~FileSystemRegistry() {} -void ParseURI(StringPiece remaining, StringPiece* scheme, StringPiece* host, - StringPiece* path) { - // 0. Parse scheme - // Make sure scheme matches [a-zA-Z][0-9a-zA-Z.]* - // TODO(keveman): Allow "+" and "-" in the scheme. - if (!strings::Scanner(remaining) - .One(strings::Scanner::LETTER) - .Many(strings::Scanner::LETTER_DIGIT_DOT) - .StopCapture() - .OneLiteral("://") - .GetResult(&remaining, scheme)) { - // If there's no scheme, assume the entire string is a path. - scheme->clear(); - host->clear(); - *path = remaining; - return; - } - - // 1. Parse host - if (!strings::Scanner(remaining).ScanUntil('/').GetResult(&remaining, host)) { - // No path, so the rest of the URI is the host. - *host = remaining; - path->clear(); - return; - } - - // 2. The rest is the path - *path = remaining; -} - -string CreateURI(StringPiece scheme, StringPiece host, StringPiece path) { - if (scheme.empty()) { - return path.ToString(); - } - return strings::StrCat(scheme, "://", host, path); -} - Status FileSystem::GetMatchingPaths(const string& pattern, std::vector<string>* results) { results->clear(); @@ -237,9 +199,9 @@ Status FileSystem::DeleteRecursively(const string& dirname, Status FileSystem::RecursivelyCreateDir(const string& dirname) { StringPiece scheme, host, remaining_dir; - ParseURI(dirname, &scheme, &host, &remaining_dir); + io::ParseURI(dirname, &scheme, &host, &remaining_dir); std::vector<StringPiece> sub_dirs; - while (!FileExists(CreateURI(scheme, host, remaining_dir)) && + while (!FileExists(io::CreateURI(scheme, host, remaining_dir)) && !remaining_dir.empty()) { // Basename returns "" for / ending dirs. if (!remaining_dir.ends_with("/")) { @@ -255,7 +217,7 @@ Status FileSystem::RecursivelyCreateDir(const string& dirname) { string built_path = remaining_dir.ToString(); for (const StringPiece sub_dir : sub_dirs) { built_path = io::JoinPath(built_path, sub_dir); - TF_RETURN_IF_ERROR(CreateDir(CreateURI(scheme, host, built_path))); + TF_RETURN_IF_ERROR(CreateDir(io::CreateURI(scheme, host, built_path))); } return Status::OK(); } |