Skip to content

Commit

Permalink
LocalTransport: Accept existing directories in puttree
Browse files Browse the repository at this point in the history
In 6898ff4 the implementation of the
processing of the `local_copy_list` in the `upload_calculation` method
was changed. Originally, the files specified by the `local_copy_list`
were first copied into the `SandboxFolder` before copying its contents
to the working directory using the transport. The commit allowed the
order in which the local and sandbox files were copied, so the local
files were now no longer copied through the sandbox. Rather, they were
copied to a temporary directory on disk, which was then copied over
using the transport. The problem is that if the latter would copy over a
directory that was already created by the copying of the sandbox, an
exception would be raised.
  • Loading branch information
sphuber committed May 4, 2024
1 parent 09f9058 commit 424027f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/aiida/engine/daemon/execmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ def _copy_local_files(logger, node, transport, inputs, local_copy_list):
shutil.copyfileobj(source, handle)

# Now copy the contents of the temporary folder to the remote working directory using the transport
for filepath in dirpath.iterdir():
transport.put(str(filepath), filepath.name)
transport.put(f'{dirpath}/*', transport.getcwd())


def _copy_sandbox_files(logger, node, transport, folder):
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/transports/plugins/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def puttree(self, localpath, remotepath, *args, **kwargs):

the_destination = os.path.join(self.curdir, remotepath)

shutil.copytree(localpath, the_destination, symlinks=not dereference)
shutil.copytree(localpath, the_destination, symlinks=not dereference, dirs_exist_ok=overwrite)

def rmtree(self, path):
"""Remove tree as rm -r would do
Expand Down
3 changes: 3 additions & 0 deletions tests/engine/daemon/test_execmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def test_retrieve_files_from_list(
(['sub', None], {'b': 'file_b'}),
([None, 'target'], {'target': {'sub': {'b': 'file_b'}, 'a': 'file_a'}}),
(['sub', 'target'], {'target': {'b': 'file_b'}}),
(['a', 'target/filename'], {'target': {'filename': 'file_a'}}),
),
)
def test_upload_local_copy_list(
Expand All @@ -186,6 +187,8 @@ def test_upload_local_copy_list(
calc_info.local_copy_list = [[folder.uuid] + local_copy_list]

with LocalTransport() as transport:
# Create the ``target`` subdirectory to make sure that won't cause an exception but directories are merged
fixture_sandbox.get_subfolder('target', create=True)
execmanager.upload_calculation(node, transport, calc_info, fixture_sandbox)

# Check that none of the files were written to the repository of the calculation node, since they were communicated
Expand Down

0 comments on commit 424027f

Please sign in to comment.