Add more filesystem wrappers that DoM needs. v1.8.83
authorCarl Hetherington <cth@carlh.net>
Fri, 6 Oct 2023 00:31:12 +0000 (02:31 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 8 Oct 2023 23:20:06 +0000 (01:20 +0200)
src/filesystem.cc
src/filesystem.h

index 0dd89228eade553360eac89a7c562ab344634d99..0ebe7cf71681badc22aedbeda8132a4f8497d87b 100644 (file)
@@ -43,6 +43,27 @@ dcp::filesystem::exists(boost::filesystem::path const& path)
 }
 
 
+bool
+dcp::filesystem::exists(boost::filesystem::path const& path, boost::system::error_code& ec)
+{
+       return boost::filesystem::exists(dcp::filesystem::fix_long_path(path), ec);
+}
+
+
+bool
+dcp::filesystem::is_directory(boost::filesystem::path const& path)
+{
+       return boost::filesystem::is_directory(dcp::filesystem::fix_long_path(path));
+}
+
+
+bool
+dcp::filesystem::is_empty(boost::filesystem::path const& path)
+{
+       return boost::filesystem::is_empty(dcp::filesystem::fix_long_path(path));
+}
+
+
 bool
 dcp::filesystem::is_regular_file(boost::filesystem::path const& path)
 {
@@ -57,6 +78,13 @@ dcp::filesystem::create_directory(boost::filesystem::path const& path)
 }
 
 
