mirror of https://github.com/odrling/Aegisub
Remove use of copy_file from boost.filesystem
copy_file's signature varies depending on whether or not boost was compiled as C++11, which makes Linux packaging awkward. Closes #1580. Closes #1581.
This commit is contained in:
parent
6e62f9e461
commit
2db687cc31
|
@ -23,7 +23,9 @@
|
|||
#include "libaegisub/log.h"
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#define BOOST_NO_SCOPED_ENUMS
|
||||
#include <boost/filesystem.hpp>
|
||||
#undef BOOST_NO_SCOPED_ENUMS
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
namespace ec = boost::system::errc;
|
||||
|
@ -94,11 +96,6 @@ namespace agi { namespace fs {
|
|||
CHECKED_CALL(bfs::rename(from, to, ec), from, to);
|
||||
}
|
||||
|
||||
void Copy(path const& from, path const& to) {
|
||||
CreateDirectory(to.parent_path());
|
||||
CHECKED_CALL(bfs::copy_file(from, to, bfs::copy_option::overwrite_if_exists, ec), from, to);
|
||||
}
|
||||
|
||||
bool HasExtension(path const& p, std::string const& ext) {
|
||||
auto filename = p.filename().string();
|
||||
if (filename.size() < ext.size() + 1) return false;
|
||||
|
|
|
@ -61,6 +61,9 @@
|
|||
// Boost
|
||||
#include <boost/container/list.hpp>
|
||||
#include <boost/container/map.hpp>
|
||||
#define BOOST_NO_SCOPED_ENUMS
|
||||
#include <boost/filesystem.hpp>
|
||||
#undef BOOST_NO_SCOPED_ENUMS
|
||||
|
||||
#ifdef __DEPRECATED // Dodge GCC warnings
|
||||
# undef __DEPRECATED
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include "libaegisub/access.h"
|
||||
#include "libaegisub/fs.h"
|
||||
#include "libaegisub/io.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <fcntl.h>
|
||||
|
@ -40,6 +42,15 @@ void Touch(path const& file) {
|
|||
}
|
||||
}
|
||||
|
||||
void Copy(fs::path const& from, fs::path const& to) {
|
||||
acs::CheckFileRead(from);
|
||||
CreateDirectory(to.parent_path());
|
||||
acs::CheckDirWrite(to.parent_path());
|
||||
|
||||
std::unique_ptr<std::istream> in(io::Open(from, true));
|
||||
io::Save(to).Get() << in->rdbuf();
|
||||
}
|
||||
|
||||
struct DirectoryIterator::PrivData {
|
||||
boost::system::error_code ec;
|
||||
bfs::directory_iterator it;
|
||||
|
|
|
@ -72,6 +72,23 @@ void Touch(path const& file) {
|
|||
throw EnvironmentError("SetFileTime failed with error: " + util::ErrorString(GetLastError()));
|
||||
}
|
||||
|
||||
void Copy(fs::path const& from, fs::path const& to) {
|
||||
acs::CheckFileRead(from);
|
||||
CreateDirectory(to.parent_path());
|
||||
acs::CheckDirWrite(to.parent_path());
|
||||
|
||||
if (!CopyFile(from.wstring().c_str(), to.wstring().c_str(), false)) {
|
||||
switch (GetLastError()) {
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
throw FileNotFound(from);
|
||||
case ERROR_ACCESS_DENIED:
|
||||
throw fs::WriteDenied("Could not overwrite " + to.string());
|
||||
default:
|
||||
throw fs::WriteDenied("Could not copy: " + util::ErrorString(GetLastError()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DirectoryIterator::PrivData {
|
||||
scoped_holder<HANDLE, BOOL (__stdcall *)(HANDLE)> h;
|
||||
PrivData() : h(INVALID_HANDLE_VALUE, FindClose) { }
|
||||
|
|
Loading…
Reference in New Issue