From dcb2adb7f1a89d1c880631f32f40f364ab3014d3 Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:45:06 -0400 Subject: [PATCH] Update earthaccess/auth.py Co-authored-by: Joseph H Kennedy --- earthaccess/auth.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index eff230f3..8e89cbdc 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -372,18 +372,22 @@ def _persist_user_credentials(self, username: str, password: str) -> bool: my_netrc = Netrc(str(netrc_path)) my_netrc["urs.earthdata.nasa.gov"] = {"login": username, "password": password} my_netrc.save() - - # Create and write .urs_cookies file - urs_cookies_file = Path.home() / ".urs_cookies" - urs_cookies_file.write_text("") + urs_cookies_path = Path.home() / ".urs_cookies" + if not usr_cookies_path.exists(): + urs_cookies_path.write_text("") # Create and write to .dodsrc file - dodsrc_file = Path.home() / ".dodsrc" - dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_file}\nHTTP.NETRC={netrc_path}" - dodsrc_file.write_text(dodsrc_contents) - - if platform.system() == "Windows": - shutil.copy2(dodsrc_file, Path.cwd()) + dodsrc_path = Path.home() / ".dodsrc" + if not dodsrc_path.exists(): + dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_file}\nHTTP.NETRC={netrc_path}" + dodsrc_path.write_text(dodsrc_contents) + + + if platform.system() == "Windows": + local_dodsrc_path = Path.cwd() / dodsrc_path.name + if not local_dodsrc_path.exists(): + shutil.copy2(dodsrc_path, local_dodsrc_path) + return True