Skip to content

Commit

Permalink
fix restore not exist file (#16113)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Apr 19, 2024
1 parent 517e2b7 commit 20bf653
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conan/api/subapi/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def save(self, package_list, tgz_path):
tgz.close()

def restore(self, path):
if not os.path.isfile(path):
raise ConanException(f"Restore archive doesn't exist in {path}")
with open(path, mode='rb') as file_handler:
the_tar = tarfile.open(fileobj=file_handler)
fileobj = the_tar.extractfile("pkglist.json")
Expand Down
6 changes: 6 additions & 0 deletions conans/test/integration/command_v2/test_cache_save_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,9 @@ def test_cache_save_subfolder():
c.run("export .")
c.run("cache save * --file=subfolder/cache.tgz")
assert os.path.exists(os.path.join(c.current_folder, "subfolder", "cache.tgz"))


def test_error_restore_not_existing():
c = TestClient()
c.run("cache restore potato.tgz", assert_error=True)
assert "ERROR: Restore archive doesn't exist in " in c.out

0 comments on commit 20bf653

Please sign in to comment.