Skip to content

Commit

Permalink
YDA-5559: keep original modified time when copying/moving files and f…
Browse files Browse the repository at this point in the history
…olders

Co-authored-by: Lazlo Westerhof <[email protected]>
  • Loading branch information
kaur16 and lwesterhof authored Jan 10, 2024
1 parent bc3b6e7 commit 8bd0e8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions util/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,8 @@ def copy(ctx, path_org, path_copy, force=True):
coll = row[0]
copy(ctx, coll, path_copy + coll[len(path_org):], force)

# Update modified date for collection if overwrite
if force:
json_inp = {"logical_path": path_copy}
msi.touch(ctx, json.dumps(json_inp))
json_inp = {"logical_path": path_copy, "options": {"reference": path_org}}
msi.touch(ctx, json.dumps(json_inp))


def move(ctx, path_org, path_move, force=True):
Expand Down
12 changes: 12 additions & 0 deletions util/data_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
__license__ = 'GPLv3, see LICENSE'

import binascii
import json

import genquery
import irods_types
Expand Down Expand Up @@ -133,6 +134,9 @@ def copy(ctx, path_org, path_copy, force=True):
'numThreads=1++++verifyChksum={}'.format('++++forceFlag=' if force else ''),
irods_types.BytesBuf())

json_inp = {"logical_path": path_copy, "options": {"reference": path_org}}
msi.touch(ctx, json.dumps(json_inp))


def remove(ctx, path, force=False):
"""Delete a data object.
Expand All @@ -159,12 +163,20 @@ def rename(ctx, path_org, path_target):
This may raise a error.UUError if the file does not exist, or when the user
does not have write permission.
"""
# Get the modified date of the data object
ret = msi.obj_stat(ctx, path_org, irods_types.RodsObjStat())
output = ret['arguments'][1]
modify_time = int(str(output.modifyTime))

msi.data_obj_rename(ctx,
path_org,
path_target,
'0',
irods_types.BytesBuf())

json_inp = {"logical_path": path_target, "options": {"seconds_since_epoch": modify_time}}
msi.touch(ctx, json.dumps(json_inp))


def name_from_id(ctx, data_id):
"""Get data object name from data object id.
Expand Down
1 change: 1 addition & 0 deletions util/msi.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def _make_exception(name, message):
sudo_obj_acl_set, SudoObjAclSetError = make('SudoObjAclSet', 'Could not set ACLs as admin')

touch, TouchError = make('_touch', 'Could not update the data object or collection')
obj_stat, ObjStatError = make('ObjStat', 'Could not get the stat of data object or collection')


def kvpair(ctx, k, v):
Expand Down

0 comments on commit 8bd0e8a

Please sign in to comment.