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

fix restore not exist file #16113

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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