diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-12-13 23:33:28 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-12-13 23:33:28 -0800 |
commit | 29315ffe4d5c0d4030252ed25ecd81905654d534 (patch) | |
tree | 93574fb4231172bcf1a04d306e1c86ab7697a6eb | |
parent | 7de863659d624468830ebc342806f255f245b4af (diff) | |
download | portage-29315ffe4d5c0d4030252ed25ecd81905654d534.tar.gz portage-29315ffe4d5c0d4030252ed25ecd81905654d534.tar.bz2 portage-29315ffe4d5c0d4030252ed25ecd81905654d534.zip |
lockfile: deprecate file object or fd parameters
Support for file object or integer file descriptor parameters is
deprecated due to ambiguity in whether or not it's safe to close
the file descriptor, making it prone to "Bad file descriptor" errors
or file descriptor leaks.
-rw-r--r-- | pym/portage/locks.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/pym/portage/locks.py b/pym/portage/locks.py index 59026e90a..297609c27 100644 --- a/pym/portage/locks.py +++ b/pym/portage/locks.py @@ -51,14 +51,24 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, if not mypath: raise InvalidData(_("Empty path given")) + # Support for file object or integer file descriptor parameters is + # deprecated due to ambiguity in whether or not it's safe to close + # the file descriptor, making it prone to "Bad file descriptor" errors + # or file descriptor leaks. if isinstance(mypath, basestring) and mypath[-1] == '/': mypath = mypath[:-1] lockfilename_path = mypath if hasattr(mypath, 'fileno'): + warnings.warn("portage.locks.lockfile() support for " + "file object parameters is deprecated. Use a file path instead.", + DeprecationWarning, stacklevel=2) lockfilename_path = getattr(mypath, 'name', None) mypath = mypath.fileno() if isinstance(mypath, int): + warnings.warn("portage.locks.lockfile() support for integer file " + "descriptor parameters is deprecated. Use a file path instead.", + DeprecationWarning, stacklevel=2) lockfilename = mypath wantnewlockfile = 0 unlinkfile = 0 @@ -157,7 +167,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, if not isinstance(lockfilename, int): # If a file object was passed in, it's not safe # to close the file descriptor because it may - # still be in use (for example, see emergelog). + # still be in use. os.close(myfd) lockfilename_path = _unicode_decode(lockfilename_path, encoding=_encodings['fs'], errors='strict') |