Develop and Download Open Source Software

Browse Subversion Repository

Diff of /hamigaki/trunk/libs/archivers/example/extract.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1781 by hamigaki, Sat Apr 26 11:33:01 2008 UTC revision 1782 by hamigaki, Sun Jun 10 06:01:53 2018 UTC
# Line 1  Line 1 
1  // extract.cpp: multi-format extractor  // extract.cpp: multi-format extractor
2    
3  // Copyright Takeshi Mouri 2006-2008.  // Copyright Takeshi Mouri 2006-2018.
4  // Distributed under the Boost Software License, Version 1.0.  // Distributed under the Boost Software License, Version 1.0.
5  // (See accompanying file LICENSE_1_0.txt or copy at  // (See accompanying file LICENSE_1_0.txt or copy at
6  // http://www.boost.org/LICENSE_1_0.txt)  // http://www.boost.org/LICENSE_1_0.txt)
# Line 34  namespace algo = boost::algorithm; Line 34  namespace algo = boost::algorithm;
34  namespace fs = boost::filesystem;  namespace fs = boost::filesystem;
35  namespace io = boost::iostreams;  namespace io = boost::iostreams;
36    
37    template<class Path>
38    bool is_valid_path(const Path& ph)
39    {
40    #if !defined(HAMIGAKI_ALLOW_DIRECTORY_TRAVERSAL)
41        if (ph.has_root_name() || ph.has_root_directory())
42            return false;
43        for (typename Path::iterator it = ph.begin(); it != ph.end(); ++it)
44        {
45            if (*it == "..")
46                return false;
47        }
48    #endif
49        return true;
50    }
51    
52  struct entry  struct entry
53  {  {
54      fs_ex::file_type type;      fs_ex::file_type type;
# Line 367  int main(int argc, char* argv[]) Line 382  int main(int argc, char* argv[])
382              const entry& e = ext_ptr->current_entry();              const entry& e = ext_ptr->current_entry();
383    
384              std::cout << e.path.string() << '\n';              std::cout << e.path.string() << '\n';
385                if (!is_valid_path(e.path))
386                {
387                    std::cerr << "Warning: invalid path" << '\n';
388                    continue;
389                }
390    
391              if (!e.hard_link_path.empty())              if (!e.hard_link_path.empty())
392                  fs_ex::create_hard_link(e.hard_link_path, e.path);                  fs_ex::create_hard_link(e.hard_link_path, e.path);

Legend:
Removed from v.1781  
changed lines
  Added in v.1782

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26