Skip to content

Commit

Permalink
Do not overwrite non-image dir and check overwrite flag for image
Browse files Browse the repository at this point in the history
  • Loading branch information
pford committed May 24, 2024
1 parent a0efd33 commit bc2681e
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/Frame/Frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,7 @@ void Frame::SaveFile(const std::string& root_folder, const CARTA::SaveFile& save
fs::path output_filename(save_file_msg.output_file_name());
fs::path directory(save_file_msg.output_file_directory());
CARTA::FileType output_file_type(save_file_msg.output_file_type());
bool overwrite(save_file_msg.overwrite());

// Set response message
int file_id(save_file_msg.file_id());
Expand All @@ -1935,12 +1936,24 @@ void Frame::SaveFile(const std::string& root_folder, const CARTA::SaveFile& save
fs::path abs_path = fs::absolute(temp_path);
output_filename = abs_path / output_filename;

if (fs::exists(output_filename) && fs::is_directory(output_filename) &&
(CasacoreImageType(output_filename.string()) == casacore::ImageOpener::UNKNOWN)) {
message = "Cannot overwrite existing directory.";
save_file_ack.set_success(success);
save_file_ack.set_message(message);
return;
if (fs::exists(output_filename)) {
if (output_filename.string() == in_file) {
message = "Cannot overwrite the source image.";
} else if (CasacoreImageType(output_filename.string()) == casacore::ImageOpener::UNKNOWN) {
// Not an image
if (fs::is_directory(output_filename)) {
message = "Cannot overwrite existing directory.";
}
} else if (!overwrite) {
// Image requires overwrite
message = "Cannot overwrite existing image.";
}

if (!message.empty()) {
save_file_ack.set_success(success);
save_file_ack.set_message(message);
return;
}
}

if (output_filename.string() == in_file) {
Expand Down

0 comments on commit bc2681e

Please sign in to comment.