Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from admin import *
from arb import *
from browse import *
from checksums import *
from datacite import *
from folder import *
from groups import *
Expand Down
30 changes: 30 additions & 0 deletions checksums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Functions for data object checksums."""

__copyright__ = 'Copyright (c) 2026, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import irods_types

from util import data_object, log, msi, rule

__all__ = ['rule_verify_checksum']


@rule.make()
def rule_verify_checksum(ctx: rule.Context, path: str) -> None:
"""Verify checksum of a data object, calculate checksum if it doesn't exist.

:param ctx: Combined type of a callback and rei struct
:param path: Path of data object to verify
"""
if data_object.checksum(ctx, path):
options = "verifyChksum="
else:
options = "ChksumAll=++++forceChksum="

try:
msi.data_obj_chksum(ctx, path, options, irods_types.BytesBuf())
checksum = data_object.checksum(ctx, path)
log.write(ctx, f"Verified checksum of <{path}>: {checksum}")
except Exception as e:
log.write(ctx, f"Could not verify checksum of <{path}>: {str(e)}")
8 changes: 7 additions & 1 deletion policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,15 @@ def pep_resource_modified_post(ctx: rule.Context,
# Log errors, but continue with revisions.
log.write(ctx, 'rule_meta_modified_post failed: ' + str(e))

# ctx.uuResourceModifiedPostRevision(instance_name, zone, path)
revisions.resource_modified_post_revision(ctx, instance_name, zone, path)

if config.enable_async_checksum:
# Calculate and verify checksum of data object.
ctx.delayExec(
f"<PLUSET>{config.async_checksum_delay_time}s</PLUSET><INST_NAME>irods_rule_engine_plugin-irods_rule_language-instance</INST_NAME>",
f"rule_verify_checksum('{path}')",
"")


@rule.make()
def py_acPostProcForObjRename(ctx: rule.Context, src: str, dst: str) -> None:
Expand Down
3 changes: 3 additions & 0 deletions rules_uu.cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ token_lifetime =
enable_inactivity_notification =
inactivity_cutoff_months =

enable_async_checksum =
async_checksum_delay_time =

async_replication_delay_time =
async_replication_max_rss =
async_revision_delay_time =
Expand Down
8 changes: 0 additions & 8 deletions tools/verify-checksums.r

This file was deleted.

2 changes: 2 additions & 0 deletions util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def __repr__(self) -> str:
token_length=0,
token_lifetime=0,
token_expiration_notification=0,
enable_async_checksum=False,
async_checksum_delay_time=0,
async_replication_delay_time=0,
async_replication_max_rss=1000000000,
async_revision_delay_time=0,
Expand Down
23 changes: 23 additions & 0 deletions util/data_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ def size(ctx: rule.Context, path: str) -> int | None:
return None


def checksum(ctx: rule.Context, path: str) -> str | None:
"""Get a data object's checksum.

:param ctx: Combined type of a callback and rei struct
:param path: Path to iRODS data object

:returns: Data object's checksum or None if object is not found
"""
coll_name, data_name = pathutil.chop(path)
coll_name = misc.escape(coll_name)
data_name = misc.escape(data_name)
iter = genquery.Query(
ctx, "DATA_CHECKSUM",
f"COLL_NAME = '{coll_name}' AND DATA_NAME = '{data_name}'",
output=genquery.AS_LIST
)

for row in iter:
return row[0]

return None


def has_replica_with_status(ctx: rule.Context, path: str, statuses: List) -> bool:
"""Check if data object has replica with specified replica statuses.

Expand Down
50 changes: 0 additions & 50 deletions uuBatch.r

This file was deleted.