Skip to content

Commit 704ed91

Browse files
1 parent bdd7525 commit 704ed91

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

fsspec/implementations/cached.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ def save_cache(self):
180180
for c in cache.values():
181181
if isinstance(c["blocks"], set):
182182
c["blocks"] = list(c["blocks"])
183-
fn2 = tempfile.mktemp()
184-
with open(fn2, "wb") as f:
183+
fd2, fn2 = tempfile.mkstemp()
184+
with open(fd2, "wb") as f:
185185
pickle.dump(cache, f)
186186
self._mkcache()
187187
move(fn2, fn)
@@ -723,10 +723,13 @@ class LocalTempFile:
723723
"""A temporary local file, which will be uploaded on commit"""
724724

725725
def __init__(self, fs, path, fn=None, mode="wb", autocommit=True, seek=0):
726-
fn = fn or tempfile.mktemp()
726+
if fn:
727+
self.fn = fn
728+
self.fh = open(fn, mode)
729+
else:
730+
fd, self.fn = tempfile.mkstemp()
731+
self.fh = open(fd, mode)
727732
self.mode = mode
728-
self.fn = fn
729-
self.fh = open(fn, mode)
730733
if seek:
731734
self.fh.seek(seek)
732735
self.path = path
@@ -760,6 +763,13 @@ def discard(self):
760763
def commit(self):
761764
self.fs.put(self.fn, self.path)
762765

766+
@property
767+
def name(self):
768+
if isinstance(self.fh.name, str):
769+
return self.fh.name # initialized by open()
770+
else:
771+
return self.fn # initialized by tempfile.mkstemp()
772+
763773
def __getattr__(self, item):
764774
return getattr(self.fh, item)
765775

0 commit comments

Comments
 (0)