ShellJob
: Detect and prevent filename clashes
#70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #68
So far, no validation was performed on the filenames of input nodes that
would be written to the working directory that could overlap with files
written by the plugin itself, such as
stdout
andstderr
. This couldlead to unexpected results and often calculations failing completely.
For example, if a
SinglefileData
would be written to the workingdirectory with the filename
stdout
, most likely because thefilename
attribute of the node was set to this, then this would be overwritten by
the redirection of the stdout, which is redirected to the file
stdout
by default.
A distinction is made between clashes that happen "implicitly", meaning
the filename of the
SinglefileData
orFolderData
just happen tooverlap, compared to "explicitly" where the user specifies a conflicting
filename in the
filenames
input. In the latter case, an exception israised during the validation. In the former case, the target filename is
automatically changed to a unique filename to resolve the naming issue.
This solution is chosen because this will happen often in normal use
cases of
aiida-shell
. For example, if a command is run whose stdout iscaptured, it will be stored as a
SinglefileData
with the namestdout
. If this in turn is used as an input for a next command, thisfilename will clash as
stdout
is a reserved name. This would force theuser to manually correct the problem by defining an alternative name in
filenames
. Since this will occur so often, it is better to have theplugin automatically solve this conflict.
There is a special case for the
FolderData
where an object containedwithin it overlaps with a reserved filename. In this case, the strategy
mentioned above of automatically renaming won't work because the writing
of the contents is not done by the plugin but by the engine. Instead, an
exception is raised. Unfortunately, this is not done in the input
validation and so this will result in an excepted process. However, it
is currently not possible to put this logic in the input validation as
this would require significant refactoring.