Skip to content

Commit fe311da

Browse files
committed
Fix download of freetype 2.6.1.
by checking file hash before exiting the download loop.
1 parent 4792425 commit fe311da

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

setupext.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,40 +1166,39 @@ def do_custom_build(self):
11661166
if not os.path.exists('build'):
11671167
os.makedirs('build')
11681168

1169-
sourceforge_url = (
1169+
url_fmts = [
11701170
'https://downloads.sourceforge.net/project/freetype'
1171-
'/freetype2/{0}/'.format(LOCAL_FREETYPE_VERSION)
1172-
)
1173-
url_fmts = (
1174-
sourceforge_url + '{0}',
1175-
'https://download.savannah.gnu.org/releases/freetype/{0}'
1176-
)
1171+
'/freetype2/{version}/{tarball}',
1172+
'https://download.savannah.gnu.org/releases/freetype'
1173+
'/{tarball}'
1174+
]
11771175
for url_fmt in url_fmts:
1178-
tarball_url = url_fmt.format(tarball)
1176+
tarball_url = url_fmt.format(
1177+
version=LOCAL_FREETYPE_VERSION, tarball=tarball)
11791178

11801179
print("Downloading {0}".format(tarball_url))
11811180
try:
11821181
urlretrieve(tarball_url, tarball_path)
1183-
except:
1182+
except IOError: # URLError (a subclass) on Py3.
11841183
print("Failed to download {0}".format(tarball_url))
11851184
else:
1186-
break
1187-
if not os.path.isfile(tarball_path):
1185+
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
1186+
print("Invalid hash.")
1187+
else:
1188+
break
1189+
else:
11881190
raise IOError("Failed to download freetype")
1189-
if get_file_hash(tarball_path) == LOCAL_FREETYPE_HASH:
1190-
try:
1191-
os.makedirs(tarball_cache_dir)
1192-
except OSError:
1193-
# Don't care if it exists.
1194-
pass
1195-
try:
1196-
shutil.copy(tarball_path, tarball_cache_path)
1197-
print('Cached tarball at: {}'
1198-
.format(tarball_cache_path))
1199-
except OSError:
1200-
# again, we do not care if this fails, can
1201-
# always re download
1202-
pass
1191+
try:
1192+
os.makedirs(tarball_cache_dir)
1193+
except OSError:
1194+
# Don't care if it exists.
1195+
pass
1196+
try:
1197+
shutil.copy(tarball_path, tarball_cache_path)
1198+
print('Cached tarball at: {}'.format(tarball_cache_path))
1199+
except OSError:
1200+
# If this fails, we can always re-download.
1201+
pass
12031202

12041203
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
12051204
raise IOError(

0 commit comments

Comments
 (0)