1 // boost/filesystem/operations.hpp ---------------------------------------------------//
3 // Copyright Beman Dawes 2002-2009
4 // Copyright Jan Langer 2002
5 // Copyright Dietmar Kuehl 2001
6 // Copyright Vladimir Prus 2002
8 // Distributed under the Boost Software License, Version 1.0.
9 // See http://www.boost.org/LICENSE_1_0.txt
11 // Library home page: http://www.boost.org/libs/filesystem
13 //--------------------------------------------------------------------------------------//
15 #ifndef BOOST_FILESYSTEM3_OPERATIONS_HPP
16 #define BOOST_FILESYSTEM3_OPERATIONS_HPP
18 #include <boost/config.hpp>
20 # if defined( BOOST_NO_STD_WSTRING )
21 # error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
24 #include <boost/filesystem/config.hpp>
25 #include <boost/filesystem/path.hpp>
26 #include <boost/filesystem/file_status.hpp>
28 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
29 // These includes are left for backward compatibility and should be included directly by users, as needed
30 #include <boost/filesystem/exception.hpp>
31 #include <boost/filesystem/directory.hpp>
34 #include <boost/core/scoped_enum.hpp>
35 #include <boost/system/error_code.hpp>
36 #include <boost/cstdint.hpp>
40 #include <boost/config/abi_prefix.hpp> // must be the last #include
42 //--------------------------------------------------------------------------------------//
45 namespace filesystem {
49 // all values are byte counts
50 boost::uintmax_t capacity;
51 boost::uintmax_t free; // <= capacity
52 boost::uintmax_t available; // <= free
55 BOOST_SCOPED_ENUM_DECLARE_BEGIN(copy_option)
56 {none=0, fail_if_exists = none, overwrite_if_exists}
57 BOOST_SCOPED_ENUM_DECLARE_END(copy_option)
59 //--------------------------------------------------------------------------------------//
60 // implementation details //
61 //--------------------------------------------------------------------------------------//
65 // We cannot pass a BOOST_SCOPED_ENUM to a compled function because it will result
66 // in an undefined reference if the library is compled with -std=c++0x but the use
67 // is compiled in C++03 mode, or vice versa. See tickets 6124, 6779, 10038.
68 enum copy_option {none=0, fail_if_exists = none, overwrite_if_exists};
71 file_status status(const path&p, system::error_code* ec=0);
73 file_status symlink_status(const path& p, system::error_code* ec=0);
75 bool is_empty(const path& p, system::error_code* ec=0);
77 path initial_path(system::error_code* ec=0);
79 path canonical(const path& p, const path& base, system::error_code* ec=0);
81 void copy(const path& from, const path& to, system::error_code* ec=0);
83 void copy_directory(const path& from, const path& to, system::error_code* ec=0);
85 void copy_file(const path& from, const path& to, // See ticket #2925
86 detail::copy_option option, system::error_code* ec=0);
88 void copy_symlink(const path& existing_symlink, const path& new_symlink, system::error_code* ec=0);
90 bool create_directories(const path& p, system::error_code* ec=0);
92 bool create_directory(const path& p, system::error_code* ec=0);
94 void create_directory_symlink(const path& to, const path& from,
95 system::error_code* ec=0);
97 void create_hard_link(const path& to, const path& from, system::error_code* ec=0);
99 void create_symlink(const path& to, const path& from, system::error_code* ec=0);
100 BOOST_FILESYSTEM_DECL
101 path current_path(system::error_code* ec=0);
102 BOOST_FILESYSTEM_DECL
103 void current_path(const path& p, system::error_code* ec=0);
104 BOOST_FILESYSTEM_DECL
105 bool equivalent(const path& p1, const path& p2, system::error_code* ec=0);
106 BOOST_FILESYSTEM_DECL
107 boost::uintmax_t file_size(const path& p, system::error_code* ec=0);
108 BOOST_FILESYSTEM_DECL
109 boost::uintmax_t hard_link_count(const path& p, system::error_code* ec=0);
110 BOOST_FILESYSTEM_DECL
111 std::time_t last_write_time(const path& p, system::error_code* ec=0);
112 BOOST_FILESYSTEM_DECL
113 void last_write_time(const path& p, const std::time_t new_time,
114 system::error_code* ec=0);
115 BOOST_FILESYSTEM_DECL
116 void permissions(const path& p, perms prms, system::error_code* ec=0);
117 BOOST_FILESYSTEM_DECL
118 path read_symlink(const path& p, system::error_code* ec=0);
119 BOOST_FILESYSTEM_DECL
120 path relative(const path& p, const path& base, system::error_code* ec = 0);
121 BOOST_FILESYSTEM_DECL
122 bool remove(const path& p, system::error_code* ec=0);
123 BOOST_FILESYSTEM_DECL
124 boost::uintmax_t remove_all(const path& p, system::error_code* ec=0);
125 BOOST_FILESYSTEM_DECL
126 void rename(const path& old_p, const path& new_p, system::error_code* ec=0);
127 BOOST_FILESYSTEM_DECL
128 void resize_file(const path& p, uintmax_t size, system::error_code* ec=0);
129 BOOST_FILESYSTEM_DECL
130 space_info space(const path& p, system::error_code* ec=0);
131 BOOST_FILESYSTEM_DECL
132 path system_complete(const path& p, system::error_code* ec=0);
133 BOOST_FILESYSTEM_DECL
134 path temp_directory_path(system::error_code* ec=0);
135 BOOST_FILESYSTEM_DECL
136 path unique_path(const path& p, system::error_code* ec=0);
137 BOOST_FILESYSTEM_DECL
138 path weakly_canonical(const path& p, system::error_code* ec = 0);
140 } // namespace detail
142 //--------------------------------------------------------------------------------------//
144 // status query functions //
146 //--------------------------------------------------------------------------------------//
149 file_status status(const path& p) {return detail::status(p);}
151 file_status status(const path& p, system::error_code& ec)
152 {return detail::status(p, &ec);}
154 file_status symlink_status(const path& p) {return detail::symlink_status(p);}
156 file_status symlink_status(const path& p, system::error_code& ec)
157 {return detail::symlink_status(p, &ec);}
159 bool exists(const path& p) {return exists(detail::status(p));}
161 bool exists(const path& p, system::error_code& ec)
162 {return exists(detail::status(p, &ec));}
164 bool is_directory(const path& p) {return is_directory(detail::status(p));}
166 bool is_directory(const path& p, system::error_code& ec)
167 {return is_directory(detail::status(p, &ec));}
169 bool is_regular_file(const path& p) {return is_regular_file(detail::status(p));}
171 bool is_regular_file(const path& p, system::error_code& ec)
172 {return is_regular_file(detail::status(p, &ec));}
174 bool is_other(const path& p) {return is_other(detail::status(p));}
176 bool is_other(const path& p, system::error_code& ec)
177 {return is_other(detail::status(p, &ec));}
179 bool is_symlink(const path& p) {return is_symlink(detail::symlink_status(p));}
181 bool is_symlink(const path& p, system::error_code& ec)
182 {return is_symlink(detail::symlink_status(p, &ec));}
183 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
185 bool is_regular(const path& p) {return is_regular(detail::status(p));}
187 bool is_regular(const path& p, system::error_code& ec)
188 {return is_regular(detail::status(p, &ec));}
192 bool is_empty(const path& p) {return detail::is_empty(p);}
194 bool is_empty(const path& p, system::error_code& ec)
195 {return detail::is_empty(p, &ec);}
197 //--------------------------------------------------------------------------------------//
199 // operational functions //
200 // in alphabetical order, unless otherwise noted //
202 //--------------------------------------------------------------------------------------//
204 // forward declarations
205 path current_path(); // fwd declaration
208 BOOST_FILESYSTEM_DECL
209 path absolute(const path& p, const path& base=current_path());
210 // If base.is_absolute(), throws nothing. Thus no need for ec argument
213 path canonical(const path& p, const path& base=current_path())
214 {return detail::canonical(p, base);}
216 path canonical(const path& p, system::error_code& ec)
217 {return detail::canonical(p, current_path(), &ec);}
219 path canonical(const path& p, const path& base, system::error_code& ec)
220 {return detail::canonical(p, base, &ec);}
222 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
224 path complete(const path& p)
226 return absolute(p, initial_path());
230 path complete(const path& p, const path& base)
232 return absolute(p, base);
237 void copy(const path& from, const path& to) {detail::copy(from, to);}
240 void copy(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
241 {detail::copy(from, to, &ec);}
243 void copy_directory(const path& from, const path& to)
244 {detail::copy_directory(from, to);}
246 void copy_directory(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
247 {detail::copy_directory(from, to, &ec);}
249 void copy_file(const path& from, const path& to, // See ticket #2925
250 BOOST_SCOPED_ENUM_NATIVE(copy_option) option)
252 detail::copy_file(from, to, static_cast<detail::copy_option>(option));
255 void copy_file(const path& from, const path& to)
257 detail::copy_file(from, to, detail::fail_if_exists);
260 void copy_file(const path& from, const path& to, // See ticket #2925
261 BOOST_SCOPED_ENUM_NATIVE(copy_option) option, system::error_code& ec) BOOST_NOEXCEPT
263 detail::copy_file(from, to, static_cast<detail::copy_option>(option), &ec);
266 void copy_file(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
268 detail::copy_file(from, to, detail::fail_if_exists, &ec);
271 void copy_symlink(const path& existing_symlink,
272 const path& new_symlink) {detail::copy_symlink(existing_symlink, new_symlink);}
275 void copy_symlink(const path& existing_symlink, const path& new_symlink,
276 system::error_code& ec) BOOST_NOEXCEPT
277 {detail::copy_symlink(existing_symlink, new_symlink, &ec);}
279 bool create_directories(const path& p) {return detail::create_directories(p);}
282 bool create_directories(const path& p, system::error_code& ec) BOOST_NOEXCEPT
283 {return detail::create_directories(p, &ec);}
285 bool create_directory(const path& p) {return detail::create_directory(p);}
288 bool create_directory(const path& p, system::error_code& ec) BOOST_NOEXCEPT
289 {return detail::create_directory(p, &ec);}
291 void create_directory_symlink(const path& to, const path& from)
292 {detail::create_directory_symlink(to, from);}
294 void create_directory_symlink(const path& to, const path& from, system::error_code& ec) BOOST_NOEXCEPT
295 {detail::create_directory_symlink(to, from, &ec);}
297 void create_hard_link(const path& to, const path& new_hard_link) {detail::create_hard_link(to, new_hard_link);}
300 void create_hard_link(const path& to, const path& new_hard_link, system::error_code& ec) BOOST_NOEXCEPT
301 {detail::create_hard_link(to, new_hard_link, &ec);}
303 void create_symlink(const path& to, const path& new_symlink) {detail::create_symlink(to, new_symlink);}
306 void create_symlink(const path& to, const path& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
307 {detail::create_symlink(to, new_symlink, &ec);}
309 path current_path() {return detail::current_path();}
312 path current_path(system::error_code& ec) {return detail::current_path(&ec);}
315 void current_path(const path& p) {detail::current_path(p);}
318 void current_path(const path& p, system::error_code& ec) BOOST_NOEXCEPT {detail::current_path(p, &ec);}
321 bool equivalent(const path& p1, const path& p2) {return detail::equivalent(p1, p2);}
324 bool equivalent(const path& p1, const path& p2, system::error_code& ec) BOOST_NOEXCEPT
325 {return detail::equivalent(p1, p2, &ec);}
327 boost::uintmax_t file_size(const path& p) {return detail::file_size(p);}
330 boost::uintmax_t file_size(const path& p, system::error_code& ec) BOOST_NOEXCEPT
331 {return detail::file_size(p, &ec);}
333 boost::uintmax_t hard_link_count(const path& p) {return detail::hard_link_count(p);}
336 boost::uintmax_t hard_link_count(const path& p, system::error_code& ec) BOOST_NOEXCEPT
337 {return detail::hard_link_count(p, &ec);}
339 path initial_path() {return detail::initial_path();}
342 path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
344 template <class Path>
345 path initial_path() {return initial_path();}
346 template <class Path>
347 path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
350 std::time_t last_write_time(const path& p) {return detail::last_write_time(p);}
353 std::time_t last_write_time(const path& p, system::error_code& ec) BOOST_NOEXCEPT
354 {return detail::last_write_time(p, &ec);}
356 void last_write_time(const path& p, const std::time_t new_time)
357 {detail::last_write_time(p, new_time);}
359 void last_write_time(const path& p, const std::time_t new_time,
360 system::error_code& ec) BOOST_NOEXCEPT
361 {detail::last_write_time(p, new_time, &ec);}
363 void permissions(const path& p, perms prms)
364 {detail::permissions(p, prms);}
366 void permissions(const path& p, perms prms, system::error_code& ec) BOOST_NOEXCEPT
367 {detail::permissions(p, prms, &ec);}
370 path read_symlink(const path& p) {return detail::read_symlink(p);}
373 path read_symlink(const path& p, system::error_code& ec)
374 {return detail::read_symlink(p, &ec);}
377 bool remove(const path& p) {return detail::remove(p);}
380 bool remove(const path& p, system::error_code& ec) BOOST_NOEXCEPT
381 {return detail::remove(p, &ec);}
384 boost::uintmax_t remove_all(const path& p) {return detail::remove_all(p);}
387 boost::uintmax_t remove_all(const path& p, system::error_code& ec) BOOST_NOEXCEPT
388 {return detail::remove_all(p, &ec);}
390 void rename(const path& old_p, const path& new_p) {detail::rename(old_p, new_p);}
393 void rename(const path& old_p, const path& new_p, system::error_code& ec) BOOST_NOEXCEPT
394 {detail::rename(old_p, new_p, &ec);}
395 inline // name suggested by Scott McMurray
396 void resize_file(const path& p, uintmax_t size) {detail::resize_file(p, size);}
399 void resize_file(const path& p, uintmax_t size, system::error_code& ec) BOOST_NOEXCEPT
400 {detail::resize_file(p, size, &ec);}
402 path relative(const path& p, const path& base=current_path())
403 {return detail::relative(p, base);}
405 path relative(const path& p, system::error_code& ec)
406 {return detail::relative(p, current_path(), &ec);}
408 path relative(const path& p, const path& base, system::error_code& ec)
409 {return detail::relative(p, base, &ec);}
411 space_info space(const path& p) {return detail::space(p);}
414 space_info space(const path& p, system::error_code& ec) BOOST_NOEXCEPT
415 {return detail::space(p, &ec);}
417 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
418 inline bool symbolic_link_exists(const path& p)
419 { return is_symlink(filesystem::symlink_status(p)); }
423 path system_complete(const path& p) {return detail::system_complete(p);}
426 path system_complete(const path& p, system::error_code& ec)
427 {return detail::system_complete(p, &ec);}
429 path temp_directory_path() {return detail::temp_directory_path();}
432 path temp_directory_path(system::error_code& ec)
433 {return detail::temp_directory_path(&ec);}
435 path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%")
436 {return detail::unique_path(p);}
438 path unique_path(const path& p, system::error_code& ec)
439 {return detail::unique_path(p, &ec);}
441 path weakly_canonical(const path& p) {return detail::weakly_canonical(p);}
444 path weakly_canonical(const path& p, system::error_code& ec)
445 {return detail::weakly_canonical(p, &ec);}
447 // test helper -----------------------------------------------------------------------//
449 // Not part of the documented interface since false positives are possible;
450 // there is no law that says that an OS that has large stat.st_size
451 // actually supports large file sizes.
455 BOOST_FILESYSTEM_DECL bool possible_large_file_size_support();
457 } // namespace detail
459 } // namespace filesystem
462 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
463 #endif // BOOST_FILESYSTEM3_OPERATIONS_HPP