Skip to content

Commit

Permalink
Add additional checking to PCAs for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
adammcdonagh authored Jan 29, 2024
1 parent 88884ec commit 61d2b09
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Bump version of opentaskpy required
- Alter logging for found files to only print ones that match regex
- Fixes tests that correctly started failing after upgrading opentaskpy version
- Additional checking to PCAs to validate that it has actually happened

## v24.4.1

Expand Down
30 changes: 30 additions & 0 deletions src/opentaskpy/addons/aws/remotehandlers/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ def handle_post_copy_action(self, files: list[str]) -> int:
"Quiet": True,
},
)

# Verify the files have been deleted
for file in files:
try:
self.s3_client.head_object(Bucket=self.spec["bucket"], Key=file)
except Exception as e:
self.logger.error(e)
self.logger.error(f"Failed to delete file: {file}")
return 1

# Copy the files to the new location, and then delete the originals
if (
self.spec["postCopyAction"]["action"] == "move"
Expand All @@ -114,6 +124,8 @@ def handle_post_copy_action(self, files: list[str]) -> int:
new_file,
)

self.logger.info(f'"Moving" file from {file} to {new_file}')

self.s3_client.copy_object(
Bucket=self.spec["bucket"],
CopySource={
Expand All @@ -122,13 +134,31 @@ def handle_post_copy_action(self, files: list[str]) -> int:
},
Key=new_file,
)

# Check that the copy worked
try:
self.s3_client.head_object(Bucket=self.spec["bucket"], Key=new_file)
except Exception as e:
# Print the exception message
self.logger.error(e)
self.logger.error(f"Failed to copy file: {file}")
return 1

self.s3_client.delete_objects(
Bucket=self.spec["bucket"],
Delete={
"Objects": [{"Key": file}],
"Quiet": True,
},
)

# Check that the delete worked
try:
self.s3_client.head_object(Bucket=self.spec["bucket"], Key=file)
except Exception as e:
self.logger.error(e)
self.logger.error(f"Failed to delete file: {file}")
return 1
return 0

def list_files(
Expand Down

0 comments on commit 61d2b09

Please sign in to comment.