Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions sonic_eeprom/eeprom_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,17 @@ def read_eeprom_bytes(self, byteCount, offset=0):
F.seek(self.s + offset)
o = F.read(byteCount)
if len(o) != byteCount:
raise RuntimeError("expected to read %d bytes from %s, " \
%(byteCount, self.p) +
"but only read %d" %(len(o)))
# If we read from the cache file, it may be corrupt. Delete it
# and try again, this time reading from the actual EEPROM.
if not self.cache_update_needed:
os.remove(self.cache_name)
self.cache_update_needed = True
F.close()
return self.read_eeprom_bytes(byteCount, offset)
Copy link
Copy Markdown

@qiluo-msft qiluo-msft Aug 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read_eeprom_bytes [](start = 28, length = 17)

The code may achieve the goal. However, the recursion logic is not intuitive to solve a simple if-else problem.

I will not block this PR. Strongly suggest refactor the code. #Closed

else:
raise RuntimeError("Expected to read %d bytes from %s, " \
%(byteCount, self.p) +
"but only read %d" %(len(o)))
F.close()
return o

Expand Down