From 7937f72f1497244744c012e5330d9e3c686aa71c Mon Sep 17 00:00:00 2001 From: Kyle Wilcox Date: Sun, 13 Aug 2017 23:18:00 -0400 Subject: [PATCH] Get permissions correct for all output files --- gutils/nc.py | 1 + gutils/watch/netcdf.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gutils/nc.py b/gutils/nc.py index 09aaea2..a7a98ea 100644 --- a/gutils/nc.py +++ b/gutils/nc.py @@ -224,6 +224,7 @@ def create_netcdf(attrs, data, output_path, mode): # Move to final destination safe_makedirs(os.path.dirname(output_file)) + os.chmod(tmp_path, 0o664) shutil.move(tmp_path, output_file) L.info('Created: {}'.format(output_file)) except BaseException as e: diff --git a/gutils/watch/netcdf.py b/gutils/watch/netcdf.py index 04c8f67..d36486d 100644 --- a/gutils/watch/netcdf.py +++ b/gutils/watch/netcdf.py @@ -270,15 +270,24 @@ def create_and_update_content(self, event): # Replace old datasets.xml os.close(new_datasets_handle) + os.chmod(new_datasets_path, 0o664) shutil.move(new_datasets_path, datasets_path) finally: # Write dataset update flag if it doesn't exist if self.erddap_flag_path is not None: - flagfile = os.path.join(self.erddap_flag_path, deployment_name) - if not os.path.isfile(flagfile): - with open(flagfile, 'w') as ff: + flag_tmp_handle, flag_tmp_path = tempfile.mkstemp(prefix='gutils_errdap_', suffix='.flag') + final_flagfile = os.path.join(self.erddap_flag_path, deployment_name) + + if not os.path.isfile(final_flagfile): + with open(flag_tmp_path, 'w') as ff: ff.write(datetime.utcnow().isoformat()) + os.chmod(flag_tmp_path, 0o666) + shutil.move(flag_tmp_path, final_flagfile) + + os.close(flag_tmp_handle) + if os.path.exists(flag_tmp_path): + os.remove(flag_tmp_path) os.close(tmp_handle) if os.path.exists(tmp_path):