Skip to content

Commit 39f3b71

Browse files
[Bugfix] [zos_copy] Character "£" not supported in dataset name and supporting "£" in content (#2153)
* Adding support of pound in dataset names and content * updating testcases * Update zos_copy.py * Update zos_copy.py * Create 2153-zos_copy-supporting-pound-in-dataset-name-and content.yml * Update zos_copy.py * Update changelogs/fragments/2153-zos_copy-supporting-pound-in-dataset-name-and content.yml Co-authored-by: Fernando Flores <[email protected]> --------- Co-authored-by: Fernando Flores <[email protected]>
1 parent baa2f6f commit 39f3b71

File tree

3 files changed

+332
-12
lines changed

3 files changed

+332
-12
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minor_changes:
2+
- zos_copy - Added support for british pound character usage in file content and data set names for both source and destination when copying.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/2153)

plugins/modules/zos_copy.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ def file_has_crlf_endings(self, src):
14711471
content = src_file.read(1024)
14721472

14731473
while content:
1474-
# In EBCDIC, \r is bytes 0d
1474+
# In UTF-8, \r is bytes 0d
14751475
if b'\x0d' in content:
14761476
return True
14771477
content = src_file.read(1024)
@@ -3183,8 +3183,8 @@ def allocate_destination_data_set(
31833183

31843184

31853185
def normalize_line_endings(src, encoding=None):
3186-
"""Normalizes src's encoding to IBM-037 (a dataset's default) and then normalizes
3187-
its line endings to LF.
3186+
"""Normalizes src's encoding to UTF-8, then normalizes
3187+
its line endings to LF and after encodes back as per encoding param.
31883188
31893189
Parameters
31903190
----------
@@ -3201,7 +3201,7 @@ def normalize_line_endings(src, encoding=None):
32013201
# Before copying into a destination dataset, we'll make sure that
32023202
# the source file doesn't contain any carriage returns that would
32033203
# result in empty records in the destination.
3204-
# Due to the differences between encodings, we'll normalize to IBM-037
3204+
# Due to the differences between encodings, we'll normalize to UTF-8
32053205
# before checking the EOL sequence.
32063206
enc_utils = encode.EncodeUtils()
32073207
src_tag = enc_utils.uss_file_tag(src)
@@ -3211,25 +3211,40 @@ def normalize_line_endings(src, encoding=None):
32113211
# This should only be true when src is a remote file and no encoding
32123212
# was specified by the user.
32133213
if not encoding:
3214-
encoding = {"from": encode.Defaults.get_default_system_charset()}
3215-
src_tag = encoding["from"]
3216-
3217-
if src_tag != "IBM-037":
3214+
src_tag = encode.Defaults.get_default_system_charset()
3215+
else:
3216+
src_tag = encoding["to"]
3217+
is_convertedto_utf8 = False
3218+
if src_tag != "UTF-8":
32183219
fd, converted_src = tempfile.mkstemp(dir=os.environ['TMPDIR'])
32193220
os.close(fd)
32203221

32213222
enc_utils.uss_convert_encoding(
32223223
src,
32233224
converted_src,
32243225
src_tag,
3225-
"IBM-037"
3226+
"UTF-8"
32263227
)
3227-
copy_handler._tag_file_encoding(converted_src, "IBM-037")
3228+
copy_handler._tag_file_encoding(converted_src, "UTF-8")
32283229
src = converted_src
3230+
is_convertedto_utf8 = True
32293231

32303232
if copy_handler.file_has_crlf_endings(src):
32313233
src = copy_handler.create_temp_with_lf_endings(src)
32323234

3235+
if is_convertedto_utf8:
3236+
fd, converted_source = tempfile.mkstemp(dir=os.environ['TMPDIR'])
3237+
os.close(fd)
3238+
3239+
enc_utils.uss_convert_encoding(
3240+
src,
3241+
converted_source,
3242+
"UTF-8",
3243+
src_tag
3244+
)
3245+
copy_handler._tag_file_encoding(converted_src, src_tag)
3246+
src = converted_source
3247+
32333248
return src
32343249

32353250

@@ -3346,6 +3361,17 @@ def run_module(module, arg_def):
33463361
# Verify the validity of module args. BetterArgParser raises ValueError
33473362
# when a parameter fails its validation check
33483363
# ********************************************************************
3364+
originalsrc = module.params.get('src')
3365+
originaldest = module.params.get('dest')
3366+
issrcpoundexists = False
3367+
isdestpoundexists = False
3368+
# Replacing pound with dollar in src and dest if exists
3369+
if "£" in module.params["src"]:
3370+
issrcpoundexists = True
3371+
module.params["src"] = module.params["src"].replace("£", "$")
3372+
if "£" in module.params["dest"]:
3373+
isdestpoundexists = True
3374+
module.params["dest"] = module.params["dest"].replace("£", "$")
33493375
try:
33503376
parser = better_arg_parser.BetterArgParser(arg_def)
33513377
parser.parse_args(module.params)
@@ -3952,8 +3978,8 @@ def run_module(module, arg_def):
39523978

39533979
res_args.update(
39543980
dict(
3955-
src=module.params.get('src') if is_src_alias else src,
3956-
dest=module.params.get('dest') if is_dest_alias else dest,
3981+
src=originalsrc if issrcpoundexists or is_src_alias else src,
3982+
dest=originaldest if isdestpoundexists or is_dest_alias else dest,
39573983
ds_type=dest_ds_type,
39583984
dest_exists=dest_exists,
39593985
backup_name=backup_name,

0 commit comments

Comments
 (0)