]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/inspect/path_name_check.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / tools / inspect / path_name_check.cpp
1 // path_name_check implementation ------------------------------------------//
2
3 // Copyright Beman Dawes 2002.
4 // Copyright Gennaro Prota 2006.
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #include "path_name_check.hpp"
11
12 #include "boost/filesystem/operations.hpp"
13 #include "boost/lexical_cast.hpp"
14
15 #include <string>
16 #include <algorithm>
17 #include <cctype>
18 #include <cstring>
19
20 using std::string;
21
22 namespace
23 {
24 const char allowable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.";
25 const char initial_char[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
26 }
27
28 namespace boost
29 {
30 namespace inspect
31 {
32
33
34 file_name_check::file_name_check() : m_name_errors(0) {}
35
36 void file_name_check::inspect(
37 const string & library_name,
38 const path & full_path )
39 {
40 string::size_type pos;
41
42 // called for each file and directory, so only the leaf need be tested
43 string const leaf( full_path.leaf().string() );
44
45 // includes only allowable characters
46 if ( (pos = leaf.find_first_not_of( allowable )) != string::npos )
47 {
48 ++m_name_errors;
49 error( library_name, full_path, string(name())
50 + " file or directory name contains unacceptable character '"
51 + leaf[pos] + "'" );
52 }
53
54 // allowable initial character
55 if ( std::strchr( initial_char, leaf[0] ) == 0 )
56 {
57 ++m_name_errors;
58 error( library_name, full_path, string(name())
59 + " file or directory name begins with an unacceptable character" );
60 }
61
62 // rules for dot characters differ slightly for directories and files
63 if ( filesystem::is_directory( full_path ) )
64 {
65 if ( std::strchr( leaf.c_str(), '.' ) )
66 {
67 ++m_name_errors;
68 error( library_name, full_path, string(name())
69 + " directory name contains a dot character ('.')" );
70 }
71 }
72 //else // not a directory
73 //{
74 // // includes at most one dot character
75 // const char * first_dot = std::strchr( leaf.c_str(), '.' );
76 // if ( first_dot && std::strchr( first_dot+1, '.' ) )
77 // {
78 // ++m_name_errors;
79 // error( library_name, full_path, string(name())
80 // + " file name with more than one dot character ('.')" );
81 // }
82 //}
83
84 // the path, including a presumed root, does not exceed the maximum size
85 path const relative_path( relative_to( full_path, search_root_path() ) );
86 const unsigned max_relative_path = 207; // ISO 9660:1999 sets this limit
87 const string generic_root( "boost_X_XX_X/" );
88 if ( relative_path.string().size() >
89 ( max_relative_path - generic_root.size() ) )
90 {
91 ++m_name_errors;
92 error( library_name, full_path,
93 string(name())
94 + " path will exceed "
95 + boost::lexical_cast<string>(max_relative_path)
96 + " characters in a directory tree with a root in the form "
97 + generic_root + ", and this exceeds ISO 9660:1999 limit of 207" )
98 ;
99 }
100
101 }
102
103 file_name_check::~file_name_check()
104 {
105 std::cout << " " << m_name_errors << " " << desc() << line_break();
106 }
107
108
109 } // namespace inspect
110 } // namespace boost