+bool
+dcp::filesystem::create_directory(boost::filesystem::path const& path, boost::system::error_code& ec)
+{
+       return boost::filesystem::create_directory(dcp::filesystem::fix_long_path(path), ec);
+}
+
+
 void
 dcp::filesystem::copy(boost::filesystem::path const& from, boost::filesystem::path const& to)
 {
@@ -71,6 +99,20 @@ dcp::filesystem::copy_file(boost::filesystem::path const& from, boost::filesyste
 }
 
 
+void
+dcp::filesystem::copy_file(boost::filesystem::path const& from, boost::filesystem::path const& to, boost::system::error_code& ec)
+{
+       boost::filesystem::copy_file(dcp::filesystem::fix_long_path(from), dcp::filesystem::fix_long_path(to), ec);
+}
+
+
+void
+dcp::filesystem::copy_file(boost::filesystem::path const& from, boost::filesystem::path const& to, boost::filesystem::copy_option option)
+{
+       boost::filesystem::copy_file(dcp::filesystem::fix_long_path(from), dcp::filesystem::fix_long_path(to), option);
+}
+
+
 bool
 dcp::filesystem::create_directories(boost::filesystem::path const& path)
 {
@@ -78,6 +120,13 @@ dcp::filesystem::create_directories(boost::filesystem::path const& path)
 }
 
 
+bool
+dcp::filesystem::create_directories(boost::filesystem::path const& path, boost::system::error_code& ec)
+{
+       return boost::filesystem::create_directories(dcp::filesystem::fix_long_path(path), ec);
+}
+
+
 boost::filesystem::path
 dcp::filesystem::absolute(boost::filesystem::path const& path)
 {
@@ -92,6 +141,27 @@ dcp::filesystem::canonical(boost::filesystem::path const& path)
 }
 
 
+boost::filesystem::path
+dcp::filesystem::weakly_canonical(boost::filesystem::path const& path)
+{
+       return dcp::filesystem::unfix_long_path(boost::filesystem::weakly_canonical(dcp::filesystem::fix_long_path(path)));
+}
+
+
+bool
+dcp::filesystem::remove(boost::filesystem::path const& path)
+{
+       return boost::filesystem::remove(dcp::filesystem::fix_long_path(path));
+}
+
+
+bool
+dcp::filesystem::remove(boost::filesystem::path const& path, boost::system::error_code& ec)
+{
+       return boost::filesystem::remove(dcp::filesystem::fix_long_path(path), ec);
+}
+
+
 uintmax_t
 dcp::filesystem::remove_all(boost::filesystem::path const& path)
 {
@@ -99,6 +169,13 @@ dcp::filesystem::remove_all(boost::filesystem::path const& path)
 }
 
 
+uintmax_t
+dcp::filesystem::remove_all(boost::filesystem::path const& path, boost::system::error_code& ec)
+{
+       return boost::filesystem::remove_all(dcp::filesystem::fix_long_path(path), ec);
+}
+
+
 uintmax_t
 dcp::filesystem::file_size(boost::filesystem::path const& path)
 {
@@ -106,6 +183,13 @@ dcp::filesystem::file_size(boost::filesystem::path const& path)
 }
 
 
+uintmax_t
+dcp::filesystem::file_size(boost::filesystem::path const& path, boost::system::error_code& ec)
+{
+       return boost::filesystem::file_size(dcp::filesystem::fix_long_path(path), ec);
+}
+
+
 boost::filesystem::path
 dcp::filesystem::current_path()
 {
@@ -127,6 +211,77 @@ dcp::filesystem::create_hard_link(boost::filesystem::path const& from, boost::fi
 }
 
 
+void
+dcp::filesystem::create_hard_link(boost::filesystem::path const& from, boost::filesystem::path const& to, boost::system::error_code& ec)
+{
+       boost::filesystem::create_hard_link(dcp::filesystem::fix_long_path(from), dcp::filesystem::fix_long_path(to), ec);
+}
+
+
+void
+dcp::filesystem::create_symlink(boost::filesystem::path const& from, boost::filesystem::path const& to, boost::system::error_code& ec)
+{
+       boost::filesystem::create_symlink(dcp::filesystem::fix_long_path(from), dcp::filesystem::fix_long_path(to), ec);
+}
+
+
+std::string
+dcp::filesystem::extension(boost::filesystem::path const& path)
+{
+       return boost::filesystem::extension(dcp::filesystem::fix_long_path(path));
+}
+
+
+boost::filesystem::space_info
+dcp::filesystem::space(boost::filesystem::path const& path)
+{
+       return boost::filesystem::space(dcp::filesystem::fix_long_path(path));
+}
+
+
+std::time_t
+dcp::filesystem::last_write_time(boost::filesystem::path const& path)
+{
+       return boost::filesystem::last_write_time(dcp::filesystem::fix_long_path(path));
+}
+
+
+std::time_t
+dcp::filesystem::last_write_time(boost::filesystem::path const& path, boost::system::error_code& ec)
+{
+       return boost::filesystem::last_write_time(dcp::filesystem::fix_long_path(path), ec);
+}
+
+
+uintmax_t
+dcp::filesystem::hard_link_count(boost::filesystem::path const& path)
+{
+       return boost::filesystem::hard_link_count(dcp::filesystem::fix_long_path(path));
+}
+
+
+void
+dcp::filesystem::rename(boost::filesystem::path const& old_path, boost::filesystem::path const& new_path)
+{
+       boost::filesystem::rename(dcp::filesystem::fix_long_path(old_path), dcp::filesystem::fix_long_path(new_path));
+}
+
+
+void
+dcp::filesystem::rename(boost::filesystem::path const& old_path, boost::filesystem::path const& new_path, boost::system::error_code& ec)
+{
+       boost::filesystem::rename(dcp::filesystem::fix_long_path(old_path), dcp::filesystem::fix_long_path(new_path), ec);
+}
+
+
+/* We don't really need this but let's add it for completeness */
+boost::filesystem::path
+dcp::filesystem::change_extension(boost::filesystem::path const& path, std::string const& new_extension)
+{
+       return boost::filesystem::change_extension(path, new_extension);
+}
+
+
 #ifdef DCPOMATIC_WINDOWS
 
 dcp::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const& path)
@@ -136,6 +291,13 @@ dcp::filesystem::directory_iterator::directory_iterator(boost::filesystem::path
 }
 
 
+dcp::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const& path, boost::system::error_code& ec)
+       : _wrapped(dcp::filesystem::fix_long_path(path), ec)
+{
+
+}
+
+
 boost::filesystem::path
 dcp::filesystem::directory_entry::path() const
 {
@@ -164,6 +326,13 @@ dcp::filesystem::directory_iterator::directory_iterator(boost::filesystem::path
 }
 
 
+dcp::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const& path, boost::system::error_code& ec)
+       : _wrapped(path, ec)
+{
+
+}
+
+
 boost::filesystem::path
 dcp::filesystem::directory_entry::path() const
 {
@@ -204,10 +373,18 @@ dcp::filesystem::directory_iterator::operator++()
 dcp::filesystem::directory_entry
 dcp::filesystem::directory_iterator::operator*() const
 {
-       return dcp::filesystem::directory_entry(*_wrapped);
+       _entry = dcp::filesystem::directory_entry(*_wrapped);
+       return _entry;
 }
 
 
+dcp::filesystem::directory_entry*
+dcp::filesystem::directory_iterator::operator->() const
+{
+       _entry = dcp::filesystem::directory_entry(_wrapped->path());
+       return &_entry;
+}
+
 bool
 dcp::filesystem::directory_iterator::operator!=(dcp::filesystem::directory_iterator const& other) const
 {
index d9fb2791c47b571b26b54da17796dbb31ddaa864..53ec209dfab9adad99b2e2f6a44d67f0c6d39420 100644 (file)
@@ -46,17 +46,39 @@ namespace filesystem
 
 boost::filesystem::path absolute(boost::filesystem::path const& path);
 boost::filesystem::path canonical(boost::filesystem::path const& path);
+boost::filesystem::path weakly_canonical(boost::filesystem::path const& path);
+boost::filesystem::path change_extension(boost::filesystem::path const& from, std::string const& new_extension);
 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);
+void copy_file(boost::filesystem::path const& from, boost::filesystem::path const& to, boost::system::error_code& ec);
+void copy_file(boost::filesystem::path const& from, boost::filesystem::path const& to, boost::filesystem::copy_option ec);
 bool create_directory(boost::filesystem::path const& path);
+bool create_directory(boost::filesystem::path const& path, boost::system::error_code& ec);
 bool create_directories(boost::filesystem::path const& path);
+bool create_directories(boost::filesystem::path const& path, boost::system::error_code& ec);
 void create_hard_link(boost::filesystem::path const& from, boost::filesystem::path const& to);
+void create_hard_link(boost::filesystem::path const& from, boost::filesystem::path const& to, boost::system::error_code& ec);
+void create_symlink(boost::filesystem::path const& from, boost::filesystem::path const& to, boost::system::error_code& ec);
 void current_path(boost::filesystem::path const& path);
 boost::filesystem::path current_path();
 bool exists(boost::filesystem::path const& path);
+bool exists(boost::filesystem::path const& path, boost::system::error_code& ec);
+std::string extension(boost::filesystem::path const& path);
+bool is_directory(boost::filesystem::path const& path);
+bool is_empty(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 file_size(boost::filesystem::path const& path, boost::system::error_code& ec);
+uintmax_t hard_link_count(boost::filesystem::path const& path);
+std::time_t last_write_time(boost::filesystem::path const& path);
+std::time_t last_write_time(boost::filesystem::path const& path, boost::system::error_code& ec);
+bool remove(boost::filesystem::path const& path);
+bool remove(boost::filesystem::path const& path, boost::system::error_code& ec);
 uintmax_t remove_all(boost::filesystem::path const& path);
+uintmax_t remove_all(boost::filesystem::path const& path, boost::system::error_code& ec);
+void rename(boost::filesystem::path const& old_path, boost::filesystem::path const& new_path);
+void rename(boost::filesystem::path const& old_path, boost::filesystem::path const& new_path, boost::system::error_code& ec);
+boost::filesystem::space_info space(boost::filesystem::path const& path);
 
 
 class directory_entry
@@ -78,13 +100,16 @@ class directory_iterator
 public:
        directory_iterator() = default;
        directory_iterator(boost::filesystem::path const& path);
+       directory_iterator(boost::filesystem::path const& path, boost::system::error_code& ec);
 
        directory_iterator& operator++();
        directory_entry operator*() const;
+       directory_entry* operator->() const;
        bool operator!=(directory_iterator const& other) const;
 
 private:
        boost::filesystem::directory_iterator _wrapped;
+       mutable directory_entry _entry;
 };