-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generated export autocommit from mamba.ru
- Loading branch information
GitLab Runner
committed
Feb 15, 2024
1 parent
b41cd1e
commit 0ddc2a7
Showing
63 changed files
with
5,979 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
}} |
Oops, something went wrong.