| 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) |
| 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; |
| 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); |