Skip to content

Commit

Permalink
Using internal copy_file instead of the boost one, to not fail with w…
Browse files Browse the repository at this point in the history
…eird filesystems.

#2938
  • Loading branch information
supermerill committed Jul 24, 2022
1 parent 0ad13b9 commit ff1e1b3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/libslic3r/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ void AppConfig::init_ui_layout() {
//copy all resources that aren't in datadir or newer
std::string current_name = get("ui_layout");
bool find_current = false;
std::string error_message;
for (const auto& layout : resources_map) {
auto it_datadir_layout = datadir_map.find(layout.first);
if (it_datadir_layout != datadir_map.end()) {
Expand All @@ -665,7 +666,8 @@ void AppConfig::init_ui_layout() {
boost::filesystem::remove_all(file.path());
}
for (boost::filesystem::directory_entry& file : boost::filesystem::directory_iterator(layout.second.path)) {
boost::filesystem::copy_file(file.path(), it_datadir_layout->second.path / file.path().filename());
if (copy_file_inner(file.path(), it_datadir_layout->second.path / file.path().filename(), error_message))
throw FileIOError(error_message);
}
//update for saving
it_datadir_layout->second.version = layout.second.version;
Expand All @@ -679,7 +681,8 @@ void AppConfig::init_ui_layout() {
std::time_t datadir_last_mod = boost::filesystem::last_write_time(datadir_path);
if (datadir_last_mod < resources_last_mod) {
boost::filesystem::remove_all(datadir_path);
boost::filesystem::copy_file(resources_file.path(), datadir_path);
if (copy_file_inner(resources_file.path(), datadir_path, error_message))
throw FileIOError(error_message);
}
}

Expand All @@ -688,7 +691,8 @@ void AppConfig::init_ui_layout() {
// Doesn't exists, copy
boost::filesystem::create_directory(data_dir_path / layout.second.path.filename());
for (boost::filesystem::directory_entry& file : boost::filesystem::directory_iterator(layout.second.path)) {
boost::filesystem::copy_file(file.path(), data_dir_path / layout.second.path.filename() / file.path().filename());
if (copy_file_inner(file.path(), data_dir_path / layout.second.path.filename() / file.path().filename(), error_message))
throw FileIOError(error_message);
}
//update for saving
datadir_map[layout.first] = layout.second;
Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ enum CopyFileResult {
FAIL_CHECK_TARGET_NOT_OPENED
};
// Copy a file, adjust the access attributes, so that the target is writable.
CopyFileResult copy_file_inner(const std::string &from, const std::string &to, std::string& error_message);
CopyFileResult copy_file_inner(const std::string& from, const std::string& to, std::string& error_message);
CopyFileResult copy_file_inner(const boost::filesystem::path& from, const boost::filesystem::path& to, std::string& error_message);
// Copy file to a temp file first, then rename it to the final file name.
// If with_check is true, then the content of the copied file is compared to the content
// of the source file before renaming.
Expand Down
5 changes: 5 additions & 0 deletions src/libslic3r/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,11 @@ CopyFileResult copy_file_inner(const std::string& from, const std::string& to, s
{
const boost::filesystem::path source(from);
const boost::filesystem::path target(to);
return copy_file_inner(source, target, error_message);
}

CopyFileResult copy_file_inner(const boost::filesystem::path& source, const boost::filesystem::path& target, std::string& error_message)
{
static const auto perms = boost::filesystem::owner_read | boost::filesystem::owner_write | boost::filesystem::group_read | boost::filesystem::others_read; // aka 644

// Make sure the file has correct permission both before and after we copy over it.
Expand Down
16 changes: 11 additions & 5 deletions src/slic3r/GUI/GalleryDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ void GalleryDialog::change_thumbnail()
png_path.replace_extension("png");

fs::path current = fs::path(into_u8(input_files.Item(0)));
fs::copy_file(current, png_path, fs::copy_option::overwrite_if_exists);
std::string error_msg;
if (copy_file_inner(current, png_path, error_msg))
throw FileIOError(error_msg);
}
catch (fs::filesystem_error const& e) {
std::cerr << e.what() << '\n';
Expand Down Expand Up @@ -560,9 +562,11 @@ bool GalleryDialog::load_files(const wxArrayString& input_files)

try {
fs::path current = fs::path(input_file);
if (!fs::exists(dest_dir / current.filename()))
fs::copy_file(current, dest_dir / current.filename());
else {
if (!fs::exists(dest_dir / current.filename())) {
std::string error_msg;
if (copy_file_inner(current, dest_dir / current.filename(), error_msg))
throw FileIOError(error_msg);
} else {
std::string filename = current.stem().string();

int file_idx = 0;
Expand All @@ -584,7 +588,9 @@ bool GalleryDialog::load_files(const wxArrayString& input_files)
}
if (file_idx > 0) {
filename += " (" + std::to_string(file_idx) + ")." + (is_gallery_file(input_file, ".stl") ? "stl" : "obj");
fs::copy_file(current, dest_dir / filename);
std::string error_msg;
if (copy_file_inner(current, dest_dir / filename, error_msg))
throw FileIOError(error_msg);
}
}
}
Expand Down

0 comments on commit ff1e1b3

Please sign in to comment.