From 6018fe0ed6e1befe6eb59cb96bd3f87289b195ec Mon Sep 17 00:00:00 2001 From: Ryan Hodges Date: Fri, 15 May 2026 17:03:58 -0700 Subject: [PATCH 1/2] import_nativeland command now ensures required directories exist --- layers/management/commands/import_nativeland.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/layers/management/commands/import_nativeland.py b/layers/management/commands/import_nativeland.py index 9903689..b860d7f 100644 --- a/layers/management/commands/import_nativeland.py +++ b/layers/management/commands/import_nativeland.py @@ -41,8 +41,17 @@ def handle(self, *args, **options): if not settings.NATIVE_LAND_API_KEY == None: - NLD_DATA_DIR = os.path.join(settings.MEDIA_ROOT, 'data_manager', 'nativeland') + DATA_MANAGER_DATA_DIR = os.path.join(settings.MEDIA_ROOT, 'data_manager') + if not os.path.exists(DATA_MANAGER_DATA_DIR): + os.makedirs(DATA_MANAGER_DATA_DIR) + + NLD_DATA_DIR = os.path.join(DATA_MANAGER_DATA_DIR, 'nativeland') + + if not os.path.exists(NLD_DATA_DIR): + os.makedirs(NLD_DATA_DIR) NLD_BACKUP_DIR = os.path.join(NLD_DATA_DIR, 'backups') + if not os.path.exists(NLD_BACKUP_DIR): + os.makedirs(NLD_BACKUP_DIR) api_prefix = 'https://native-land.ca/api/polygons/geojson/' api_postfix = '?key={}'.format(settings.NATIVE_LAND_API_KEY) From 348361832dcc88377dad693fa448bc6a9c6190a2 Mon Sep 17 00:00:00 2001 From: Ryan Hodges Date: Fri, 15 May 2026 17:13:39 -0700 Subject: [PATCH 2/2] rewrite makedirs in import_nativeland to prevent race conditions --- layers/management/commands/import_nativeland.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/layers/management/commands/import_nativeland.py b/layers/management/commands/import_nativeland.py index b860d7f..6f94b69 100644 --- a/layers/management/commands/import_nativeland.py +++ b/layers/management/commands/import_nativeland.py @@ -42,16 +42,11 @@ def handle(self, *args, **options): if not settings.NATIVE_LAND_API_KEY == None: DATA_MANAGER_DATA_DIR = os.path.join(settings.MEDIA_ROOT, 'data_manager') - if not os.path.exists(DATA_MANAGER_DATA_DIR): - os.makedirs(DATA_MANAGER_DATA_DIR) - + os.makedirs(DATA_MANAGER_DATA_DIR, exist_ok=True) NLD_DATA_DIR = os.path.join(DATA_MANAGER_DATA_DIR, 'nativeland') - - if not os.path.exists(NLD_DATA_DIR): - os.makedirs(NLD_DATA_DIR) + os.makedirs(NLD_DATA_DIR, exist_ok=True) NLD_BACKUP_DIR = os.path.join(NLD_DATA_DIR, 'backups') - if not os.path.exists(NLD_BACKUP_DIR): - os.makedirs(NLD_BACKUP_DIR) + os.makedirs(NLD_BACKUP_DIR, exist_ok=True) api_prefix = 'https://native-land.ca/api/polygons/geojson/' api_postfix = '?key={}'.format(settings.NATIVE_LAND_API_KEY)