Skip to content

Commit

Permalink
BUG: WriteAsciiData-Add preflight checks for empty paths. (#938)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored May 1, 2024
1 parent 9d7c4e4 commit 5bb8213
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace
{
// Error Code constants
constexpr nx::core::int32 k_UnmatchingTupleCountError = -51001;
constexpr nx::core::int32 k_NoArraySelections = -51002;
} // namespace

namespace nx::core
Expand Down Expand Up @@ -118,6 +119,10 @@ IFilter::PreflightResult WriteASCIIDataFilter::preflightImpl(const DataStructure
if(static_cast<WriteASCIIDataFilter::OutputStyle>(pOutputStyleValue) == WriteASCIIDataFilter::OutputStyle::SingleFile)
{
auto pSelectedDataArrayPathsValue = filterArgs.value<MultiArraySelectionParameter::ValueType>(k_SelectedDataArrayPaths_Key);
if(pSelectedDataArrayPathsValue.empty())
{
return MakePreflightErrorResult(k_NoArraySelections, "At least 1 data array must be selected");
}

if(!CheckArraysHaveSameTupleCount(dataStructure, pSelectedDataArrayPathsValue))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ Parameters WriteDREAM3DFilter::parameters() const
Parameters params;

params.insertSeparator(Parameters::Separator{"Input Parameters"});
params.insert(std::make_unique<FileSystemPathParameter>(k_ExportFilePath, "Export File Path", "The file path the DataStructure should be written to as an HDF5 file.", "",
FileSystemPathParameter::ExtensionsType{".dream3d"}, FileSystemPathParameter::PathType::OutputFile));
params.insert(std::make_unique<BoolParameter>(k_WriteXdmf, "Write Xdmf File", "Whether or not to write the data out an xdmf file", true));
params.insert(std::make_unique<FileSystemPathParameter>(k_ExportFilePath, "Output File Path", "The file path the DataStructure should be written to as an HDF5 file.", "Untitled.dream3d",
FileSystemPathParameter::ExtensionsType{".dream3d"}, FileSystemPathParameter::PathType::OutputFile, false));
params.insert(std::make_unique<BoolParameter>(k_WriteXdmf, "Write Xdmf File", "Whether or not to write the data out an XDMF file", true));
return params;
}

Expand Down
5 changes: 5 additions & 0 deletions src/simplnx/Parameters/FileSystemPathParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ Result<> ValidateInputDir(const FileSystemPathParameter::ValueType& path)
//-----------------------------------------------------------------------------
Result<> ValidateOutputFile(const FileSystemPathParameter::ValueType& path)
{
if(fs::exists(path) && fs::is_directory(path))
{
return MakeErrorResult(-8, fmt::format("File System Path '{}' exists AND is a directory. The Parameter is set to save a file.", path.string()));
}

auto result = FileUtilities::ValidateDirectoryWritePermission(path, true);
if(result.invalid())
{
Expand Down

0 comments on commit 5bb8213

Please sign in to comment.