-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dumbdbm should not commit if in read mode #73033
Comments
Or at the very least, if there is an OSError in _update, an error should be raised instead of ignoring this error. In the current state of the code, if there was an OSError while reading the dirfile, the dirfile would be overwritten with a blank file when it is closed. |
Do you have concrete example when not ignoring an OSError in _update causes an issue? This is needed for writing tests. |
I'm not sure how to create an OSError. But perhaps something like this: ''' db = dumb.open('temp', flag='n')
db['foo'] = 'bar'
db.close()
db = dumb.open('temp', flag='r')
print(len(db.keys()))
db.close
os.rename('temp.dir', 'temp_.dir') # simulates OSError
db = dumb.open('temp', flag='r')
os.rename('temp_.dir', 'temp.dir')
db.close()
db = dumb.open('temp', flag='r')
assert len(db.keys()) > 0
''' |
This example is too artificial. But there is a real issue: opening read-only files in read mode. Currently this causes a PermissionError on closing. For backward compatibility flags 'r' and 'w' are ignored. I.e. opening with 'r' and 'w' creates a file if it is not existing, and opening with 'r' allows modifying the database. Since 3.6 this emits deprecation warnings (bpo-21708). In future versions this will be an error. Proposed patch makes two changes:
May be the first change can be backported. |
#1 makes sense to be backported. On Thu, Dec 1, 2016 at 8:41 PM, Serhiy Storchaka <[email protected]>
|
New changeset 0516f54491cb by Serhiy Storchaka in branch '2.7': |
The first part is committed in 2.7. I'll commit it in 3.5-3.7 after releasing 3.6.0. |
Serhiy: The Windows buildbots are having trouble removing read-only files. Maybe restore the write mode for the end of the test, or fix support.rmtree()? See <https://docs.python.org/3/library/shutil.html#rmtree-example\>. |
New changeset dc7c86de9e13 by Martin Panter in branch '2.7': |
http://buildbot.python.org/all/builders/AMD64%20Windows8%202.7/builds/9/steps/test/logs/stdio Traceback (most recent call last):
File "D:\buildarea\2.7.bolen-windows8\build\lib\test\test_dumbdbm.py", line 190, in test_readonly_files
test_support.rmtree(dir)
File "D:\buildarea\2.7.bolen-windows8\build\lib\test\test_support.py", line 289, in rmtree
_rmtree(path)
File "D:\buildarea\2.7.bolen-windows8\build\lib\test\test_support.py", line 245, in _rmtree
_waitfor(_rmtree_inner, path, waitall=True)
File "D:\buildarea\2.7.bolen-windows8\build\lib\test\test_support.py", line 199, in _waitfor
func(pathname)
File "D:\buildarea\2.7.bolen-windows8\build\lib\test\test_support.py", line 244, in _rmtree_inner
_force_run(path, os.unlink, fullname)
File "D:\buildarea\2.7.bolen-windows8\build\lib\test\test_support.py", line 194, in _force_run
return func(*args)
WindowsError: [Error 5] Access is denied: '@test_3796_tmp\\db.dat'
----------------------------------------------------------------------
'test_dumbdbm' left behind directory '@test_3796_tmp'
. . .
test test_dumbdbm crashed -- <type 'exceptions.WindowsError'>: [Error 5] Access is denied: '@test_3796_tmp\\db.dat'
Traceback (most recent call last):
File "D:\buildarea\2.7.bolen-windows8\build\PCbuild\..\Lib\test\regrtest.py", line 948, in runtest_inner
test_time = time.time() - start_time
File "D:\buildarea\2.7.bolen-windows8\build\PCbuild\..\Lib\test\regrtest.py", line 899, in __exit__
restore(original)
File "D:\buildarea\2.7.bolen-windows8\build\PCbuild\..\Lib\test\regrtest.py", line 876, in restore_files
test_support.rmtree(fn)
. . .
'test_dumbdbm' left behind directory '@test_3796_tmp' and it couldn't be removed: [Error 5] Access is denied: '@test_3796_tmp\\db.dat'
Traceback (most recent call last):
File "D:\buildarea\2.7.bolen-windows8\build\PCbuild\..\Lib\test\regrtest.py", line 1679, in <module>
main()
File "D:\buildarea\2.7.bolen-windows8\build\lib\contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "D:\buildarea\2.7.bolen-windows8\build\lib\test\test_support.py", line 765, in temp_cwd
rmtree(name) |
New changeset cb4a892e9b66 by Serhiy Storchaka in branch '2.7': |
Thanks Martin for pointing on this. Now buildbots are green. |
New changeset 0a74bc7ba462 by Serhiy Storchaka in branch '3.5': New changeset 0c532bd28539 by Serhiy Storchaka in branch '3.6': New changeset 2f59be67830c by Serhiy Storchaka in branch 'default': New changeset a10361dfbf64 by Serhiy Storchaka in branch 'default': |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: