问题
I'm working with shelve in python 2.7.6 for caching calculations, and I've ran into the issue described HERE for shelve files produced by me and implemented the suggested solution in a function that merges a file other
into the file target
:
... # target and other are strings
# Loads the gdbm module, as suggested
mod = __import__("gdbm")
# Open target for modifications
tar = shelve.Shelf(mod.open(target, 'c', 0666)) # THROWS EXCEPTION
# Open other for reading
oth = shelve.Shelf(mod.open(other, 'r'))
...
The two files are owned by me, are recorded in a local filesystem and have posix permissions set to 0666
, or, equivalently, -rw-rw-rw-
in my Linux Mint box, so that the obvious checks have been performed:
$ ls -l
-rw-rw-rw- 1 myusr mygrp 11694080 Sep 17 21:24 cache
-rw-rw-rw- 1 myusr mygrp 12189696 Sep 17 21:23 cache.0
Here, cache
is the target
, and cache.0
is the other
file. The current working directory is owned by me and has permissions 0775
, and I can create files with touch
, cp
, etc., at will with no problems, and I've even set my umask
to 0000
, so new files are created with 0666
, or, equivalently, -rw-rw-rw-
permissions.
I've even matched the actual file permissions with the permissions in the gdbm.open() call, according to its documentation; however, to no avail.
Update: By running the python code with sudo
, i.e., with superuser privileges, the error occurs on the same line; however with a different message: gdbm error: Bad magic number
! This is very strange as the very point of using a (seemingly) lower-level module (gdbm
as opposed to shelve
) was precisely bypassing database type detection.
Update #2: Running python whichdb.py
on the files returns dbhash
; however, changing the module to the dbhash
on the loading code still gives the following errors:
bsddb.db.DBAccessError: (13, 'Permission denied')
when running as user, but
bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- BDB0210 ././merge-cache.py: metadata page checksum error')
when running with sudo; merge-cache.py
is my code's name.
This new error is discussed here, in connection with python version, but (i) my python version is different than the one in that post, and (ii) files are created and later read with the same version of python.
This answer indicates shelve
gets "wasted" with large sets, but the problem I'm reporting occurs with smaller databases as well.
Question: How can I open these shelve files using python-2.7.6? (upgrading python is not an option).
来源:https://stackoverflow.com/questions/39553264/got-gdbm-error-13-permission-denied-despite-posix-permissions-seeming-ok