]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/inspect/path_name_check.cpp
1 // path_name_check implementation ------------------------------------------//
3 // Copyright Beman Dawes 2002.
4 // Copyright Gennaro Prota 2006.
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)
10 #include "path_name_check.hpp"
12 #include "boost/filesystem/operations.hpp"
13 #include "boost/lexical_cast.hpp"
24 const char allowable
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.";
25 const char initial_char
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
34 file_name_check::file_name_check() : m_name_errors(0) {}
36 void file_name_check::inspect(
37 const string
& library_name
,
38 const path
& full_path
)
40 string::size_type pos
;
42 // called for each file and directory, so only the leaf need be tested
43 string
const leaf( full_path
.leaf().string() );
45 // includes only allowable characters
46 if ( (pos
= leaf
.find_first_not_of( allowable
)) != string::npos
)
49 error( library_name
, full_path
, string(name())
50 + " file or directory name contains unacceptable character '"
54 // allowable initial character
55 if ( std::strchr( initial_char
, leaf
[0] ) == 0 )
58 error( library_name
, full_path
, string(name())
59 + " file or directory name begins with an unacceptable character" );
62 // rules for dot characters differ slightly for directories and files
63 if ( filesystem::is_directory( full_path
) )
65 if ( std::strchr( leaf
.c_str(), '.' ) )
68 error( library_name
, full_path
, string(name())
69 + " directory name contains a dot character ('.')" );
72 //else // not a directory
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, '.' ) )
79 // error( library_name, full_path, string(name())
80 // + " file name with more than one dot character ('.')" );
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() ) )
92 error( library_name
, full_path
,
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" )
103 file_name_check::~file_name_check()
105 std::cout
<< " " << m_name_errors
<< " " << desc() << line_break();
109 } // namespace inspect