11import os
22import textwrap
33
4- from conan .internal .util .files import tar_extract
4+ from conan .internal .util .files import COMPRESSED_PLUGIN_TAR_NAME , tar_extract
55from conan .test .assets .genconanfile import GenConanfile
66from conan .test .utils .tools import TestClient
77
@@ -26,7 +26,7 @@ def tar_compress(archive_path, files, recursive, conf=None, *args, **kwargs):
2626 }
2727 )
2828 c .run ("create ." )
29- c .run ("cache save 'pkg/*'" , assert_error = True )
29+ c .run ("cache save 'pkg/*:* '" , assert_error = True )
3030 assert (
3131 "ERROR: The 'compression.py' plugin does not contain required `tar_extract` or `tar_compress` functions"
3232 in c .out
@@ -48,13 +48,15 @@ def test_compression_plugin_correctly_load():
4848
4949 # xz compression
5050 def tar_compress(archive_path, files, recursive, conf=None, ref=None, *args, **kwargs):
51+ archive_path += ".xz"
5152 name = os.path.basename(archive_path)
5253 ConanOutput(scope=ref).info(f"Compressing {name} using compression plugin (xz)")
5354 compresslevel = conf.get("core.gzip:compresslevel", check_type=int) if conf else None
5455 kwargs = {"preset": compresslevel} if compresslevel else {}
5556 with tarfile.open(archive_path, f"w:xz", **kwargs) as tgz:
5657 for filename, abs_path in sorted(files.items()):
5758 tgz.add(abs_path, filename, recursive=True)
59+ return archive_path
5860
5961 def tar_extract(archive_path, dest_dir, conf=None, *args, **kwargs):
6062 ConanOutput().info(f"Decompressing {os.path.basename(archive_path)} using compression plugin (xz)")
@@ -75,24 +77,25 @@ def tar_extract(archive_path, dest_dir, conf=None, *args, **kwargs):
7577 }
7678 )
7779 c .run ("create ." )
78- c .run ("cache save 'pkg/*'" )
79- assert "Compressing conan_cache_save.tgz using compression plugin (xz)" in c .out
80+ c .run ("cache save 'pkg/*:*'" )
81+ print (c .out )
82+ assert f"Compressing { COMPRESSED_PLUGIN_TAR_NAME } .xz using compression plugin (xz)" in c .out
8083 c .run ("remove pkg/* -c" )
8184 c .run ("cache restore conan_cache_save.tgz" )
82- assert "Decompressing conan_cache_save.tgz using compression plugin (xz)" in c .out
85+ assert f "Decompressing { COMPRESSED_PLUGIN_TAR_NAME } .xz using compression plugin (xz)" in c .out
8386 c .run ("list pkg/1.0" )
8487 assert "Found 1 pkg/version recipes matching pkg/1.0 in local cache" in c .out
8588
8689 # Remove pre existing tgz to force a recompression
8790 c .run ("remove pkg/* -c" )
8891 c .run ("create ." )
8992 # Check the plugin is also used on remote interactions
90- c .run ("upload * -r=default -c" )
91- assert "Compressing conan_package.tgz using compression plugin (xz)" in c .out
93+ c .run ("upload *:* -r=default -c" )
94+ assert f "Compressing { COMPRESSED_PLUGIN_TAR_NAME } .xz using compression plugin (xz)" in c .out
9295 assert "pkg/1.0: Uploading recipe" in c .out
9396 c .run ("remove pkg/* -c" )
9497 c .run ("download 'pkg/*' -r=default" )
95- assert "Decompressing conan_package.tgz using compression plugin (xz)" in c .out
98+ assert f "Decompressing { COMPRESSED_PLUGIN_TAR_NAME } .xz using compression plugin (xz)" in c .out
9699
97100
98101def test_compression_plugin_tar_not_compatible_with_builtin ():
@@ -111,6 +114,7 @@ def test_compression_plugin_tar_not_compatible_with_builtin():
111114 # zip compression
112115 def tar_compress(archive_path, files, recursive, conf=None, *args, **kwargs):
113116 # compress files using zipfile library taking into account recursive
117+ archive_path += ".zip"
114118 name = os.path.basename(archive_path)
115119 compresslevel = conf.get("core.gzip:compresslevel", check_type=int) if conf else None
116120 ConanOutput().info(f"Compressing {name} using compression plugin (zip)")
@@ -121,6 +125,7 @@ def tar_compress(archive_path, files, recursive, conf=None, *args, **kwargs):
121125 zipf.write(abs_path, arcname)
122126 else:
123127 zipf.write(abs_path, filename)
128+ return archive_path
124129
125130 def tar_extract(archive_path, dest_dir, conf=None, *args, **kwargs):
126131 # extract tar using zipfile library
@@ -139,13 +144,13 @@ def tar_extract(archive_path, dest_dir, conf=None, *args, **kwargs):
139144 }
140145 )
141146 c .run ("create ." )
142- c .run ("cache save 'pkg/*'" )
147+ c .run ("cache save 'pkg/*:* '" )
143148 c .run ("remove pkg/* -c" )
144149 os .unlink (os .path .join (c .cache_folder , "extensions" , "plugins" , "compression.py" ))
145150 c .run ("cache restore conan_cache_save.tgz" , assert_error = True )
146151 assert (
147- "Error while extracting conan_cache_save.tgz. The file compression is not recogniced. \n "
148- "This file could have been compressed using a `compression` plugin.\n "
152+ "Error while extracting conan_cache_save.tgz.\n "
153+ "This file has been compressed using a `compression` plugin.\n "
149154 "If your organization uses this plugin, ensure it is correctly installed on your environment."
150155 ) in c .out
151156
@@ -160,13 +165,15 @@ def test_compress_in_subdirectory():
160165 from conan.api.output import ConanOutput
161166 def tar_compress(archive_path, files, recursive, *args, **kwargs):
162167 # compress files using tarfile putting all content in a `conan/` subfolder
168+ archive_path += ".tgz"
163169 name = os.path.basename(archive_path)
164170 ConanOutput().info(f"Compressing {os.path.basename(name)} in conan subfolder")
165171 with open(archive_path, "wb") as tgz_handle:
166172 tgz = tarfile.open(name, "w", fileobj=tgz_handle)
167173 for filename, abs_path in sorted(files.items()):
168174 tgz.add(abs_path, os.path.join("conan", filename), recursive=recursive)
169175 tgz.close()
176+ return archive_path
170177
171178 def tar_extract(archive_path, dest_dir, *args, **kwargs):
172179 ConanOutput().info(f"Decompressing {archive_path} in conan subfolder")
@@ -189,12 +196,6 @@ def tar_extract(archive_path, dest_dir, *args, **kwargs):
189196 }
190197 )
191198 c .run ("create ." )
192- c .run ("cache save 'pkg/*'" )
199+ c .run ("cache save 'pkg/*:* '" )
193200 c .run ("remove pkg/* -c" )
194201 c .run ("cache restore conan_cache_save.tgz" )
195- with open (os .path .join (c .current_folder , "conan_cache_save.tgz" ), 'rb' ) as file_handler :
196- dest_dir = os .path .join (c .cache_folder , "extracted" )
197- tar_extract (file_handler , dest_dir )
198- assert os .listdir (dest_dir ) == ["conan" ]
199- assert os .path .exists (os .path .join (dest_dir , "conan" , "pkglist.json" ))
200-
0 commit comments