Skip to content

Commit ca5af4d

Browse files
Fixes for csfle downloading on some Linux platforms (#977)
* Fix mongodl for older Python versions * Archlinux is a special case. Just use RHEL8 binaries * Disable csfle download if there is no version download available for the system. * Explain some behavior in mongodl * Fix Amazon linux detection
1 parent 0c45daf commit ca5af4d

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

.evergreen/compile-unix.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ if [ "darwin" = "$OS" -a "arm64" = "$MARCH" ]; then
199199
CONFIGURE_FLAGS="$CONFIGURE_FLAGS -DCMAKE_OSX_ARCHITECTURES=arm64"
200200
fi
201201

202+
if ! python3 build/mongodl.py --test -C csfle -V 5.3.1 -o . > /dev/null; then
203+
echo "No csfle detected for this platform. Disabling MONGOC_TEST_USE_CSFLE."
204+
CONFIGURE_FLAGS="$CONFIGURE_FLAGS -DMONGOC_TEST_USE_CSFLE=OFF"
205+
fi
206+
202207
CONFIGURE_FLAGS="$CONFIGURE_FLAGS $EXTRA_CONFIGURE_FLAGS"
203208
export MONGOC_TEST_FUTURE_TIMEOUT_MS=30000
204209
export MONGOC_TEST_SKIP_LIVE=on

build/mongodl.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'opensuse-leap': 'sles',
3333
'opensuse': 'sles',
3434
'redhat': 'rhel',
35+
'rocky': 'rhel',
3536
}
3637

3738
DISTRO_VERSION_MAP = {
@@ -46,6 +47,7 @@
4647
'20.*': 'ubuntu2004',
4748
'18.*': 'ubuntu1804',
4849
'16.*': 'ubuntu1604',
50+
'14.*': 'ubuntu1404',
4951
},
5052
'debian': {
5153
'9': 'debian92',
@@ -54,8 +56,11 @@
5456
},
5557
'rhel': {
5658
'6': 'rhel60',
59+
'6.*': 'rhel60',
5760
'7': 'rhel70',
61+
'7.*': 'rhel70',
5862
'8': 'rhel80',
63+
'8.*': 'rhel80',
5964
},
6065
'sles': {
6166
'10.*': 'suse10',
@@ -65,8 +70,8 @@
6570
'15.*': 'suse15',
6671
},
6772
'amzn': {
68-
'2018': 'amzn64',
69-
'2': 'amzn64',
73+
'2018.*': 'amzn64',
74+
'2': 'amazon2',
7075
},
7176
}
7277

@@ -84,12 +89,18 @@ def infer_target():
8489

8590

8691
def _infer_target_os_rel():
87-
content = Path('/etc/os-release').read_text()
92+
with Path('/etc/os-release').open('r', encoding='utf-8') as f:
93+
content = f.read()
8894
id_re = re.compile(r'\bID=("?)(.*)\1')
8995
mat = id_re.search(content)
9096
assert mat, 'Unable to detect ID from [/etc/os-release] content:\n{}'.format(
9197
content)
9298
os_id = mat.group(2)
99+
if os_id == 'arch':
100+
# There are no Archlinux-specific MongoDB downloads, so we'll just use
101+
# the build for RHEL8, which is reasonably compatible with other modern
102+
# distributions (including Arch).
103+
return 'rhel80'
93104
ver_id_re = re.compile(r'VERSION_ID=("?)(.*?)\1')
94105
mat = ver_id_re.search(content)
95106
assert mat, 'Unable to detect VERSION_ID from [/etc/os-release] content:\n{}'.format(
@@ -122,11 +133,11 @@ def caches_root():
122133
if sys.platform == 'win32':
123134
return Path(os.environ['LocalAppData'])
124135
if sys.platform == 'darwin':
125-
return Path('~/Library/Caches').expanduser()
136+
return Path(os.environ['HOME'] + '/Library/Caches')
126137
xdg_cache = os.getenv('XDG_CACHE_HOME')
127138
if xdg_cache:
128139
return Path(xdg_cache)
129-
return Path('~/.cache').expanduser()
140+
return Path(os.environ['HOME'] + '/.cache')
130141

131142

132143
def cache_dir():
@@ -214,9 +225,27 @@ def _import_json_data(db, json_file):
214225
)
215226

216227

228+
def _mkdir(dirpath):
229+
"""
230+
Ensure a directory at ``dirpath``, and all parent directories thereof.
231+
232+
Cannot using Path.mkdir(parents, exist_ok) on some Python versions that
233+
we need to support.
234+
"""
235+
if dirpath.is_dir():
236+
return
237+
par = dirpath.parent
238+
if par != dirpath:
239+
_mkdir(par)
240+
try:
241+
dirpath.mkdir()
242+
except FileExistsError:
243+
pass
244+
245+
217246
def get_dl_db():
218247
caches = cache_dir()
219-
caches.mkdir(exist_ok=True, parents=True)
248+
_mkdir(caches)
220249
db = sqlite3.connect(str(caches / 'downloads.db'), isolation_level=None)
221250
db.executescript(r'''
222251
CREATE TABLE IF NOT EXISTS meta (
@@ -271,7 +300,7 @@ def _print_list(db, version, target, arch, edition, component):
271300
' Edition: {}\n\n'
272301
' Info: {}\n\n'.format(comp_key, version, target, arch,
273302
edition, comp_data))
274-
print(f'(Omit filter arguments for a list of available filters)')
303+
print('(Omit filter arguments for a list of available filters)')
275304
return
276305

277306
arches, targets, editions, versions, components = next(
@@ -344,7 +373,7 @@ def _download_file(db, url):
344373
return DLRes(False, dest)
345374
else:
346375
print('Downloading [{}] ...'.format(url))
347-
dest.parent.mkdir(exist_ok=True, parents=True)
376+
_mkdir(dest.parent)
348377
got_etag = resp.getheader("ETag")
349378
got_modtime = resp.getheader('Last-Modified')
350379
with dest.open('wb') as of:
@@ -551,10 +580,10 @@ def _maybe_extract_member(out, relpath, pattern, strip, is_dir, opener,
551580
# We are running in test-only mode: Do not do anything
552581
return 1
553582
if is_dir:
554-
dest.mkdir(exist_ok=True, parents=True)
583+
_mkdir(dest)
555584
return 1
556585
with opener() as infile:
557-
dest.parent.mkdir(exist_ok=True, parents=True)
586+
_mkdir(dest.parent)
558587
with dest.open('wb') as outfile:
559588
shutil.copyfileobj(infile, outfile)
560589
os.chmod(str(dest), modebits)

0 commit comments

Comments
 (0)