fix to smi.builder to explicitly fail on any MIB file access error but ENOENT

pull/45/head
elie 2015-03-07 18:00:57 +00:00
parent e1f6af5f0e
commit a455b4c3fa
2 changed files with 22 additions and 5 deletions

View File

@ -112,6 +112,8 @@ Revision 4.2.6rc2
- Fix to file descriptor leak at MibBuilder.
- Fix to rfc2576.v2ToV1() to ignore impossible errorStatus.
- Fix to rfc2576.v1ToV2() to reset ErrorStatus==noSuchName on proxying.
- Fix to smi.builder to explicitly fail on any MIB file access error
but ENOENT.
Revision 4.2.5
--------------

View File

@ -1,5 +1,9 @@
# MIB modules loader
import os, sys, imp, struct, marshal, time, traceback
try:
from errno import ENOENT
except ImportError:
ENOENT = -1
from pysnmp.smi import error
from pysnmp import debug
@ -55,7 +59,11 @@ class __AbstractMibSource:
try:
pycData = self._getData(f + pycSfx, pycMode)
except IOError:
pycTime = -1
why = sys.exc_info()[1]
if why.errno == ENOENT or ENOENT == -1:
pycTime = -1
else:
raise error.SmiError('MIB file %s access error: %s' % (f+pycSfx, why))
else:
if self.__magic == pycData[:4]:
pycData = pycData[4:]
@ -76,7 +84,11 @@ class __AbstractMibSource:
try:
pyTime = self._getTimestamp(f+pySfx)
except (IOError, OSError):
pyTime = -1
why = sys.exc_info()[1]
if why.errno == ENOENT or ENOENT == -1:
pyTime = -1
else:
raise error.SmiError('MIB file %s access error: %s' % (f+pySfx, why))
else:
break
@ -166,9 +178,12 @@ class DirMibSource(__AbstractMibSource):
data = fp.read()
fp.close()
return data
except OSError:
pass
raise IOError # pretend there's no such file
except (IOError, OSError):
why = sys.exc_info()[1]
if why.errno != ENOENT and ENOENT != -1:
raise error.SmiError('MIB file %s access error: %s' % (os.path.join(self._srcName, f), why))
raise IOError(ENOENT, 'No such file or directory')
class MibBuilder:
loadTexts = 0