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

[command][cache path] Raising error if folder path does not exist #15257

Merged
merged 5 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions conan/cli/commands/cache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os.path

from conan.api.conan_api import ConanAPI
from conan.api.model import ListPattern, MultiPackagesList
from conan.api.output import cli_out_write
Expand Down Expand Up @@ -46,6 +48,8 @@ def cache_path(conan_api: ConanAPI, parser, subparser, *args):
path = conan_api.cache.recipe_metadata_path(ref)
else:
raise ConanException(f"'--folder {args.folder}' requires a valid package reference")
if args.folder and not os.path.exists(path):
raise ConanException(f"'{args.folder}' folder does not exist for the reference {ref}")
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
else:
if args.folder is None:
path = conan_api.cache.package_path(pref)
Expand All @@ -55,6 +59,9 @@ def cache_path(conan_api: ConanAPI, parser, subparser, *args):
path = conan_api.cache.package_metadata_path(pref)
else:
raise ConanException(f"'--folder {args.folder}' requires a recipe reference")
if args.folder and not os.path.exists(path):
raise ConanException(f"'{args.folder}' folder does not exist for the package reference "
f"{pref}")
return path


Expand Down
14 changes: 14 additions & 0 deletions conans/test/integration/command_v2/test_cache_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,17 @@ def test_cache_path_arg_errors():
# source, cannot obtain build without pref
t.run("cache path foo/1.0:pid --folder source", assert_error=True)
assert "ERROR: '--folder source' requires a recipe reference" in t.out


def test_cache_path_does_not_exist_folder():
client = TestClient(default_server_user=True)
conanfile = GenConanfile()
client.save({"conanfile.py": conanfile})
client.run("create . --name=mypkg --version=0.1")
pref = client.created_package_reference("mypkg/0.1")
client.run("upload * --confirm -r default")
client.run("remove * -c")

client.run(f"install --requires mypkg/0.1")
client.run(f"cache path {pref} --folder build", assert_error=True)
assert f"ERROR: 'build' folder does not exist for the package reference {pref}" in client.out
15 changes: 8 additions & 7 deletions conans/test/integration/metadata/test_metadata_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_upload(self, create_conan_pkg):
# Add some metadata
self.save_metadata_file(c, "pkg/0.1", "mylogs.txt")
self.save_metadata_file(c, f"pkg/0.1:{pid}", "mybuildlogs.txt")

# Now upload everything
c.run("upload * -c -r=default")
assert "pkg/0.1: Recipe metadata: 1 files" in c.out
Expand All @@ -47,15 +46,17 @@ def test_upload(self, create_conan_pkg):

c.run("remove * -c")
c.run("install --requires=pkg/0.1") # wont install metadata by default
c.run("cache path pkg/0.1 --folder=metadata")
metadata_path = str(c.stdout).strip()
c.run(f"cache path pkg/0.1:{pid} --folder=metadata")
pkg_metadata_path = str(c.stdout).strip()
assert not os.path.exists(metadata_path)
assert not os.path.exists(pkg_metadata_path)
c.run("cache path pkg/0.1 --folder=metadata", assert_error=True)
assert "'metadata' folder does not exist for the reference pkg/0.1" in c.out
c.run(f"cache path pkg/0.1:{pid} --folder=metadata", assert_error=True)
assert f"'metadata' folder does not exist for the package reference pkg/0.1:{pid}" in c.out

# Forcing the download of the metadata of cache-existing things with the "download" command
c.run("download pkg/0.1 -r=default --metadata=*")
c.run(f"cache path pkg/0.1 --folder=metadata")
metadata_path = str(c.stdout).strip()
c.run(f"cache path pkg/0.1:{pid} --folder=metadata")
pkg_metadata_path = str(c.stdout).strip()
for f in "logs/mylogs.txt", "logs/mylogs2.txt":
assert os.path.isfile(os.path.join(metadata_path, f))
for f in "logs/mybuildlogs.txt", "logs/mybuildlogs2.txt":
Expand Down