Sfoglia il codice sorgente

Different temp dir impls per platform

default_compile_flags
vector-of-bool 5 anni fa
parent
commit
a1fe8db5f6
3 ha cambiato i file con 38 aggiunte e 8 eliminazioni
  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 Vedi File

@@ -14,7 +14,12 @@ class temporary_dir {

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;

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

@@ -1,3 +1,4 @@
#ifndef _WIN32
#include "./temp.hpp"

using namespace dds;
@@ -15,10 +16,4 @@ temporary_dir temporary_dir::create() {
auto path = fs::path(tempdir_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 Vedi File

@@ -0,0 +1,30 @@
#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…
Annulla
Salva