-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Closed
Description
In which file did you encounter the issue?
Describe the issue
As written the crud_object.py file main function will fail with this error (on windows at least):
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\owner\\AppData\\Local\\Temp\\tmp3preaezj'
Traceback (most recent call last):
File "crud_object.py", line 150, in <module>
main(args.bucket, args.filename, args.reader, args.owner)
File "crud_object.py", line 47, in main
if not filecmp.cmp(filename, tmpfile.name):
File "E:\Python\Python35\lib\filecmp.py", line 62, in cmp
outcome = _do_cmp(f1, f2)
File "E:\Python\Python35\lib\filecmp.py", line 75, in _do_cmp
with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2:
The issue is that NamedTemporaryFile keeps the file handle open so that when filecmp attempts to open it, it will fail with a permission denied error. The correct way to do this is shown below:
print('Fetching object..')
with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as tmpfile:
get_object(bucket, filename, out_file=tmpfile)
tmpfile.seek(0)
tmpName = tmpfile.name
if not filecmp.cmp(filename, tmpName):
raise Exception('Downloaded file != uploaded object')
print('Deleting object..')
os.remove(tmpName)
Metadata
Metadata
Assignees
Labels
No labels