Skip to content

Commit c9b94ef

Browse files
committed
- pycboard file transfer now only checks whether the filesystem is full if it is unable to transfer a file.
1 parent 43d83ed commit c9b94ef

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

com/pycboard.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ def _fs_free_space(drive='/flash'):
3131
def _receive_file(file_path, file_size):
3232
usb = pyb.USB_VCP()
3333
usb.setinterrupt(-1)
34-
if file_size > _fs_free_space():
35-
usb.write(b'NS')
36-
return
37-
else:
38-
usb.write(b'OK')
3934
buf_size = 512
4035
buf = bytearray(buf_size)
4136
buf_mv = memoryview(buf)
@@ -49,7 +44,10 @@ def _receive_file(file_path, file_size):
4944
bytes_remaining -= bytes_read
5045
f.write(buf_mv[:bytes_read])
5146
except:
52-
usb.write(b'ER')
47+
if _fs_free_space() < bytes_remaining:
48+
usb.write(b'NS') # Out of space.
49+
else:
50+
usb.write(b'ER')
5351

5452
# ----------------------------------------------------------------------------------------
5553
# Pycboard class.
@@ -188,16 +186,8 @@ def transfer_file(self, file_path, target_path=None):
188186
for i in range(3):
189187
if file_hash == self.get_file_hash(target_path):
190188
return
191-
try:
192-
self.remove_file(file_path)
193-
time.sleep(0.01)
194-
except PyboardError:
195-
pass
196189
self.exec_raw_no_follow("_receive_file('{}',{})"
197190
.format(target_path, file_size))
198-
if not self.serial.read(2) == b'OK':
199-
self.print('\n\nInsufficient space on pyboard filesystem to transfer file.')
200-
raise PyboardError
201191
with open(file_path, 'rb') as f:
202192
while True:
203193
chunk = f.read(512)
@@ -206,15 +196,16 @@ def transfer_file(self, file_path, target_path=None):
206196
self.serial.write(chunk)
207197
response_bytes = self.serial.read(2)
208198
if response_bytes != b'OK':
209-
self.print('\n\nError: Unable to transfer file. See the troubleshooting docs:\n'
210-
'https://pycontrol.readthedocs.io/en/latest/user-guide/troubleshooting/')
211-
199+
if response_bytes == b'NS':
200+
self.print('\n\nInsufficient space on pyboard filesystem to transfer file.')
201+
else:
202+
self.print('\n\nError: Unable to transfer file. See the troubleshooting docs:\n'
203+
'https://pycontrol.readthedocs.io/en/latest/user-guide/troubleshooting/')
212204
time.sleep(0.01)
213205
self.serial.reset_input_buffer()
214206
raise PyboardError
215207
self.follow(3)
216208

217-
218209
def transfer_folder(self, folder_path, target_folder=None, file_type='all',
219210
show_progress=False):
220211
'''Copy a folder into the root directory of the pyboard. Folders that

0 commit comments

Comments
 (0)