Sha256: d2f330b059ec1682e937443d999a132bc1bc1dd844c3d15e3f098584713b4e48

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

#include <leatherman/file_util/directory.hpp>
#include <leatherman/util/regex.hpp>
#include <boost/filesystem.hpp>

using namespace std;
using namespace boost::filesystem;
using namespace leatherman::util;

namespace leatherman { namespace file_util {

    static void each(string const& directory, file_type type, function<bool(string const&)> const& callback, string const& pattern)
    {
        boost::regex regex;
        if (!pattern.empty()) {
            regex = pattern;
        }

        // Attempt to iterate the directory
        boost::system::error_code ec;
        directory_iterator it = directory_iterator(directory, ec);
        if (ec) {
            return;
        }

        // Call the callback for any matching entries
        directory_iterator end;
        for (; it != end; ++it) {
            ec.clear();
            auto status = it->status(ec);
            if (ec || (status.type() != type)) {
                continue;
            }
            if (regex.empty() || re_search(it->path().filename().string(), regex)) {
                if (!callback(it->path().string())) {
                    break;
                }
            }
        }
    }

    void each_file(string const& directory, function<bool(string const&)> const& callback, string const& pattern)
    {
        each(directory, regular_file, callback, pattern);
    }

    void each_subdirectory(string const& directory, function<bool(string const&)> const& callback, string const& pattern)
    {
        each(directory, directory_file, callback, pattern);
    }

}}  // namespace leatherman::file_util

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
facter-3.12.2.cfacter.20181217 ext/facter/leatherman/file_util/src/directory.cc
facter-3.12.1.cfacter.20181031 ext/facter/leatherman/file_util/src/directory.cc
facter-3.11.6.cfacter.20181031 ext/facter/leatherman/file_util/src/directory.cc
facter-3.12.1.cfacter.20181023 ext/facter/leatherman/file_util/src/directory.cc
facter-3.11.5.cfacter.20181022 ext/facter/leatherman/file_util/src/directory.cc
facter-3.12.0.cfacter.20181004 ext/facter/leatherman/file_util/src/directory.cc
facter-3.12.0.cfacter.20181001 ext/facter/leatherman/file_util/src/directory.cc
facter-3.12.0.cfacter.20180918 ext/facter/leatherman/file_util/src/directory.cc
facter-3.11.4.cfacter.20180821 ext/facter/leatherman/file_util/src/directory.cc
facter-3.11.3.cfacter.20180716 ext/facter/leatherman/file_util/src/directory.cc
facter-3.11.2.cfacter.20180612 ext/facter/leatherman/file_util/src/directory.cc
facter-3.9.6.cfacter.20180612 ext/facter/leatherman/file_util/src/directory.cc
facter-3.11.2.cfacter.20180606 ext/facter/leatherman/file_util/src/directory.cc
facter-3.9.6.cfacter.20180606 ext/facter/leatherman/file_util/src/directory.cc
facter-3.11.0.cfacter.20180319 ext/facter/leatherman/file_util/src/directory.cc
cfacter-3.11.0.rc.20180314 ext/facter/leatherman/file_util/src/directory.cc