Skip to content

Commit

Permalink
verdi migrate: make --in-place work across different file systems (
Browse files Browse the repository at this point in the history
…#4393)

The `verdi migrate` command assumed implicitly that the archive that is
to be migrated, resides on the same file system as the one that is used
by the `tempfile` module. If this is not the case, the `os.rename` call
used to atomically move the migrated archive to the original will fail
with the exception:

    OSError: [Errno 18] Invalid cross-device link

Changing `os.rename` to `shutil.move` fixes this problem. The downside,
however, is that the move is no longer atomic, but that is probably why
`os.rename` is restricted to same filysystem operations.
  • Loading branch information
ltalirz authored Oct 26, 2020
1 parent 861a39f commit 7c49471
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion aiida/cmdline/commands/cmd_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""`verdi export` command."""
import os
import tempfile
import shutil

import click
import tabulate
Expand Down Expand Up @@ -245,7 +246,7 @@ def migrate(input_file, output_file, force, silent, in_place, archive_format, ve
archive.add(folder.abspath, arcname='')

if in_place:
os.rename(output_file, input_file)
shutil.move(output_file, input_file)
tempdir.cleanup()

if not silent:
Expand Down

0 comments on commit 7c49471

Please sign in to comment.