From 46812af5c2560b1ca6a18595a1fa8ca35a9b5239 Mon Sep 17 00:00:00 2001 From: Mark Calvert Date: Thu, 22 Feb 2024 11:54:40 +0800 Subject: [PATCH] Fix file move and remove in archiver tasks --- .../01_copy_archive_resource.patch | 27 +++++++++++++++++++ .../ckanext-archiver/01_copy_function.patch | 13 --------- 2 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 ckan/patches/ckanext-archiver/01_copy_archive_resource.patch delete mode 100644 ckan/patches/ckanext-archiver/01_copy_function.patch diff --git a/ckan/patches/ckanext-archiver/01_copy_archive_resource.patch b/ckan/patches/ckanext-archiver/01_copy_archive_resource.patch new file mode 100644 index 00000000..4a984354 --- /dev/null +++ b/ckan/patches/ckanext-archiver/01_copy_archive_resource.patch @@ -0,0 +1,27 @@ +index 06a1758..08a3ba6 100644 +--- a/ckanext/archiver/tasks.py ++++ b/ckanext/archiver/tasks.py +@@ -568,14 +568,14 @@ def archive_resource(context, resource, log, result=None, url_timeout=30): + except Exception: + file_name = "resource" + +- # move the temp file to the resource's archival directory +- saved_file = os.path.join(archive_dir, file_name) +- shutil.move(result['saved_file'], saved_file) +- log.info('Going to do chmod: %s', saved_file) + try: +- os.chmod(saved_file, 0o644) # allow other users to read it ++ # move the temp file to the resource's archival directory ++ saved_file = os.path.join(archive_dir, file_name) ++ shutil.copy(result['saved_file'], saved_file) ++ log.info('File moved : %s', saved_file) ++ os.remove(result['saved_file']) + except Exception as e: +- log.error('chmod failed %s: %s', saved_file, e) ++ log.error("move the temp file to the resource's archival directory failed %s: %s", saved_file, e) + raise + log.info('Archived resource as: %s', saved_file) + + +~ +~ \ No newline at end of file diff --git a/ckan/patches/ckanext-archiver/01_copy_function.patch b/ckan/patches/ckanext-archiver/01_copy_function.patch deleted file mode 100644 index 727485a3..00000000 --- a/ckan/patches/ckanext-archiver/01_copy_function.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/ckanext/archiver/tasks.py b/ckanext/archiver/tasks.py -index 06a1758..95fa968 100644 ---- a/ckanext/archiver/tasks.py -+++ b/ckanext/archiver/tasks.py -@@ -570,7 +570,7 @@ def archive_resource(context, resource, log, result=None, url_timeout=30): - - # move the temp file to the resource's archival directory - saved_file = os.path.join(archive_dir, file_name) -- shutil.move(result['saved_file'], saved_file) -+ shutil.move(result['saved_file'], saved_file, copy_function=shutil.copy) - log.info('Going to do chmod: %s', saved_file) - try: - os.chmod(saved_file, 0o644) # allow other users to read it