// Copyright Jan Langer 2002
// Copyright Dietmar Kuehl 2001
// Copyright Vladimir Prus 2002
+// Copyright Andrey Semashev 2020
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#include <boost/filesystem/directory.hpp>
#endif
+#include <boost/detail/bitmask.hpp>
#include <boost/core/scoped_enum.hpp>
#include <boost/system/error_code.hpp>
#include <boost/cstdint.hpp>
boost::uintmax_t available; // <= free
};
+BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(copy_options, unsigned int)
+{
+ none = 0u, // Default. For copy_file: error if the target file exists. For copy: do not recurse, follow symlinks, copy file contents.
+
+ // copy_file options:
+ skip_existing = 1u, // Don't overwrite the existing target file, don't report an error
+ overwrite_existing = 1u << 1, // Overwrite existing file
+ update_existing = 1u << 2, // Overwrite existing file if its last write time is older than the replacement file
+
+ // copy options:
+ recursive = 1u << 8, // Recurse into sub-directories
+ copy_symlinks = 1u << 9, // Copy symlinks as symlinks instead of copying the referenced file
+ skip_symlinks = 1u << 10, // Don't copy symlinks
+ directories_only = 1u << 11, // Only copy directory structure, do not copy non-directory files
+ create_symlinks = 1u << 12, // Create symlinks instead of copying files
+ create_hard_links = 1u << 13, // Create hard links instead of copying files
+ _detail_recursing = 1u << 14 // Internal use only, do not use
+}
+BOOST_SCOPED_ENUM_DECLARE_END(copy_options)
+
+BOOST_BITMASK(BOOST_SCOPED_ENUM_NATIVE(copy_options))
+
+#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
BOOST_SCOPED_ENUM_DECLARE_BEGIN(copy_option)
- {none=0, fail_if_exists = none, overwrite_if_exists}
+{
+ none = static_cast< unsigned int >(copy_options::none),
+ fail_if_exists = none,
+ overwrite_if_exists = static_cast< unsigned int >(copy_options::overwrite_existing)
+}
BOOST_SCOPED_ENUM_DECLARE_END(copy_option)
+#endif
//--------------------------------------------------------------------------------------//
// implementation details //
namespace detail {
-// We cannot pass a BOOST_SCOPED_ENUM to a compled function because it will result
-// in an undefined reference if the library is compled with -std=c++0x but the use
-// is compiled in C++03 mode, or vice versa. See tickets 6124, 6779, 10038.
-enum copy_option {none=0, fail_if_exists = none, overwrite_if_exists};
-
+BOOST_FILESYSTEM_DECL
+path absolute(const path& p, const path& base, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
file_status status(const path&p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
BOOST_FILESYSTEM_DECL
path canonical(const path& p, const path& base, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
-void copy(const path& from, const path& to, system::error_code* ec=0);
+void copy(const path& from, const path& to, unsigned int options, system::error_code* ec=0);
+#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
BOOST_FILESYSTEM_DECL
void copy_directory(const path& from, const path& to, system::error_code* ec=0);
+#endif
BOOST_FILESYSTEM_DECL
-void copy_file(const path& from, const path& to, // See ticket #2925
- detail::copy_option option, system::error_code* ec=0);
+bool copy_file(const path& from, const path& to, // See ticket #2925
+ unsigned int options, system::error_code* ec=0); // see copy_options for options
BOOST_FILESYSTEM_DECL
void copy_symlink(const path& existing_symlink, const path& new_symlink, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
bool create_directories(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
-bool create_directory(const path& p, system::error_code* ec=0);
+bool create_directory(const path& p, const path* existing, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void create_directory_symlink(const path& to, const path& from,
system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
boost::uintmax_t hard_link_count(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
+std::time_t creation_time(const path& p, system::error_code* ec=0);
+BOOST_FILESYSTEM_DECL
std::time_t last_write_time(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void last_write_time(const path& p, const std::time_t new_time,
//--------------------------------------------------------------------------------------//
// //
// operational functions //
-// in alphabetical order, unless otherwise noted //
// //
//--------------------------------------------------------------------------------------//
-// forward declarations
-path current_path(); // fwd declaration
-path initial_path();
+inline
+path initial_path() {return detail::initial_path();}
-BOOST_FILESYSTEM_DECL
-path absolute(const path& p, const path& base=current_path());
-// If base.is_absolute(), throws nothing. Thus no need for ec argument
+inline
+path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
+
+template <class Path>
+path initial_path() {return initial_path();}
+template <class Path>
+path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
+
+inline
+path current_path() {return detail::current_path();}
+
+inline
+path current_path(system::error_code& ec) {return detail::current_path(&ec);}
+
+inline
+void current_path(const path& p) {detail::current_path(p);}
+
+inline
+void current_path(const path& p, system::error_code& ec) BOOST_NOEXCEPT {detail::current_path(p, &ec);}
+
+inline
+path absolute(const path& p, const path& base=current_path()) {return detail::absolute(p, base);}
+inline
+path absolute(const path& p, system::error_code& ec)
+{
+ path base = current_path(ec);
+ if (ec)
+ return path();
+ return detail::absolute(p, base, &ec);
+}
+inline
+path absolute(const path& p, const path& base, system::error_code& ec) {return detail::absolute(p, base, &ec);}
inline
path canonical(const path& p, const path& base=current_path())
{return detail::canonical(p, base);}
inline
path canonical(const path& p, system::error_code& ec)
- {return detail::canonical(p, current_path(), &ec);}
+{
+ path base = current_path(ec);
+ if (ec)
+ return path();
+ return detail::canonical(p, base, &ec);
+}
inline
path canonical(const path& p, const path& base, system::error_code& ec)
{return detail::canonical(p, base, &ec);}
#endif
inline
-void copy(const path& from, const path& to) {detail::copy(from, to);}
-
+void copy(const path& from, const path& to)
+{
+ detail::copy(from, to, static_cast< unsigned int >(copy_options::none));
+}
inline
void copy(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
- {detail::copy(from, to, &ec);}
+{
+ detail::copy(from, to, static_cast< unsigned int >(copy_options::none), &ec);
+}
+inline
+void copy(const path& from, const path& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options)
+{
+ detail::copy(from, to, static_cast< unsigned int >(options));
+}
+inline
+void copy(const path& from, const path& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
+{
+ detail::copy(from, to, static_cast< unsigned int >(options), &ec);
+}
+
+#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
inline
void copy_directory(const path& from, const path& to)
{detail::copy_directory(from, to);}
inline
void copy_directory(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
{detail::copy_directory(from, to, &ec);}
+#endif
+inline
+bool copy_file(const path& from, const path& to)
+{
+ return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none));
+}
+inline
+bool copy_file(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
+{
+ return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none), &ec);
+}
inline
-void copy_file(const path& from, const path& to, // See ticket #2925
- BOOST_SCOPED_ENUM_NATIVE(copy_option) option)
+bool copy_file(const path& from, const path& to, // See ticket #2925
+ BOOST_SCOPED_ENUM_NATIVE(copy_options) options)
{
- detail::copy_file(from, to, static_cast<detail::copy_option>(option));
+ return detail::copy_file(from, to, static_cast< unsigned int >(options));
}
inline
-void copy_file(const path& from, const path& to)
+bool copy_file(const path& from, const path& to, // See ticket #2925
+ BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
{
- detail::copy_file(from, to, detail::fail_if_exists);
+ return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec);
}
+#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
inline
-void copy_file(const path& from, const path& to, // See ticket #2925
- BOOST_SCOPED_ENUM_NATIVE(copy_option) option, system::error_code& ec) BOOST_NOEXCEPT
+bool copy_file(const path& from, const path& to, // See ticket #2925
+ BOOST_SCOPED_ENUM_NATIVE(copy_option) options)
{
- detail::copy_file(from, to, static_cast<detail::copy_option>(option), &ec);
+ return detail::copy_file(from, to, static_cast< unsigned int >(options));
}
inline
-void copy_file(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
+bool copy_file(const path& from, const path& to, // See ticket #2925
+ BOOST_SCOPED_ENUM_NATIVE(copy_option) options, system::error_code& ec) BOOST_NOEXCEPT
{
- detail::copy_file(from, to, detail::fail_if_exists, &ec);
+ return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec);
}
+#endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
inline
void copy_symlink(const path& existing_symlink,
const path& new_symlink) {detail::copy_symlink(existing_symlink, new_symlink);}
bool create_directories(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::create_directories(p, &ec);}
inline
-bool create_directory(const path& p) {return detail::create_directory(p);}
+bool create_directory(const path& p) {return detail::create_directory(p, 0);}
inline
bool create_directory(const path& p, system::error_code& ec) BOOST_NOEXCEPT
- {return detail::create_directory(p, &ec);}
+ {return detail::create_directory(p, 0, &ec);}
+inline
+bool create_directory(const path& p, const path& existing)
+ {return detail::create_directory(p, &existing);}
+inline
+bool create_directory(const path& p, const path& existing, system::error_code& ec) BOOST_NOEXCEPT
+ {return detail::create_directory(p, &existing, &ec);}
inline
void create_directory_symlink(const path& to, const path& from)
{detail::create_directory_symlink(to, from);}
inline
void create_symlink(const path& to, const path& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
{detail::create_symlink(to, new_symlink, &ec);}
-inline
-path current_path() {return detail::current_path();}
-
-inline
-path current_path(system::error_code& ec) {return detail::current_path(&ec);}
-
-inline
-void current_path(const path& p) {detail::current_path(p);}
-
-inline
-void current_path(const path& p, system::error_code& ec) BOOST_NOEXCEPT {detail::current_path(p, &ec);}
-
inline
bool equivalent(const path& p1, const path& p2) {return detail::equivalent(p1, p2);}
boost::uintmax_t hard_link_count(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::hard_link_count(p, &ec);}
inline
-path initial_path() {return detail::initial_path();}
+std::time_t creation_time(const path& p) { return detail::creation_time(p); }
inline
-path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
-
-template <class Path>
-path initial_path() {return initial_path();}
-template <class Path>
-path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
-
+std::time_t creation_time(const path& p, system::error_code& ec) BOOST_NOEXCEPT
+ { return detail::creation_time(p, &ec); }
inline
std::time_t last_write_time(const path& p) {return detail::last_write_time(p);}
{return detail::relative(p, base);}
inline
path relative(const path& p, system::error_code& ec)
- {return detail::relative(p, current_path(), &ec);}
+{
+ path base = current_path(ec);
+ if (ec)
+ return path();
+ return detail::relative(p, base, &ec);
+}
inline
path relative(const path& p, const path& base, system::error_code& ec)
{return detail::relative(p, base, &ec);}