From 29315ffe4d5c0d4030252ed25ecd81905654d534 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 13 Dec 2011 23:33:28 -0800 Subject: 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. --- pym/portage/locks.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'pym/portage/locks.py') 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') -- cgit v1.2.3-1-g7c22