diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/boost/tools/inspect/path_name_check.cpp | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/tools/inspect/path_name_check.cpp')
-rw-r--r-- | src/boost/tools/inspect/path_name_check.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/boost/tools/inspect/path_name_check.cpp b/src/boost/tools/inspect/path_name_check.cpp new file mode 100644 index 000000000..0714e20c0 --- /dev/null +++ b/src/boost/tools/inspect/path_name_check.cpp @@ -0,0 +1,110 @@ +// path_name_check implementation ------------------------------------------// + +// Copyright Beman Dawes 2002. +// Copyright Gennaro Prota 2006. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include "path_name_check.hpp" + +#include "boost/filesystem/operations.hpp" +#include "boost/lexical_cast.hpp" + +#include <string> +#include <algorithm> +#include <cctype> +#include <cstring> + +using std::string; + +namespace +{ + const char allowable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-."; + const char initial_char[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; +} + +namespace boost +{ + namespace inspect + { + + + file_name_check::file_name_check() : m_name_errors(0) {} + + void file_name_check::inspect( + const string & library_name, + const path & full_path ) + { + string::size_type pos; + + // called for each file and directory, so only the leaf need be tested + string const leaf( full_path.leaf().string() ); + + // includes only allowable characters + if ( (pos = leaf.find_first_not_of( allowable )) != string::npos ) + { + ++m_name_errors; + error( library_name, full_path, string(name()) + + " file or directory name contains unacceptable character '" + + leaf[pos] + "'" ); + } + + // allowable initial character + if ( std::strchr( initial_char, leaf[0] ) == 0 ) + { + ++m_name_errors; + error( library_name, full_path, string(name()) + + " file or directory name begins with an unacceptable character" ); + } + + // rules for dot characters differ slightly for directories and files + if ( filesystem::is_directory( full_path ) ) + { + if ( std::strchr( leaf.c_str(), '.' ) ) + { + ++m_name_errors; + error( library_name, full_path, string(name()) + + " directory name contains a dot character ('.')" ); + } + } + //else // not a directory + //{ + // // includes at most one dot character + // const char * first_dot = std::strchr( leaf.c_str(), '.' ); + // if ( first_dot && std::strchr( first_dot+1, '.' ) ) + // { + // ++m_name_errors; + // error( library_name, full_path, string(name()) + // + " file name with more than one dot character ('.')" ); + // } + //} + + // the path, including a presumed root, does not exceed the maximum size + path const relative_path( relative_to( full_path, search_root_path() ) ); + const unsigned max_relative_path = 207; // ISO 9660:1999 sets this limit + const string generic_root( "boost_X_XX_X/" ); + if ( relative_path.string().size() > + ( max_relative_path - generic_root.size() ) ) + { + ++m_name_errors; + error( library_name, full_path, + string(name()) + + " path will exceed " + + boost::lexical_cast<string>(max_relative_path) + + " characters in a directory tree with a root in the form " + + generic_root + ", and this exceeds ISO 9660:1999 limit of 207" ) + ; + } + + } + + file_name_check::~file_name_check() + { + std::cout << " " << m_name_errors << " " << desc() << line_break(); + } + + + } // namespace inspect +} // namespace boost |