Skip to content

Commit

Permalink
[stdlib] "prettier" implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
  • Loading branch information
artemiogr97 committed Jun 4, 2024
1 parent 32ecc93 commit f1a9416
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions stdlib/src/tempfile/tempfile.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -282,21 +282,23 @@ struct NamedTemporaryFile:
var potential_name = final_dir / (
prefix + _get_random_name() + suffix
)
if not os.path.exists(potential_name):
if os.path.exists(potential_name):
continue
try:
# TODO for now this name could be relative,
# python implementation expands the path,
# but several functions are not yet implemented in mojo
# i.e. abspath, normpath
self.name = potential_name.__fspath__()
break
self._file_handle = FileHandle(
potential_name.__fspath__(), mode=mode
)
return
except:
continue
else:
raise Error("Failed to create temporary file")

try:
self._file_handle = FileHandle(self.name, mode=mode)
except:
raise Error("Failed to create temporary file")

@always_inline
fn __del__(owned self):
"""Closes the file handle."""
Expand Down

0 comments on commit f1a9416

Please sign in to comment.