Use io::JoinPath to build paths and avoid `\` when constructing file names.
JoinPath is being made to deal with different OS path separators. Defaulting to
`/` doesn't work in all cases. As an example, on Windows, when a `\` is in a
path, `/` is no longer considered a path separator which is why we want to avoid
it in filenames.
PiperOrigin-RevId: 296086151
Change-Id: Ib2dfef55e9e779ff5138f960dc462fce8a14833b
diff --git a/tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc b/tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc
index f06734a..1b8ae84 100644
--- a/tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc
+++ b/tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc
@@ -43,7 +43,8 @@
// Remove illegal characters from `name`.
for (int i = 0; i < name.size(); ++i) {
char ch = name[i];
- if (ch == '/' || ch == '[' || ch == ']' || ch == '*' || ch == '?') {
+ if (ch == '/' || ch == '[' || ch == ']' || ch == '*' || ch == '?' ||
+ ch == '\\') {
name[i] = '_';
}
}
@@ -123,10 +124,7 @@
<< "' directory for dumping: " << status;
return Status(error::Code::UNAVAILABLE, "(unavailable)");
}
- *filepath = llvm::Twine(dir)
- .concat("/")
- .concat(MakeUniqueFilename(std::string(name)))
- .str();
+ *filepath = io::JoinPath(dir, MakeUniqueFilename(std::string(name)));
// Try to open the file and generate a raw_ostream.
std::unique_ptr<WritableFile> file;