Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy error when adding files to an existing rocrate #86

Closed
cedricdcc opened this issue Nov 8, 2021 · 3 comments
Closed

Copy error when adding files to an existing rocrate #86

cedricdcc opened this issue Nov 8, 2021 · 3 comments

Comments

@cedricdcc
Copy link

Problem: Trying to add a file to an existing ro-crate results into a copy-error that keeps the rocrate from being updated.

Use-Case: 2 scientists working together on a project and making the rocrate in multiple times. (re instantiating the same rocrate multiple times.)

Solution: An internal check if a file is already present in the rocrate folder and if already present ignore the copy

@simleo
Copy link
Collaborator

simleo commented Nov 10, 2021

Assuming this is the scenario:

temp.py:

from rocrate.rocrate import ROCrate

crate = ROCrate("/tmp/crate")
crate.add_file("/etc/fstab")
crate.write("/tmp/crate")
$ rm -rf /tmp/crate && cp -rf test/test-data/read_crate /tmp/crate
$ python temp.py
Traceback (most recent call last):
  File "temp.py", line 5, in <module>
    crate.write("/tmp/crate")
  File "/home/simleo/git/ro-crate-py/rocrate/rocrate.py", line 474, in write
    self._copy_unlisted(self.source, base_path)
  File "/home/simleo/git/ro-crate-py/rocrate/rocrate.py", line 468, in _copy_unlisted
    shutil.copyfile(source, dest)
  File "/usr/lib/python3.6/shutil.py", line 104, in copyfile
    raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
shutil.SameFileError: PosixPath('/tmp/crate/ro-crate-metadata.jsonld') and PosixPath('/tmp/crate/ro-crate-metadata.jsonld') are the same file

Note that adding the file is not required to trigger the error: just trying to write the crate back to the source dir is enough.

@pauldg
Copy link
Contributor

pauldg commented Nov 10, 2021

I suggested a PR for this here: #88

@simleo
Copy link
Collaborator

simleo commented Nov 19, 2021

Fixed in #88

@simleo simleo closed this as completed Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants