kopia lustrzana https://github.com/peterhinch/micropython_eeprom
bdevice.py: Protect _set_pagesize against exceptions.
rodzic
a5ebd63bfa
commit
9a9c588f9b
|
@ -100,6 +100,7 @@ class EepromDevice(BlockDevice):
|
|||
if page_size is None: # Measure it
|
||||
self._psize(16) # Conservative
|
||||
old = self[:129] # Save old contents (nonvolatile!)
|
||||
try:
|
||||
self._psize(256) # Ambitious
|
||||
r = (16, 32, 64, 128) # Legal page sizes + 256
|
||||
for x in r:
|
||||
|
@ -111,6 +112,10 @@ class EepromDevice(BlockDevice):
|
|||
ps = 256
|
||||
self._psize(ps)
|
||||
self[:129] = old
|
||||
except: # If anything goes wrong, restore old data and raise
|
||||
for n, v in enumerate(old):
|
||||
self[n] = v
|
||||
raise
|
||||
else: # Validated page_size was supplied
|
||||
self._psize(page_size)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue