diff --git a/tensorflow/contrib/session_bundle/session_bundle.cc b/tensorflow/contrib/session_bundle/session_bundle.cc index b9f86d5ddf9..f84359aa290 100644 --- a/tensorflow/contrib/session_bundle/session_bundle.cc +++ b/tensorflow/contrib/session_bundle/session_bundle.cc @@ -70,8 +70,8 @@ void AddAssetsTensorsToInputs(const StringPiece export_dir, return; } for (auto& asset : asset_files) { - Tensor assets_file_tensor = CreateStringTensor(io::JoinPath( - io::JoinPath(export_dir, kAssetsDirectory), asset.filename())); + Tensor assets_file_tensor = CreateStringTensor( + io::JoinPath(export_dir, kAssetsDirectory, asset.filename())); inputs->push_back( {asset.tensor_binding().tensor_name(), assets_file_tensor}); } diff --git a/tensorflow/core/lib/io/path.cc b/tensorflow/core/lib/io/path.cc index 348e003354e..107bd5e56a0 100644 --- a/tensorflow/core/lib/io/path.cc +++ b/tensorflow/core/lib/io/path.cc @@ -18,11 +18,11 @@ limitations under the License. namespace tensorflow { namespace io { +namespace internal { -string JoinPath(StringPiece part1, StringPiece part2) { +string JoinPathImpl(std::initializer_list paths) { string result; - StringPiece paths[2] = {part1, part2}; for (StringPiece path : paths) { if (path.empty()) continue; @@ -49,8 +49,6 @@ string JoinPath(StringPiece part1, StringPiece part2) { return result; } -namespace internal { - // Return the parts of the path, split on the final "/". If there is no // "/" in the path, the first part of the output is empty and the second // is the input. If the only "/" in the path is the first character, it is diff --git a/tensorflow/core/lib/io/path.h b/tensorflow/core/lib/io/path.h index 4cd62bff332..347f9d7e961 100644 --- a/tensorflow/core/lib/io/path.h +++ b/tensorflow/core/lib/io/path.h @@ -22,9 +22,13 @@ limitations under the License. namespace tensorflow { class StringPiece; namespace io { +namespace internal { +string JoinPathImpl(std::initializer_list paths); +} // Utility routines for processing filenames +#ifndef SWIG // variadic templates // Join multiple paths together, without introducing unnecessary path // separators. // For example: @@ -38,7 +42,12 @@ namespace io { // Usage: // string path = io::JoinPath("/mydir", filename); // string path = io::JoinPath(FLAGS_test_srcdir, filename); -string JoinPath(StringPiece part1, StringPiece part2); +// string path = io::JoinPath("/full", "path", "to", "filename); +template +string JoinPath(const T&... args) { + return internal::JoinPathImpl({args...}); +} +#endif /* SWIG */ // Return true if path is absolute. bool IsAbsolutePath(StringPiece path); diff --git a/tensorflow/core/lib/io/path_test.cc b/tensorflow/core/lib/io/path_test.cc index 688fc3b04f8..7ebcc216be4 100644 --- a/tensorflow/core/lib/io/path_test.cc +++ b/tensorflow/core/lib/io/path_test.cc @@ -31,6 +31,7 @@ TEST(PathTest, JoinPath) { EXPECT_EQ("/foo/bar/baz/blah/blink/biz", JoinPath("/foo/bar/baz/", "/blah/blink/biz")); + EXPECT_EQ("/foo/bar/baz/blah", JoinPath("/foo", "bar", "baz", "blah")); } TEST(PathTest, IsAbsolutePath) {