freemyipod r792 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r791‎ | r792 | r793 >
Date:01:34, 19 November 2011
Author:theseven
Status:new
Tags:
Comment:
emcore.py: Fix a couple bugs
Modified paths:
  • /emcore/trunk/tools/emcore.py (modified) (history)

Diff [purge]

Index: emcore/trunk/tools/emcore.py
@@ -1016,7 +1016,7 @@
10171017 self.logger.info("Reading volume %s sectors %X - %X to %s..." % (volume, sector, sector + count - 1, file))
10181018 while count > 0:
10191019 sectors = min(count, int(buffsize / storageinfo.sectorsize))
1020 - self.emcore.storage_read_sectors_md(volume, sector, sectors, buffsize, buffer)
 1020+ self.emcore.storage_read_sectors_md(volume, sector, sectors, buffer)
10211021 f.write(self.emcore.read(buffer, storageinfo.sectorsize * sectors))
10221022 sector = sector + sectors
10231023 count = count - sectors
@@ -1032,6 +1032,7 @@
10331033 """
10341034 Writes contents of <file> to <count> sectors starting at <sector> on storage <volume>,
10351035 buffering them in memory at [buffer] in chunks of [buffsize] bytes (both optional).
 1036+ If <count> is -1, the number of sectors will be determined from the file size.
10361037 """
10371038 volume = to_int(volume)
10381039 sector = to_int(sector)
@@ -1043,6 +1044,7 @@
10441045 raise ArgumentError("Could not open local file for reading.")
10451046 try:
10461047 storageinfo = self.emcore.storage_get_info(volume)
 1048+ if count == -1: count = int((os.path.getsize(file) + storageinfo.sectorsize - 1) / storageinfo.sectorsize)
10471049 buffsize = min(buffsize, storageinfo.sectorsize * count)
10481050 if buffer is None:
10491051 buffer = self.emcore.memalign(0x10, buffsize)
@@ -1055,11 +1057,13 @@
10561058 while count > 0:
10571059 sectors = min(count, int(buffsize / storageinfo.sectorsize))
10581060 bytes = storageinfo.sectorsize * sectors
1059 - data = f.read(bytes)
1060 - if len(data) == 0: break
1061 - while len(data) < bytes: data = data + f.read(bytes - len(data))
 1061+ data = b""
 1062+ while len(data) < bytes:
 1063+ new = f.read(bytes - len(data))
 1064+ data = data + new
 1065+ if len(new) == 0: break
10621066 self.emcore.write(buffer, data)
1063 - self.emcore.storage_write_sectors_md(volume, sector, sectors, buffsize, buffer)
 1067+ self.emcore.storage_write_sectors_md(volume, sector, sectors, buffer)
10641068 sector = sector + sectors
10651069 count = count - sectors
10661070 finally: