diff --git a/edk2toolext/environment/extdeptypes/web_dependency.py b/edk2toolext/environment/extdeptypes/web_dependency.py index 0095c7bc..c694c0f4 100644 --- a/edk2toolext/environment/extdeptypes/web_dependency.py +++ b/edk2toolext/environment/extdeptypes/web_dependency.py @@ -129,9 +129,6 @@ def fetch(self): # # If we're unpacking a directory, we can copy the important parts into # # a directory named self.contents_dir if self.download_is_directory: - # The root of the internal path is the folder we will see populated in descriptor_location - unzip_root = WebDependency.get_internal_path_root(self.descriptor_location, self.internal_path) - logging.info(f"Copying directory from {complete_internal_path} to {self.contents_dir}") if os.path.isdir(complete_internal_path) is False: # internal_path was not accurate, exit @@ -141,9 +138,9 @@ def fetch(self): shutil.move(complete_internal_path, self.contents_dir) # If the unzipped directory still exists, delete it. - if os.path.isdir(unzip_root): - logging.debug(f"Cleaning up {unzip_root}") - shutil.rmtree(unzip_root) + if os.path.isdir(temp_folder): + logging.debug(f"Cleaning up {temp_folder}") + shutil.rmtree(temp_folder) # If we just downloaded a file, we need to create a directory named self.contents_dir, # copy the file inside, and name it self.internal_path diff --git a/edk2toolext/tests/test_web_dependency.py b/edk2toolext/tests/test_web_dependency.py index 24ee57ee..1148f500 100644 --- a/edk2toolext/tests/test_web_dependency.py +++ b/edk2toolext/tests/test_web_dependency.py @@ -44,7 +44,28 @@ "flags": [], "internal_path": "test.txt" } - +# Use the github release +zip_directory_extdep = { + "scope": "global", + "type": "web", + "name": "win-flexbison", + "compression_type": "zip", + "source": "https://github.com/lexxmark/winflexbison/releases/download/v2.4.7/win_flex_bison-2.4.7.zip", + "version": "2.4.7", + "sha256": "7553a2d6738c799e101ec38a6ad073885ead892826f87bc1a24e78bcd7ac2a8c", + "internal_path": "/." +} +# Use the GNU FTP +tar_directory_extdep = { + "scope": "global", + "type": "web", + "name": "unix-bison", + "compression_type": "tar", + "source": "https://ftp.gnu.org/gnu/bison/bison-3.7.tar.gz", + "version": "3.7", + "sha256": "492ad61202de893ca21a99b621d63fa5389da58804ad79d3f226b8d04b803998", + "internal_path": "/bison-3.7", +} # Download a valid file from CDN jquery_json_file = { "scope": "global", @@ -120,6 +141,40 @@ def test_single_file(self): if not os.path.isfile(file_path): self.fail("The downloaded file isn't there") + # try to download a whole zip directory and test sha256 comparison + def test_sha256_whole_zip_directory(self): + ext_dep_file_path = os.path.join(test_dir, "good_ext_dep.json") + + with open(ext_dep_file_path, "w+") as ext_dep_file: + ext_dep_file.write(json.dumps(zip_directory_extdep)) # dump to a file + + ext_dep_descriptor = EDF.ExternDepDescriptor(ext_dep_file_path).descriptor_contents + ext_dep = WebDependency(ext_dep_descriptor) + ext_dep.fetch() + + ext_dep_name = zip_directory_extdep['name'] + "_extdep" + folder_path = os.path.join(test_dir, ext_dep_name) + if not os.path.exists(os.path.join(folder_path, "README.txt")): + logging.warning(folder_path) + self.fail() + + # try to download a whole zip directory and test sha256 comparison + def test_sha256_whole_tar_directory(self): + ext_dep_file_path = os.path.join(test_dir, "good_ext_dep.json") + + with open(ext_dep_file_path, "w+") as ext_dep_file: + ext_dep_file.write(json.dumps(tar_directory_extdep)) # dump to a file + + ext_dep_descriptor = EDF.ExternDepDescriptor(ext_dep_file_path).descriptor_contents + ext_dep = WebDependency(ext_dep_descriptor) + ext_dep.fetch() + + ext_dep_name = tar_directory_extdep['name'] + "_extdep" + folder_path = os.path.join(test_dir, ext_dep_name) + if not os.path.exists(os.path.join(folder_path, "README")): + logging.warning(folder_path) + self.fail() + # try to download a single file and test sha256 comparison def test_sha256_uppercase_single_file(self): ext_dep_file_path = os.path.join(test_dir, "good_ext_dep.json")