Skip to content

Commit

Permalink
[Bug] fix web extdep unzipping root folder (#213)
Browse files Browse the repository at this point in the history
When unzipping the root of a zip compressed extdep, it will delete the root folder that the extdep is in because of an improper shuti.rmtree
  • Loading branch information
matthewfcarlson authored Aug 21, 2020
1 parent b6bc525 commit 2c22533
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
9 changes: 3 additions & 6 deletions edk2toolext/environment/extdeptypes/web_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
57 changes: 56 additions & 1 deletion edk2toolext/tests/test_web_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 2c22533

Please sign in to comment.