Index: emcore/trunk/tools/emcore.py |
— | — | @@ -891,6 +891,8 @@ |
892 | 892 | except IOError:
|
893 | 893 | raise ArgumentError("Could not open local file for writing.")
|
894 | 894 | try:
|
| 895 | + storageinfo = self.emcore.storage_get_info(volume)
|
| 896 | + buffsize = min(buffsize, storageinfo.sectorsize * count)
|
895 | 897 | if buffer is None:
|
896 | 898 | buffer = self.emcore.malloc(buffsize)
|
897 | 899 | malloc = True
|
— | — | @@ -899,7 +901,6 @@ |
900 | 902 | malloc = False
|
901 | 903 | try:
|
902 | 904 | self.logger.info("Reading volume %s sectors %X - %X to %s..." % (volume, sector, sector + count - 1, file))
|
903 | | - storageinfo = self.emcore.storage_get_info(volume)
|
904 | 905 | while count > 0:
|
905 | 906 | sectors = min(count, int(buffsize / storageinfo.sectorsize))
|
906 | 907 | self.emcore.storage_read_sectors_md(volume, sector, sectors, buffsize, buffer)
|
— | — | @@ -928,6 +929,8 @@ |
929 | 930 | except IOError:
|
930 | 931 | raise ArgumentError("Could not open local file for reading.")
|
931 | 932 | try:
|
| 933 | + storageinfo = self.emcore.storage_get_info(volume)
|
| 934 | + buffsize = min(buffsize, storageinfo.sectorsize * count)
|
932 | 935 | if buffer is None:
|
933 | 936 | buffer = self.emcore.malloc(buffsize)
|
934 | 937 | malloc = True
|
— | — | @@ -936,7 +939,6 @@ |
937 | 940 | malloc = False
|
938 | 941 | try:
|
939 | 942 | self.logger.info("Writing %s to volume %s sectors %X - %X..." % (file, volume, sector, sector + count - 1))
|
940 | | - storageinfo = self.emcore.storage_get_info(volume)
|
941 | 943 | while count > 0:
|
942 | 944 | sectors = min(count, int(buffsize / storageinfo.sectorsize))
|
943 | 945 | bytes = storageinfo.sectorsize * sectors
|
— | — | @@ -1023,26 +1025,27 @@ |
1024 | 1026 | except IOError:
|
1025 | 1027 | raise ArgumentError("Could not open local file for writing.")
|
1026 | 1028 | try:
|
1027 | | - if buffer is None:
|
1028 | | - buffer = self.emcore.malloc(buffsize)
|
1029 | | - malloc = True
|
1030 | | - else:
|
1031 | | - buffer = self._hexint(buffer)
|
1032 | | - malloc = False
|
| 1029 | + fd = self.emcore.file_open(remotename, 0)
|
1033 | 1030 | try:
|
1034 | | - self.logger.info("Downloading file " + remotename + " to " + localname + "...")
|
1035 | | - fd = self.emcore.file_open(remotename, 0)
|
| 1031 | + size = self.emcore.file_size(fd)
|
| 1032 | + buffsize = min(buffsize, size)
|
| 1033 | + if buffer is None:
|
| 1034 | + buffer = self.emcore.malloc(buffsize)
|
| 1035 | + malloc = True
|
| 1036 | + else:
|
| 1037 | + buffer = self._hexint(buffer)
|
| 1038 | + malloc = False
|
1036 | 1039 | try:
|
1037 | | - size = self.emcore.file_size(fd)
|
| 1040 | + self.logger.info("Downloading file " + remotename + " to " + localname + "...")
|
1038 | 1041 | while size > 0:
|
1039 | 1042 | bytes = self.emcore.file_read(fd, buffsize, buffer)
|
1040 | 1043 | f.write(self.emcore.read(buffer, bytes))
|
1041 | 1044 | size = size - bytes
|
1042 | 1045 | finally:
|
1043 | | - self.emcore.file_close(fd)
|
| 1046 | + if malloc == True:
|
| 1047 | + self.emcore.free(buffer)
|
1044 | 1048 | finally:
|
1045 | | - if malloc == True:
|
1046 | | - self.emcore.free(buffer)
|
| 1049 | + self.emcore.file_close(fd)
|
1047 | 1050 | finally:
|
1048 | 1051 | f.close()
|
1049 | 1052 | self.logger.info(" done\n")
|
— | — | @@ -1097,6 +1100,7 @@ |
1098 | 1101 | except IOError:
|
1099 | 1102 | raise ArgumentError("Could not open local file for reading.")
|
1100 | 1103 | try:
|
| 1104 | + buffsize = min(buffsize, os.path.getsize(localname))
|
1101 | 1105 | if buffer is None:
|
1102 | 1106 | buffer = self.emcore.malloc(buffsize)
|
1103 | 1107 | malloc = True
|