summaryrefslogtreecommitdiff
path: root/src/filesystem.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-10-06 02:04:49 +0200
committerCarl Hetherington <cth@carlh.net>2023-10-09 01:20:01 +0200
commite4b2ebd80779a44d24fe87af26ef278c1e2d97d2 (patch)
tree3bc940c5eb49c96c3c18a896c8ccd8039e6db839 /src/filesystem.h
parent3be26a66645de04c7b220abeebfd2f024990a696 (diff)
Add wrappers around boost::filesystem methods that handle the
required mangling of long filenames on Windows. Also wrap lots of missing places (e.g. calls to asdcplib, libxml++, libcxml etc.) in dcp::filesystem::fix_long_path(). The idea is to keep paths un-mangled until they we call some filesystem-related API and mangle them at that point. Otherwise we end up serialising mangled names, which seems like it will not end well. Should fix DoM #2623.
Diffstat (limited to 'src/filesystem.h')
-rw-r--r--src/filesystem.h124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/filesystem.h b/src/filesystem.h
new file mode 100644
index 00000000..d9fb2791
--- /dev/null
+++ b/src/filesystem.h
@@ -0,0 +1,124 @@
+/*
+ Copyright (C) 2012-2023 Carl Hetherington <cth@carlh.net>
+
+ This file is part of libdcp.
+
+ libdcp 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 2 of the License, or
+ (at your option) any later version.
+
+ libdcp 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.
+
+ You should have received a copy of the GNU General Public License
+ along with libdcp. If not, see <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+*/
+
+
+#ifndef LIBDCP_FILESYSTEM_H
+#define LIBDCP_FILESYSTEM_H
+
+
+#include <boost/filesystem.hpp>
+
+
+namespace dcp
+{
+namespace filesystem
+{
+
+boost::filesystem::path absolute(boost::filesystem::path const& path);
+boost::filesystem::path canonical(boost::filesystem::path const& path);
+void copy(boost::filesystem::path const& from, boost::filesystem::path const& to);
+void copy_file(boost::filesystem::path const& from, boost::filesystem::path const& to);
+bool create_directory(boost::filesystem::path const& path);
+bool create_directories(boost::filesystem::path const& path);
+void create_hard_link(boost::filesystem::path const& from, boost::filesystem::path const& to);
+void current_path(boost::filesystem::path const& path);
+boost::filesystem::path current_path();
+bool exists(boost::filesystem::path const& path);
+bool is_regular_file(boost::filesystem::path const& path);
+uintmax_t file_size(boost::filesystem::path const& path);
+uintmax_t remove_all(boost::filesystem::path const& path);
+
+
+class directory_entry
+{
+public:
+ directory_entry() {}
+ directory_entry(boost::filesystem::path const& path);
+
+ boost::filesystem::path path() const;
+ operator boost::filesystem::path const&() const;
+
+private:
+ boost::filesystem::path _path;
+};
+
+
+class directory_iterator
+{
+public:
+ directory_iterator() = default;
+ directory_iterator(boost::filesystem::path const& path);
+
+ directory_iterator& operator++();
+ directory_entry operator*() const;
+ bool operator!=(directory_iterator const& other) const;
+
+private:
+ boost::filesystem::directory_iterator _wrapped;
+};
+
+
+directory_iterator const& begin(directory_iterator const& iter);
+directory_iterator end(directory_iterator const&);
+
+
+
+class recursive_directory_iterator
+{
+public:
+ recursive_directory_iterator() = default;
+ recursive_directory_iterator(boost::filesystem::path const& path);
+
+ recursive_directory_iterator& operator++();
+ directory_entry operator*() const;
+ directory_entry* operator->() const;
+ bool operator!=(recursive_directory_iterator const& other) const;
+
+private:
+ boost::filesystem::recursive_directory_iterator _wrapped;
+ mutable directory_entry _entry;
+};
+
+
+recursive_directory_iterator const& begin(recursive_directory_iterator const& iter);
+recursive_directory_iterator end(recursive_directory_iterator const&);
+
+
+boost::filesystem::path fix_long_path(boost::filesystem::path long_path);
+boost::filesystem::path unfix_long_path(boost::filesystem::path long_path);
+
+}
+}
+
+
+#endif