641cb5a675
Based on Filesystem TS implementation, with the changes applied by: - P0219R1 Relative Paths for Filesystem - P0317R1 Directory Entry Caching for Filesystem - P0492R2 Resolution of C++17 National Body Comments Where appropriate code is shared between the TS and C++17 implementations. * include/Makefile.am: Add new headers for C++17 filesystem library. * include/Makefile.in: Regenerate. * include/bits/fs_dir.h: New header, based on Filesystem TS code in include/experimental/bits directory. * include/bits/fs_fwd.h: Likewise. * include/bits/fs_ops.h: Likewise. * include/bits/fs_path.h: Likewise. * include/experimental/bits/fs_dir.h: Rename Doxygen group. * include/experimental/bits/fs_fwd.h: Likewise. * include/experimental/bits/fs_ops.h: Likewise. * include/experimental/bits/fs_path.h: Likewise. * include/experimental/filesystem (filesystem_error::_M_gen_what): Remove inline definition. * include/precompiled/stdc++.h: Add <filesystem> to precompiled header. * include/std/filesystem: New header. * python/libstdcxx/v6/printers.py: Enable printer for std::filesystem paths. * src/filesystem/Makefile.am: Add new files. Compile as C++17. * src/filesystem/Makefile.in: Regenerate. * src/filesystem/cow-dir.cc: Update comment. * src/filesystem/cow-ops.cc: Likewise. * src/filesystem/cow-path.cc: Likewise. * src/filesystem/cow-std-dir.cc: New file. * src/filesystem/cow-std-ops.cc: New file. * src/filesystem/cow-std-path.cc: New file. * src/filesystem/dir-common.h (_Dir_base, get_file_type): New header for common code. * src/filesystem/dir.cc (_Dir): Derive from _Dir_base. (open_dir): Move to _Dir_base constructor. (get_file_type): Move to dir-common.h. (recurse): Move to _Dir_base::should_recurse. * src/filesystem/ops-common.h: New header for common code. * src/filesystem/ops.cc (is_set, make_file_type, make_file_status) (is_not_found_errno, file_time, do_copy_file): Move to ops-common.h. * src/filesystem/path.cc (filesystem_error::_M_gen_what): Define. * src/filesystem/std-dir.cc: New file, based on Filesystem TS code. * src/filesystem/std-ops.cc: Likewise. * src/filesystem/std-dir.cc: Likewise. * testsuite/27_io/filesystem/iterators/directory_iterator.cc: New test. * testsuite/27_io/filesystem/iterators/pop.cc: New test. * testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc: New test. * testsuite/27_io/filesystem/operations/absolute.cc: New test. * testsuite/27_io/filesystem/operations/canonical.cc: New test. * testsuite/27_io/filesystem/operations/copy.cc: New test. * testsuite/27_io/filesystem/operations/copy_file.cc: New test. * testsuite/27_io/filesystem/operations/create_directories.cc: New test. * testsuite/27_io/filesystem/operations/create_directory.cc: New test. * testsuite/27_io/filesystem/operations/create_symlink.cc: New test. * testsuite/27_io/filesystem/operations/current_path.cc: New test. * testsuite/27_io/filesystem/operations/equivalent.cc: New test. * testsuite/27_io/filesystem/operations/exists.cc: New test. * testsuite/27_io/filesystem/operations/file_size.cc: New test. * testsuite/27_io/filesystem/operations/is_empty.cc: New test. * testsuite/27_io/filesystem/operations/last_write_time.cc: New test. * testsuite/27_io/filesystem/operations/permissions.cc: New test. * testsuite/27_io/filesystem/operations/proximate.cc: New test. * testsuite/27_io/filesystem/operations/read_symlink.cc: New test. * testsuite/27_io/filesystem/operations/relative.cc: New test. * testsuite/27_io/filesystem/operations/remove_all.cc: New test. * testsuite/27_io/filesystem/operations/space.cc: New test. * testsuite/27_io/filesystem/operations/status.cc: New test. * testsuite/27_io/filesystem/operations/symlink_status.cc: New test. * testsuite/27_io/filesystem/operations/temp_directory_path.cc: New test. * testsuite/27_io/filesystem/operations/weakly_canonical.cc: New test. * testsuite/27_io/filesystem/path/append/path.cc: New test. * testsuite/27_io/filesystem/path/assign/assign.cc: New test. * testsuite/27_io/filesystem/path/assign/copy.cc: New test. * testsuite/27_io/filesystem/path/compare/compare.cc: New test. * testsuite/27_io/filesystem/path/compare/path.cc: New test. * testsuite/27_io/filesystem/path/compare/strings.cc: New test. * testsuite/27_io/filesystem/path/concat/path.cc: New test. * testsuite/27_io/filesystem/path/concat/strings.cc: New test. * testsuite/27_io/filesystem/path/construct/copy.cc: New test. * testsuite/27_io/filesystem/path/construct/default.cc: New test. * testsuite/27_io/filesystem/path/construct/locale.cc: New test. * testsuite/27_io/filesystem/path/construct/range.cc: New test. * testsuite/27_io/filesystem/path/construct/string_view.cc: New test. * testsuite/27_io/filesystem/path/decompose/extension.cc: New test. * testsuite/27_io/filesystem/path/decompose/filename.cc: New test. * testsuite/27_io/filesystem/path/decompose/parent_path.cc: New test. * testsuite/27_io/filesystem/path/decompose/relative_path.cc: New test. * testsuite/27_io/filesystem/path/decompose/root_directory.cc: New test. * testsuite/27_io/filesystem/path/decompose/root_name.cc: New test. * testsuite/27_io/filesystem/path/decompose/root_path.cc: New test. * testsuite/27_io/filesystem/path/decompose/stem.cc: New test. * testsuite/27_io/filesystem/path/generation/normal.cc: New test. * testsuite/27_io/filesystem/path/generation/proximate.cc: New test. * testsuite/27_io/filesystem/path/generation/relative.cc: New test. * testsuite/27_io/filesystem/path/generic/generic_string.cc: New test. * testsuite/27_io/filesystem/path/itr/traversal.cc: New test. * testsuite/27_io/filesystem/path/modifiers/clear.cc: New test. * testsuite/27_io/filesystem/path/modifiers/make_preferred.cc: New test. * testsuite/27_io/filesystem/path/modifiers/remove_filename.cc: New test. * testsuite/27_io/filesystem/path/modifiers/replace_extension.cc: New test. * testsuite/27_io/filesystem/path/modifiers/replace_filename.cc: New test. * testsuite/27_io/filesystem/path/modifiers/swap.cc: New test. * testsuite/27_io/filesystem/path/native/string.cc: New test. * testsuite/27_io/filesystem/path/nonmember/hash_value.cc: New test. * testsuite/27_io/filesystem/path/query/empty.cc: New test. * testsuite/27_io/filesystem/path/query/has_extension.cc: New test. * testsuite/27_io/filesystem/path/query/has_filename.cc: New test. * testsuite/27_io/filesystem/path/query/has_parent_path.cc: New test. * testsuite/27_io/filesystem/path/query/has_relative_path.cc: New test. * testsuite/27_io/filesystem/path/query/has_root_directory.cc: New test. * testsuite/27_io/filesystem/path/query/has_root_name.cc: New test. * testsuite/27_io/filesystem/path/query/has_root_path.cc: New test. * testsuite/27_io/filesystem/path/query/has_stem.cc: New test. * testsuite/27_io/filesystem/path/query/is_relative.cc: New test. * testsuite/experimental/filesystem/path/construct/string_view.cc: Define USE_FILESYSTEM_TS. * testsuite/util/testsuite_fs.h: Allow use with C++17 paths as well as Filesystem TS. From-SVN: r254008
349 lines
10 KiB
C++
349 lines
10 KiB
C++
// Filesystem declarations -*- C++ -*-
|
|
|
|
// Copyright (C) 2014-2017 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 3, or (at your option)
|
|
// any later version.
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
// 3.1, as published by the Free Software Foundation.
|
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
/** @file include/bits/fs_fwd.h
|
|
* This is an internal header file, included by other library headers.
|
|
* Do not attempt to use it directly. @headername{filesystem}
|
|
*/
|
|
|
|
#ifndef _GLIBCXX_FS_FWD_H
|
|
#define _GLIBCXX_FS_FWD_H 1
|
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
#include <system_error>
|
|
#include <cstdint>
|
|
#include <chrono>
|
|
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
|
{
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
|
namespace filesystem
|
|
{
|
|
#if _GLIBCXX_USE_CXX11_ABI
|
|
inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
|
|
#endif
|
|
|
|
/**
|
|
* @defgroup filesystem Filesystem
|
|
*
|
|
* Utilities for performing operations on file systems and their components,
|
|
* such as paths, regular files, and directories.
|
|
*
|
|
* @{
|
|
*/
|
|
|
|
class file_status;
|
|
_GLIBCXX_BEGIN_NAMESPACE_CXX11
|
|
class path;
|
|
class filesystem_error;
|
|
class directory_entry;
|
|
class directory_iterator;
|
|
class recursive_directory_iterator;
|
|
_GLIBCXX_END_NAMESPACE_CXX11
|
|
|
|
struct space_info
|
|
{
|
|
uintmax_t capacity;
|
|
uintmax_t free;
|
|
uintmax_t available;
|
|
};
|
|
|
|
enum class file_type : signed char {
|
|
none = 0, not_found = -1, regular = 1, directory = 2, symlink = 3,
|
|
block = 4, character = 5, fifo = 6, socket = 7, unknown = 8
|
|
};
|
|
|
|
/// Bitmask type
|
|
enum class copy_options : unsigned short {
|
|
none = 0,
|
|
skip_existing = 1, overwrite_existing = 2, update_existing = 4,
|
|
recursive = 8,
|
|
copy_symlinks = 16, skip_symlinks = 32,
|
|
directories_only = 64, create_symlinks = 128, create_hard_links = 256
|
|
};
|
|
|
|
constexpr copy_options
|
|
operator&(copy_options __x, copy_options __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<copy_options>::type;
|
|
return static_cast<copy_options>(
|
|
static_cast<__utype>(__x) & static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr copy_options
|
|
operator|(copy_options __x, copy_options __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<copy_options>::type;
|
|
return static_cast<copy_options>(
|
|
static_cast<__utype>(__x) | static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr copy_options
|
|
operator^(copy_options __x, copy_options __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<copy_options>::type;
|
|
return static_cast<copy_options>(
|
|
static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr copy_options
|
|
operator~(copy_options __x) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<copy_options>::type;
|
|
return static_cast<copy_options>(~static_cast<__utype>(__x));
|
|
}
|
|
|
|
inline copy_options&
|
|
operator&=(copy_options& __x, copy_options __y) noexcept
|
|
{ return __x = __x & __y; }
|
|
|
|
inline copy_options&
|
|
operator|=(copy_options& __x, copy_options __y) noexcept
|
|
{ return __x = __x | __y; }
|
|
|
|
inline copy_options&
|
|
operator^=(copy_options& __x, copy_options __y) noexcept
|
|
{ return __x = __x ^ __y; }
|
|
|
|
|
|
/// Bitmask type
|
|
enum class perms : unsigned {
|
|
none = 0,
|
|
owner_read = 0400,
|
|
owner_write = 0200,
|
|
owner_exec = 0100,
|
|
owner_all = 0700,
|
|
group_read = 040,
|
|
group_write = 020,
|
|
group_exec = 010,
|
|
group_all = 070,
|
|
others_read = 04,
|
|
others_write = 02,
|
|
others_exec = 01,
|
|
others_all = 07,
|
|
all = 0777,
|
|
set_uid = 04000,
|
|
set_gid = 02000,
|
|
sticky_bit = 01000,
|
|
mask = 07777,
|
|
unknown = 0xFFFF,
|
|
};
|
|
|
|
constexpr perms
|
|
operator&(perms __x, perms __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<perms>::type;
|
|
return static_cast<perms>(
|
|
static_cast<__utype>(__x) & static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr perms
|
|
operator|(perms __x, perms __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<perms>::type;
|
|
return static_cast<perms>(
|
|
static_cast<__utype>(__x) | static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr perms
|
|
operator^(perms __x, perms __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<perms>::type;
|
|
return static_cast<perms>(
|
|
static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr perms
|
|
operator~(perms __x) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<perms>::type;
|
|
return static_cast<perms>(~static_cast<__utype>(__x));
|
|
}
|
|
|
|
inline perms&
|
|
operator&=(perms& __x, perms __y) noexcept
|
|
{ return __x = __x & __y; }
|
|
|
|
inline perms&
|
|
operator|=(perms& __x, perms __y) noexcept
|
|
{ return __x = __x | __y; }
|
|
|
|
inline perms&
|
|
operator^=(perms& __x, perms __y) noexcept
|
|
{ return __x = __x ^ __y; }
|
|
|
|
/// Bitmask type
|
|
enum class perm_options : unsigned {
|
|
replace = 0x1,
|
|
add = 0x2,
|
|
remove = 0x4,
|
|
nofollow = 0x8
|
|
};
|
|
|
|
constexpr perm_options
|
|
operator&(perm_options __x, perm_options __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<perm_options>::type;
|
|
return static_cast<perm_options>(
|
|
static_cast<__utype>(__x) & static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr perm_options
|
|
operator|(perm_options __x, perm_options __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<perm_options>::type;
|
|
return static_cast<perm_options>(
|
|
static_cast<__utype>(__x) | static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr perm_options
|
|
operator^(perm_options __x, perm_options __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<perm_options>::type;
|
|
return static_cast<perm_options>(
|
|
static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr perm_options
|
|
operator~(perm_options __x) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<perm_options>::type;
|
|
return static_cast<perm_options>(~static_cast<__utype>(__x));
|
|
}
|
|
|
|
inline perm_options&
|
|
operator&=(perm_options& __x, perm_options __y) noexcept
|
|
{ return __x = __x & __y; }
|
|
|
|
inline perm_options&
|
|
operator|=(perm_options& __x, perm_options __y) noexcept
|
|
{ return __x = __x | __y; }
|
|
|
|
inline perm_options&
|
|
operator^=(perm_options& __x, perm_options __y) noexcept
|
|
{ return __x = __x ^ __y; }
|
|
|
|
// Bitmask type
|
|
enum class directory_options : unsigned char {
|
|
none = 0, follow_directory_symlink = 1, skip_permission_denied = 2
|
|
};
|
|
|
|
constexpr directory_options
|
|
operator&(directory_options __x, directory_options __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<directory_options>::type;
|
|
return static_cast<directory_options>(
|
|
static_cast<__utype>(__x) & static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr directory_options
|
|
operator|(directory_options __x, directory_options __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<directory_options>::type;
|
|
return static_cast<directory_options>(
|
|
static_cast<__utype>(__x) | static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr directory_options
|
|
operator^(directory_options __x, directory_options __y) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<directory_options>::type;
|
|
return static_cast<directory_options>(
|
|
static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
|
|
}
|
|
|
|
constexpr directory_options
|
|
operator~(directory_options __x) noexcept
|
|
{
|
|
using __utype = typename std::underlying_type<directory_options>::type;
|
|
return static_cast<directory_options>(~static_cast<__utype>(__x));
|
|
}
|
|
|
|
inline directory_options&
|
|
operator&=(directory_options& __x, directory_options __y) noexcept
|
|
{ return __x = __x & __y; }
|
|
|
|
inline directory_options&
|
|
operator|=(directory_options& __x, directory_options __y) noexcept
|
|
{ return __x = __x | __y; }
|
|
|
|
inline directory_options&
|
|
operator^=(directory_options& __x, directory_options __y) noexcept
|
|
{ return __x = __x ^ __y; }
|
|
|
|
using file_time_type = std::chrono::system_clock::time_point;
|
|
|
|
// operational functions
|
|
|
|
void copy(const path& __from, const path& __to, copy_options __options);
|
|
void copy(const path& __from, const path& __to, copy_options __options,
|
|
error_code&) noexcept;
|
|
|
|
bool copy_file(const path& __from, const path& __to, copy_options __option);
|
|
bool copy_file(const path& __from, const path& __to, copy_options __option,
|
|
error_code&) noexcept;
|
|
|
|
path current_path();
|
|
|
|
bool exists(file_status) noexcept;
|
|
|
|
bool is_other(file_status) noexcept;
|
|
|
|
uintmax_t file_size(const path&);
|
|
uintmax_t file_size(const path&, error_code&) noexcept;
|
|
uintmax_t hard_link_count(const path&);
|
|
uintmax_t hard_link_count(const path&, error_code&) noexcept;
|
|
file_time_type last_write_time(const path&);
|
|
file_time_type last_write_time(const path&, error_code&) noexcept;
|
|
|
|
void permissions(const path&, perms, perm_options, error_code&);
|
|
|
|
path proximate(const path& __p, const path& __base, error_code& __ec);
|
|
path proximate(const path& __p, const path& __base, error_code& __ec);
|
|
|
|
path relative(const path& __p, const path& __base, error_code& __ec);
|
|
|
|
file_status status(const path&);
|
|
file_status status(const path&, error_code&) noexcept;
|
|
|
|
bool status_known(file_status) noexcept;
|
|
|
|
file_status symlink_status(const path&);
|
|
file_status symlink_status(const path&, error_code&) noexcept;
|
|
|
|
bool is_regular_file(file_status) noexcept;
|
|
bool is_symlink(file_status) noexcept;
|
|
|
|
// @} group filesystem
|
|
} // namespace filesystem
|
|
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
|
} // namespace std
|
|
|
|
#endif // C++17
|
|
|
|
#endif // _GLIBCXX_FS_FWD_H
|