d9fb2791c47b571b26b54da17796dbb31ddaa864
[libdcp.git] / src / filesystem.h
1 /*
2     Copyright (C) 2012-2023 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 #ifndef LIBDCP_FILESYSTEM_H
36 #define LIBDCP_FILESYSTEM_H
37
38
39 #include <boost/filesystem.hpp>
40
41
42 namespace dcp
43 {
44 namespace filesystem
45 {
46
47 boost::filesystem::path absolute(boost::filesystem::path const& path);
48 boost::filesystem::path canonical(boost::filesystem::path const& path);
49 void copy(boost::filesystem::path const& from, boost::filesystem::path const& to);
50 void copy_file(boost::filesystem::path const& from, boost::filesystem::path const& to);
51 bool create_directory(boost::filesystem::path const& path);
52 bool create_directories(boost::filesystem::path const& path);
53 void create_hard_link(boost::filesystem::path const& from, boost::filesystem::path const& to);
54 void current_path(boost::filesystem::path const& path);
55 boost::filesystem::path current_path();
56 bool exists(boost::filesystem::path const& path);
57 bool is_regular_file(boost::filesystem::path const& path);
58 uintmax_t file_size(boost::filesystem::path const& path);
59 uintmax_t remove_all(boost::filesystem::path const& path);
60
61
62 class directory_entry
63 {
64 public:
65         directory_entry() {}
66         directory_entry(boost::filesystem::path const& path);
67
68         boost::filesystem::path path() const;
69         operator boost::filesystem::path const&() const;
70
71 private:
72         boost::filesystem::path _path;
73 };
74
75
76 class directory_iterator
77 {
78 public:
79         directory_iterator() = default;
80         directory_iterator(boost::filesystem::path const& path);
81
82         directory_iterator& operator++();
83         directory_entry operator*() const;
84         bool operator!=(directory_iterator const& other) const;
85
86 private:
87         boost::filesystem::directory_iterator _wrapped;
88 };
89
90
91 directory_iterator const& begin(directory_iterator const& iter);
92 directory_iterator end(directory_iterator const&);
93
94
95
96 class recursive_directory_iterator
97 {
98 public:
99         recursive_directory_iterator() = default;
100         recursive_directory_iterator(boost::filesystem::path const& path);
101
102         recursive_directory_iterator& operator++();
103         directory_entry operator*() const;
104         directory_entry* operator->() const;
105         bool operator!=(recursive_directory_iterator const& other) const;
106
107 private:
108         boost::filesystem::recursive_directory_iterator _wrapped;
109         mutable directory_entry _entry;
110 };
111
112
113 recursive_directory_iterator const& begin(recursive_directory_iterator const& iter);
114 recursive_directory_iterator end(recursive_directory_iterator const&);
115
116
117 boost::filesystem::path fix_long_path(boost::filesystem::path long_path);
118 boost::filesystem::path unfix_long_path(boost::filesystem::path long_path);
119
120 }
121 }
122
123
124 #endif