Skip to content

Commit

Permalink
Generated export autocommit from mamba.ru
Browse files Browse the repository at this point in the history
  • Loading branch information
GitLab Runner committed Feb 15, 2024
1 parent b41cd1e commit 0ddc2a7
Show file tree
Hide file tree
Showing 63 changed files with 5,979 additions and 35 deletions.
48 changes: 24 additions & 24 deletions package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ SET(
prefixdb_source_list
prefixdb_package.cpp
prefixdb/prefixdb_module.cpp
prefixdb/prefixdb/prefixdb.cpp
prefixdb/prefixdb/multidb/multidb.cpp
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb_factory.cpp
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb.cpp
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb_restore.cpp
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb_slave.cpp
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb_initial.cpp
prefixdb/prefixdb/multidb/wrocksdb/since_reader.cpp
prefixdb/prefixdb/multidb/wrocksdb/merge/merge_operator.cpp
prefixdb/prefixdb/multidb/god.cpp
prefixdb/prefixdb/multidb/aux/scan_dir.cpp
prefixdb/prefixdb/multidb/aux/copy_dir.cpp
prefixdb/prefixdb/prefixdb_multiton.cpp
prefixdb/domain/prefixdb_domain.cpp
prefixdb/domain/multidb/multidb.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb_factory.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb_restore.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb_slave.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb_initial.cpp
prefixdb/domain/multidb/wrocksdb/since_reader.cpp
prefixdb/domain/multidb/wrocksdb/merge/merge_operator.cpp
prefixdb/domain/multidb/god.cpp
prefixdb/domain/multidb/aux/scan_dir.cpp
prefixdb/domain/multidb/aux/copy_dir.cpp
prefixdb/domain/prefixdb_multiton.cpp
prefixdb/service/prefixdb_service_multiton.cpp
prefixdb/service/prefixdb_cmd.cpp
prefixdb/gateway/prefixdb_gateway_multiton.cpp
Expand All @@ -31,33 +31,33 @@ enable_stat(wfc_prefixdb)

# отключение предупреждений rocksdb параноидального режима
set_source_files_properties(
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb_factory.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb_factory.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-sign-conversion -Wno-switch-default -Wno-unused-const-variable"
)


set_source_files_properties(
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb.cpp
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb_restore.cpp
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb_slave.cpp
prefixdb/prefixdb/multidb/wrocksdb/wrocksdb_initial.cpp
prefixdb/prefixdb/multidb/wrocksdb/since_reader.cpp
prefixdb/prefixdb/multidb/multidb.cpp
prefixdb/prefixdb/multidb/god.cpp
prefixdb/prefixdb/prefixdb.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb_restore.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb_slave.cpp
prefixdb/domain/multidb/wrocksdb/wrocksdb_initial.cpp
prefixdb/domain/multidb/wrocksdb/since_reader.cpp
prefixdb/domain/multidb/multidb.cpp
prefixdb/domain/multidb/god.cpp
prefixdb/domain/prefixdb.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-sign-conversion -Wno-unused-const-variable"
)

set_source_files_properties(
prefixdb/prefixdb/multidb/wrocksdb/merge/merge_operator.cpp
prefixdb/domain/multidb/wrocksdb/merge/merge_operator.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-strict-overflow"
)

target_include_directories(wfc_prefixdb PUBLIC "$<BUILD_INTERFACE:${wfc_prefixdb_SOURCE_DIR}>")
target_include_directories(wfc_prefixdb PRIVATE "$<BUILD_INTERFACE:${wfc_prefixdb_SOURCE_DIR}/package>")
target_include_directories(wfc_prefixdb PUBLIC "$<BUILD_INTERFACE:${wfc_prefixdb_SOURCE_DIR}/package>")

find_library(LIBRT rt)
set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down
34 changes: 34 additions & 0 deletions package/prefixdb/domain/multidb/aux/base64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/insert_linebreaks.hpp>
#include <boost/archive/iterators/remove_whitespace.hpp>

#include <vector>
#include <string>

namespace wamba{ namespace prefixdb {

template<typename I, typename Out >
inline Out encode64(I beg, I end, Out out)
{
using namespace boost::archive::iterators;
typedef insert_linebreaks<base64_from_binary<transform_width<I, 6, 8> >, 72 > iterator;
out = std::copy( iterator(beg), iterator(end), out);
return std::fill_n( out, (3-std::distance(beg,end)%3)%3, '=');
}

// костыль для старого буста: tail - хвост который нужно отрезать в результате, модификация интервала
template<typename I, typename Out >
inline Out decode64(I beg, I end, Out out, size_t& tail)
{
using namespace boost::archive::iterators;
typedef transform_width<binary_from_base64< remove_whitespace<I> >, 8, 6> iterator;
std::reverse_iterator<I> rend(end);
for ( tail=0; tail < 2 && *rend == '='; ++tail, ++rend, *( end - static_cast<std::ptrdiff_t>(tail) )='A' );
return std::copy( iterator(beg), iterator(end), out);
}

}}
186 changes: 186 additions & 0 deletions package/prefixdb/domain/multidb/aux/copy_dir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#define BOOST_NO_CXX11_SCOPED_ENUMS

#include <prefixdb/domain/multidb/aux/copy_dir.hpp>
#include <boost/algorithm/string.hpp>
#include <wfc/boost.hpp>
#include <sstream>
#include <cstdlib>
namespace wamba{ namespace prefixdb { namespace file{

namespace
{
bool copy_(
boost::filesystem::path const & source,
boost::filesystem::path const & destination,
std::string& message
)
{
try
{
// Check whether the function call is valid
if( !boost::filesystem::exists(source) || !boost::filesystem::is_directory(source) )
{
std::stringstream ss;
ss << "Source directory " << source.string() << " does not exist or is not a directory." << '\n';
message = ss.str();
return false;
}

if ( boost::filesystem::exists(destination) )
{
std::stringstream ss;
ss << "Destination directory " << destination.string() << " already exists." << '\n';
message = ss.str();
return false;
}

// Create the destination directory
if( !boost::filesystem::create_directory(destination) )
{
std::stringstream ss;
ss << "Unable to create destination directory " << destination.string() << '\n';
message = ss.str();
return false;
}
}
catch(boost::filesystem::filesystem_error const & e)
{
std::stringstream ss;
ss << e.what() << '\n';
message = ss.str();
return false;
}

// Iterate through the source directory
for( boost::filesystem::directory_iterator file(source); file != boost::filesystem::directory_iterator(); ++file) try
{
boost::filesystem::path current(file->path());
if( boost::filesystem::is_directory(current) )
{
// Found directory: Recursion
if( !copy_(current, destination / current.filename(), message) )
return false;
}
else
{
// Found file: Copy
boost::system::error_code ec;
boost::filesystem::copy_file( current, destination / current.filename(), ec);
if (ec)
{
// TODO: Ошибка
}
}
}
catch(const boost::filesystem::filesystem_error& e)
{
std::stringstream ss;
ss << e.what() << '\n';
message = ss.str();
return false;
}
return true;
}

bool remove_( const boost::filesystem::path& path, std::string& message )
{
boost::system::error_code ec;
boost::filesystem::remove_all(path, ec);
if (ec)
{
message = "delete_dir(" + path.string() + "):" + ec.message();
return false;
}
return true;
}

bool move_(
boost::filesystem::path const & source,
boost::filesystem::path const & destination,
std::string& message
)
try
{
boost::system::error_code ec;
if ( boost::filesystem::exists(destination, ec) )
{
if ( ec )
{
message = "move_dir: boost::filesystem::exists(" + destination.string() + ")" + ec.message();
return false;
}

if ( !remove_(destination, message) )
return false;

/*boost::filesystem::remove_all(destination, ec);
if ( ec )
{
message = "boost::filesystem::remove_all: " + ec.message();
return false;
}*/
}

boost::filesystem::rename(source, destination, ec);
if ( ec )
{
message = "boost::filesystem::rename(" + source.string() + "," + destination.string() + "):" + ec.message();
return false;
}

/*
if ( std::system(nullptr) != 0 )
{
std::stringstream ss;
ss << "mv '" << source << "' '" << destination << "'";
int ret = std::system(ss.str().c_str());
if ( WIFEXITED(ret) )
{
int err = WEXITSTATUS(ret);
if ( err != 0 )
{
message = std::string(std::strerror(err)) + ": " << ss.str();
return false;
}
}
}
else
{
message="command processor is available";
return false;
}*/
//boost::filesystem::rename(source, destination);
return true;
}
catch(const boost::filesystem::filesystem_error& e)
{
std::stringstream ss;
ss << "move_dir exception: " << e.what() << '\n';
message = ss.str();
return false;
}

}

bool copy(const std::string& from, const std::string& to, std::string& message)
{
return copy_( boost::filesystem::path(from), boost::filesystem::path(to), message);
}

bool move(const std::string& from, const std::string& to, std::string& message)
{
return move_( boost::filesystem::path(from), boost::filesystem::path(to), message);
}

bool remove(const std::string& path, std::string& message)
{
return remove_( boost::filesystem::path(path), message );
}

bool exist(const std::string& path)
{
boost::system::error_code ec;
return boost::filesystem::exists( boost::filesystem::path(path), ec) && !ec;
}

}}}
14 changes: 14 additions & 0 deletions package/prefixdb/domain/multidb/aux/copy_dir.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include <string>

namespace wamba{ namespace prefixdb { namespace file{

bool copy(const std::string& from, const std::string& to, std::string& message);

bool move(const std::string& from, const std::string& to, std::string& message);

bool remove(const std::string& path, std::string& message);

bool exist(const std::string& path);

}}}
43 changes: 43 additions & 0 deletions package/prefixdb/domain/multidb/aux/multidb.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <wfc/memory.hpp>
#include <prefixdb/api/common_status.hpp>

namespace wamba{ namespace prefixdb { namespace{

template<common_status Status, typename Res, typename ReqPtr, typename Callback>
inline bool send_error(const ReqPtr& req, const Callback& cb)
{
if ( cb!=nullptr )
{
auto res = std::make_unique<Res>();
res->prefix = std::move(req->prefix);
res->status = Status;
cb( std::move(res) );
return true;
}
return false;
}

template<typename Res, typename ReqPtr, typename Callback>
inline bool prefix_not_found(const ReqPtr& req, const Callback& cb)
{
return send_error<common_status::PrefixNotFound, Res>(std::move(req), std::move(cb) );
}

template<typename Res, typename ReqPtr, typename Callback>
inline bool create_prefix_fail(const ReqPtr& req, const Callback& cb)
{
return send_error<common_status::CreatePrefixFail, Res>(std::move(req), std::move(cb) );
}

template<typename Res, typename ReqPtr, typename Callback>
inline bool empty_fields(const ReqPtr& req, const Callback& cb)
{
if ( req->fields.empty() )
{
send_error<common_status::EmptyFields, Res>(std::move(req), std::move(cb) );
return true;
}
return false;
}

}}}
35 changes: 35 additions & 0 deletions package/prefixdb/domain/multidb/aux/scan_dir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <prefixdb/domain/multidb/aux/scan_dir.hpp>
#include <dirent.h>

namespace wamba{ namespace prefixdb {

std::vector<std::string> scan_dir(const std::string& path, bool& fail)
{
fail = false;
std::vector<std::string> result;

DIR *dir;
dirent *entry;

dir = opendir(path.c_str());
if (!dir)
{
fail = true;
return result;
};

while ( (entry = readdir(dir)) != nullptr)
{
if ( entry->d_type == 4)
{
std::string file = entry->d_name;
if ( file=="." || file==".." ) continue;
result.push_back(file);
}
};

closedir(dir);
return result;
}

}}
Loading

0 comments on commit 0ddc2a7

Please sign in to comment.