Use std::filesystem in c10 tempfile and tempdir (#106656)

This PR simplifies c10::TempFile and c10::TempDir. It also deletes Windows temp files in c10::~TempFile, this behavior is absent on the current version.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/106656
Approved by: https://github.com/ezyang
This commit is contained in:
cyy
2023-09-03 13:03:10 +00:00
committed by PyTorch MergeBot
parent 1b3dc05c3e
commit 7b91f762b6
4 changed files with 92 additions and 76 deletions

View File

@ -5,6 +5,7 @@
#include <algorithm>
#include <cerrno>
#include <memory>
#include <optional>
#include <set>
#include <unordered_map>
#include <vector>
@ -83,7 +84,7 @@ int main(int argc, char* argv[]) {
setsid(); // Daemonize the process
std::unique_ptr<ManagerServerSocket> srv_socket;
c10::optional<c10::TempDir> tempdir;
std::optional<c10::TempDir> tempdir;
try {
tempdir = c10::try_make_tempdir(/*name_prefix=*/"torch-shm-dir-");
if (!tempdir.has_value()) {
@ -91,7 +92,7 @@ int main(int argc, char* argv[]) {
"could not generate a random directory for manager socket");
}
std::string tempfile = tempdir->name + "/manager.sock";
std::string tempfile = (tempdir->name / "manager.sock").string();
srv_socket = std::make_unique<ManagerServerSocket>(tempfile);
register_fd(srv_socket->socket_fd);