storage/reflink: use context managers in is_supported()

Don't rely on garbage collection to close and remove the tempfiles.
This commit is contained in:
Rusty Bird 2018-09-13 19:46:48 +00:00
parent 867baf47d1
commit 5756e870bd
No known key found for this signature in database
GPG Key ID: 469D78F47AAF2ADF

View File

@ -456,7 +456,7 @@ def is_supported(dst_dir, src_dir=None):
'''
if src_dir is None:
src_dir = dst_dir
dst = tempfile.TemporaryFile(dir=dst_dir)
src = tempfile.TemporaryFile(dir=src_dir)
src.write(b'foo') # don't let any filesystem get clever with empty files
return _attempt_ficlone(src, dst)
with tempfile.TemporaryFile(dir=src_dir) as src, \
tempfile.TemporaryFile(dir=dst_dir) as dst:
src.write(b'foo') # don't let any fs get clever with empty files
return _attempt_ficlone(src, dst)