Skip to content

Commit

Permalink
Removed commented line, changed TMP env var to TMPDIR to comply with …
Browse files Browse the repository at this point in the history
…uss temporary directories and used os.path.join in favor of just concatenating strings
  • Loading branch information
fernandofloresg committed Oct 4, 2024
1 parent 6aac655 commit 1f2bfa6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugins/action/zos_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def _copy_to_remote(self, src, is_dir=False, ignore_stderr=False):
msg = f"Failed to resolve remote temporary directory {self.tmp_dir}. Ensure that the directory exists and user has proper access."
return self._exit_action({}, msg, failed=True)
self.tmp_dir = stdout.decode("utf-8").replace("\r", "").replace("\n", "")
temp_path = "{0}/{1}/{2}".format(self.tmp_dir, _create_temp_path_name(), os.path.basename(src))
temp_path = os.path.join(self.tmp_dir, _create_temp_path_name(), os.path.basename(src))
self._connection.exec_command("mkdir -p {0}".format(os.path.dirname(temp_path)))
_src = src.replace("#", "\\#")
_sftp_action = 'put'
Expand Down
17 changes: 8 additions & 9 deletions plugins/modules/zos_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ def convert_encoding(self, src, encoding, remote_src):
if os.path.isdir(new_src):
try:
if remote_src:
temp_dir = tempfile.mkdtemp(prefix=os.environ['TMP'])
temp_dir = tempfile.mkdtemp(prefix=os.environ['TMPDIR'])
shutil.copytree(new_src, temp_dir, dirs_exist_ok=True)
new_src = temp_dir

Expand All @@ -1301,7 +1301,7 @@ def convert_encoding(self, src, encoding, remote_src):
else:
try:
if remote_src:
fd, temp_src = tempfile.mkstemp(dir=os.environ['TMP'])
fd, temp_src = tempfile.mkstemp(dir=os.environ['TMPDIR'])
os.close(fd)
shutil.copy(new_src, temp_src)
new_src = temp_src
Expand Down Expand Up @@ -1464,7 +1464,7 @@ def create_temp_with_lf_endings(self, src):
If the conversion fails.
"""
try:
fd, converted_src = tempfile.mkstemp(dir=os.environ['TMP'])
fd, converted_src = tempfile.mkstemp(dir=os.environ['TMPDIR'])
os.close(fd)

with open(converted_src, "wb") as converted_file:
Expand Down Expand Up @@ -2230,7 +2230,7 @@ def dump_data_set_member_to_file(data_set_member, is_binary):
DataSetMemberAttributeError
When the call to dcp fails.
"""
fd, temp_path = tempfile.mkstemp(dir=os.environ['TMP'])
fd, temp_path = tempfile.mkstemp(dir=os.environ['TMPDIR'])
os.close(fd)

copy_args = dict()
Expand Down Expand Up @@ -2727,7 +2727,7 @@ def cleanup(src_list):
A list of file paths.
"""
module = AnsibleModuleHelper(argument_spec={})
tmp_prefix = os.environ['TMP']
tmp_prefix = os.environ['TMPDIR']
tmp_dir = os.path.realpath("/" + tmp_prefix)
dir_list = glob.glob(tmp_dir + "/ansible-zos-copy-payload*")
conv_list = glob.glob(tmp_dir + "/converted*")
Expand Down Expand Up @@ -3140,8 +3140,7 @@ def normalize_line_endings(src, encoding=None):
src_tag = encoding["from"]

if src_tag != "IBM-037":
# fd, converted_src = tempfile.mkstemp(dir=os.environ['TMP'])
fd, converted_src = tempfile.mkstemp(dir=os.environ['TMP'])
fd, converted_src = tempfile.mkstemp(dir=os.environ['TMPDIR'])
os.close(fd)

enc_utils.uss_convert_encoding(
Expand Down Expand Up @@ -3270,7 +3269,7 @@ def run_module(module, arg_def):
content = module.params.get('content')

# Set temporary directory at os environment level
os.environ['TMP'] = f"{os.path.realpath(module.tmpdir)}/"
os.environ['TMPDIR'] = f"{os.path.realpath(module.tmpdir)}/"

dest_data_set = module.params.get('dest_data_set')
if dest_data_set:
Expand Down Expand Up @@ -3375,7 +3374,7 @@ def run_module(module, arg_def):
src_tag = encode.Defaults.get_default_system_charset()

# Converting the original src to a temporary one in UTF-8.
fd, converted_src = tempfile.mkstemp(dir=os.environ['TMP'])
fd, converted_src = tempfile.mkstemp(dir=os.environ['TMPDIR'])
os.close(fd)
encode_utils.uss_convert_encoding(
new_src,
Expand Down

0 comments on commit 1f2bfa6

Please sign in to comment.