Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mrdata common public
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hpc-kyb
mrdata common public
Commits
622c27e1
Commit
622c27e1
authored
9 months ago
by
Blake Fitch
Browse files
Options
Downloads
Patches
Plain Diff
enable removing old confirmed_put files (objects) when skip_on_zero_len and replace_existing
parent
b0b3eb2d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pymods/irods_utils/irods_utils.py
+32
-17
32 additions, 17 deletions
pymods/irods_utils/irods_utils.py
with
32 additions
and
17 deletions
pymods/irods_utils/irods_utils.py
+
32
−
17
View file @
622c27e1
...
...
@@ -350,12 +350,13 @@ def streaming_transfer_file_to_object( args ):
return
rc
,
hash_digest256
,
hash_digest512
,
transfer_size
# Returns None or the data_object irods ref.
def
confirmed_put
(
irods_sesh
,
file_pathname
,
new_obj_ipath
,
metadata_dict
=
None
,
datatype
=
None
,
block_size
=
(
2
**
28
),
replace_existing
=
Non
e
):
def
confirmed_put
(
irods_sesh
,
file_pathname
,
new_obj_ipath
,
metadata_dict
=
None
,
datatype
=
None
,
block_size
=
(
2
**
28
),
replace_existing
=
False
,
skip_on_zero_len
=
Fals
e
):
logging
.
debug
(
"
file_pathname:
"
+
file_pathname
+
"
new_obj_ipath:
"
+
new_obj_ipath
+
"
datatype:
"
+
datatype
+
"
block_size:
"
+
str
(
block_size
)
+
"
replace_existing
"
+
str
(
replace_existing
)
)
+
"
replace_existing
"
+
str
(
replace_existing
),
+
"
skip_on_zero_len
"
+
str
(
skip_on_zero_len
)
)
# NOTE: this routine uploades the file as a temporary iRODS object.
# Common sense suggests checking if the objct already exsists, a rare condition first.
...
...
@@ -368,6 +369,34 @@ def confirmed_put( irods_sesh, file_pathname, new_obj_ipath, metadata_dict=None,
logging
.
error
(
"
irods_sesh == None
"
)
return
None
# Figure out if this path in the archive is occupied with pre-existing data.
existing_obj
=
None
try
:
options
=
{
kw
.
VERIFY_CHKSUM_KW
:
''
}
existing_obj
=
irods_sesh
.
data_objects
.
get
(
new_obj_ipath
,
**
options
)
logging
.
debug
(
"
Object aleady exists at ipath:
"
+
new_obj_ipath
)
except
irods_ex
.
DataObjectDoesNotExist
:
logging
.
debug
(
"
DataObjectDoesNotExist
"
+
new_obj_ipath
)
except
irods_ex
.
OBJ_PATH_DOES_NOT_EXIST
:
logging
.
debug
(
"
OBJ_PATH_DOES_NOT_EXIST
"
+
new_obj_ipath
)
except
Exception
as
ex
:
logging
.
error
(
"
Failed using data_onject.get() (but not DataObjectDoesNotExist) ipath:
"
+
new_obj_ipath
+
"
ex:
"
+
str
(
ex
)
+
"
type
"
+
str
(
type
(
ex
))
)
return
None
try
:
upload_file_size
=
os
.
path
.
getsize
(
file_pathname
)
except
Exception
as
ex
:
logging
.
error
(
f
"
FATAL: Failed to get size of file to upload. file_pathname:
{
file_pathname
}
ex:
{
ex
}
"
)
raise
if
upload_file_size
==
0
and
existing_obj
!=
None
and
replace_existing
and
skip_on_zero_len
:
logging
.
warning
(
f
"
got zero len file with replace_existing -- removing current data object. ipath:
{
new_object_ipath
}
"
)
try
:
existing_obj
.
unlink
(
force
=
True
)
except
Exception
as
ex
:
logging
.
warning
(
"
Failed remove zero line file on replace_existing and skip_on_zero_len. ipath: {new_obj_ipath} ex: {ex}
"
)
raise
# Make a timestamped partial tmp file name which, if the upload somehow fails here, will be left behind
# Hopefully this does not happen much, but we have seen at least on case so far.
# Cleanup will need to be done elsewhere.
...
...
@@ -428,20 +457,6 @@ def confirmed_put( irods_sesh, file_pathname, new_obj_ipath, metadata_dict=None,
logging
.
error
(
"
metadata AVU dict >
"
+
str
(
metadata_dict
)
+
"
<
"
)
return
None
existing_obj
=
None
try
:
options
=
{
kw
.
VERIFY_CHKSUM_KW
:
''
}
existing_obj
=
irods_sesh
.
data_objects
.
get
(
new_obj_ipath
,
**
options
)
logging
.
debug
(
"
Object aleady exists at ipath:
"
+
new_obj_ipath
)
except
irods_ex
.
DataObjectDoesNotExist
:
logging
.
debug
(
"
DataObjectDoesNotExist
"
+
new_obj_ipath
)
except
irods_ex
.
OBJ_PATH_DOES_NOT_EXIST
:
logging
.
debug
(
"
OBJ_PATH_DOES_NOT_EXIST
"
+
new_obj_ipath
)
except
Exception
as
ex
:
logging
.
error
(
"
Failed using data_onject.get() (but not DataObjectDoesNotExist) ipath:
"
+
new_obj_ipath
+
"
ex:
"
+
str
(
ex
)
+
"
type
"
+
str
(
type
(
ex
))
)
return
None
mismatch
=
False
if
existing_obj
!=
None
:
...
...
@@ -512,7 +527,7 @@ def confirmed_put( irods_sesh, file_pathname, new_obj_ipath, metadata_dict=None,
dup_obj
.
unlink
(
force
=
True
)
except
Exception
as
ex
:
logging
.
warning
(
"
Failed remove dup when remove_existing flag set. ipath: {dup_ipath} ex: {ex}
"
)
new_obj
=
None
try
:
new_obj
=
irods_sesh
.
data_objects
.
get
(
new_obj_ipath
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment