Browse Source

Different temp dir impls per platform

default_compile_flags
vector-of-bool 5 years ago
parent
commit
a1fe8db5f6
3 changed files with 38 additions and 8 deletions
  1. +6
    -1
      src/dds/temp.hpp
  2. +2
    -7
      src/dds/temp.nix.cpp
  3. +30
    -0
      src/dds/temp.win.cpp

+ 6
- 1
src/dds/temp.hpp View File



impl(const impl&) = delete; impl(const impl&) = delete;


~impl();
~impl() {
std::error_code ec;
if (fs::exists(path, ec)) {
fs::remove_all(path, ec);
}
}
}; };


std::shared_ptr<impl> _ptr; std::shared_ptr<impl> _ptr;

src/dds/temp.cpp → src/dds/temp.nix.cpp View File

#ifndef _WIN32
#include "./temp.hpp" #include "./temp.hpp"


using namespace dds; using namespace dds;
auto path = fs::path(tempdir_path); auto path = fs::path(tempdir_path);
return std::make_shared<impl>(std::move(path)); return std::make_shared<impl>(std::move(path));
} }

temporary_dir::impl::~impl() {
std::error_code ec;
if (fs::exists(path, ec)) {
fs::remove_all(path, ec);
}
}
#endif

+ 30
- 0
src/dds/temp.win.cpp View File

#ifdef _WIN32
#include "./temp.hpp"

#include <memory>

#include <rpc.h>

#include <cassert>

using namespace dds;

temporary_dir temporary_dir::create() {
auto base = fs::temp_directory_path();

::UUID uuid;
auto status = ::UuidCreate(&uuid);
assert(status == RPC_S_OK || status == RPC_S_UUID_LOCAL_ONLY
|| status == RPC_S_UUID_NO_ADDRESS);

RPC_CSTR uuid_str;
::UuidToStringA(&uuid, &uuid_str);
std::string uuid_std_str(reinterpret_cast<const char*>(uuid_str));
::RpcStringFree(&uuid_str);

auto new_dir = base / uuid_std_str;
std::error_code ec;
fs::create_directory(new_dir);
return std::make_shared<impl>(std::move(new_dir));
}
#endif

Loading…
Cancel
Save