Skip to content

Commit

Permalink
Remove dependencies to cpplocate, cppassist, and cppexpose (only the …
Browse files Browse the repository at this point in the history
…examples still need cppassist)
  • Loading branch information
Stefan Buschmann committed Jul 16, 2017
1 parent b909695 commit f96c714
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 142 deletions.
5 changes: 0 additions & 5 deletions source/cppfs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# External dependencies
#

find_package(cpplocate REQUIRED)
find_package(cppassist REQUIRED)
find_package(cppexpose REQUIRED)
find_package(LibSSH2 REQUIRED)
find_package(LibCrypto)
find_package(ZLIB)
Expand Down Expand Up @@ -182,8 +179,6 @@ target_link_libraries(${target}

PUBLIC
${DEFAULT_LIBRARIES}
cppassist::cppassist
cppexpose::cppexpose

INTERFACE
)
Expand Down
41 changes: 4 additions & 37 deletions source/cppfs/include/cppfs/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
#include <cppfs/cppfs_api.h>


namespace cppexpose
{
class Variant;
}


namespace cppfs
{

Expand Down Expand Up @@ -310,39 +304,12 @@ class CPPFS_API Tree

/**
* @brief
* Get JSON representation of the tree
* Print tree to stdout
*
* @return
* Variant
*/
cppexpose::Variant toVariant() const;

/**
* @brief
* Load tree from JSON representation
*
* @param[in] obj
* Variant (must be an object)
*/
void fromVariant(const cppexpose::Variant & obj);

/**
* @brief
* Save tree to .json file
*
* @param[in] path
* Path to file
*/
void save(const std::string & path) const;

/**
* @brief
* Load tree from .json file
*
* @param[in] path
* Path to file
* @param[in] indent
* Indentation
*/
void load(const std::string & path);
void print(const std::string & indent = "") const;

/**
* @brief
Expand Down
87 changes: 3 additions & 84 deletions source/cppfs/source/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
#include <algorithm>
#include <iostream>

#include <cppexpose/variant/Variant.h>

#include <cppfs/fs.h>
#include <cppfs/FileHandle.h>
#include <cppfs/Diff.h>


using namespace cppexpose;


namespace cppfs
{

Expand Down Expand Up @@ -198,90 +193,14 @@ void Tree::add(std::unique_ptr<Tree> && tree)
m_children.push_back(std::move(tree));
}

Variant Tree::toVariant() const
void Tree::print(const std::string & indent) const
{
Variant obj = Variant::map();
VariantMap & map = *obj.asMap();

map["path"] = m_path;
map["filename"] = m_filename;
map["isFile"] = !m_directory;
map["isDirectory"] = m_directory;
map["size"] = m_size;
map["accessTime"] = m_accessTime;
map["modificationTime"] = m_modificationTime;
map["userId"] = m_userId;
map["groupId"] = m_groupId;
map["permissions"] = m_permissions;
map["sha1"] = m_sha1;
map["children"] = Variant::array();

VariantArray & array = *map["children"].asArray();
std::cout << indent << m_filename << std::endl;

for (auto & tree : m_children)
{
array.push_back(tree->toVariant());
tree->print(indent + " ");
}

return obj;
}

void Tree::fromVariant(const cppexpose::Variant & obj)
{
// Clear old data
clear();

// Check object
if (!obj.isVariantMap())
{
return;
}

// Read data
const VariantMap & map = *obj.asMap();
m_path = map.at("path").toString();
m_filename = map.at("filename").toString();
m_directory = map.at("isDirectory").toBool();
m_size = map.at("size").value<unsigned int>();
m_accessTime = map.at("accessTime").value<unsigned int>();
m_modificationTime = map.at("modificationTime").value<unsigned int>();
m_userId = map.at("userId").value<unsigned int>();
m_groupId = map.at("groupId").value<unsigned int>();
m_permissions = map.at("permissions").value<unsigned int>();
m_sha1 = map.at("sha1").toString();

// Read children
const auto it = map.find("children");
if (it != map.end())
{
const cppexpose::Variant & children = (*it).second;
const cppexpose::VariantArray & array = *children.asArray();

for (auto & childObj : array)
{
std::unique_ptr<Tree> tree(new Tree);
tree->fromVariant(childObj);

add(std::move(tree));
}
}
}

void Tree::save(const std::string & path) const
{
FileHandle file = fs::open(path);
file.writeFile(toVariant().toJSON(JSON::Beautify));
}

void Tree::load(const std::string & path)
{
FileHandle file = fs::open(path);
std::string json = file.readFile();

Variant obj;
JSON::parse(obj, json);

fromVariant(obj);
}

std::unique_ptr<Diff> Tree::createDiff(const Tree & target) const
Expand Down
7 changes: 1 addition & 6 deletions source/cppfs/source/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <openssl/sha.h>
#endif

#include <cppassist/string/conversion.h>

#include <cppfs/system.h>
#include <cppfs/LoginCredentials.h>
#include <cppfs/Url.h>
Expand All @@ -31,9 +29,6 @@
#endif


using namespace cppassist;


namespace cppfs
{
namespace fs
Expand Down Expand Up @@ -62,7 +57,7 @@ FileHandle open(const std::string & path, const LoginCredentials * credentials)
// Apply login credentials
if (credentials)
{
if (credentials->isSet("port")) port = string::fromString<int>(credentials->value("port"));
if (credentials->isSet("port")) port = std::stoi(credentials->value("port"));
if (credentials->isSet("username")) user = credentials->value("username");
if (credentials->isSet("password")) pass = credentials->value("password");
if (credentials->isSet("publicKey")) publicKey = credentials->value("publicKey");
Expand Down
7 changes: 1 addition & 6 deletions source/cppfs/source/ssh/SshFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
#include <libssh2.h>
#include <libssh2_sftp.h>

#include <cppassist/string/conversion.h>

#include <cppfs/FileHandle.h>
#include <cppfs/ssh/SshFileHandle.h>


using namespace cppassist;


namespace cppfs
{

Expand Down Expand Up @@ -96,7 +91,7 @@ void SshFileSystem::connect()
hints.ai_socktype = SOCK_STREAM;

struct addrinfo * addrInfo = nullptr;
if ((getaddrinfo(m_host.c_str(), string::toString<int>(m_port).c_str(), &hints, &addrInfo)) != 0)
if ((getaddrinfo(m_host.c_str(), std::to_string(m_port).c_str(), &hints, &addrInfo)) != 0)
{
// Error!
return;
Expand Down
6 changes: 2 additions & 4 deletions source/examples/cppfs-tree/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <cppassist/cmdline/CommandLineOption.h>
#include <cppassist/cmdline/CommandLineParameter.h>

#include <cppexpose/variant/Variant.h>

#include <cppfs/cppfs-version.h>
#include <cppfs/fs.h>
#include <cppfs/LoginCredentials.h>
Expand Down Expand Up @@ -76,8 +74,8 @@ int main(int argc, char * argv[])
auto tree = dir.readTree();

// Print tree
std::string json = tree->toVariant().toJSON(cppexpose::JSON::Beautify);
std::cout << json << std::endl;
tree->print();
std::cout << std::endl;

// Done
return 0;
Expand Down

0 comments on commit f96c714

Please sign in to comment.