linuxmint / warpinator

Share files across the LAN
GNU General Public License v3.0
1.21k stars 81 forks source link

[Small bug + fix] Server.py: retry from client fails #114

Closed williamMillington closed 2 years ago

williamMillington commented 2 years ago

Hello!

I believe I've found a very minor bug in server.py that causes a 'sending' transfer from a client machine to fail on retry. (I am using version 1.2.4, but as far as I checked this has not been addressed in any commits since)

I tried restarting a transfer from the Warpinator Android app ([https://github.com/slowscript/warpinator-android]), which failed. Debug mode on the computer revealed:

2021-12-12 22:01:53,063::warpinator::ERROR: Exception calling application: local variable 'op' referenced before assignment -- _server.py (line 397)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/grpc/_server.py", line 389, in _call_behavior
    return behavior(argument, context), True
  File "/usr/libexec/warpinator/server.py", line 460, in ProcessTransferOpRequest
    op.use_compression = request.info.use_compression
UnboundLocalError: local variable 'op' referenced before assignment

The transfer restart worked as expected when the changes below were made to my local 'server.py' source file.

Within the 'try' statement in the for-loop at 457: https://github.com/linuxmint/warpinator/blob/01e2e1d0a1eac75b70d5990fd4a0cdc4d99af932/src/server.py#L457

for existing_op in remote_machine.transfer_ops:
            if existing_op.start_time == request.info.timestamp:
                # Compression could have changed for a restart, as it's not tied to the op.
                try:
                    op.use_compression = request.info.use_compression
                except AttributeError:
                    op.use_compression = False
                existing_op.set_status(OpStatus.WAITING_PERMISSION)
                self.add_receive_op_to_remote_machine(existing_op)
                return void

op.use_compression = request.info.use_compression and op.use_compression = False

should be:

existing_op.use_compression = request.info.use_compression and existing_op.use_compression = False

to match the for-loop declaration.

Hope this is helpful!

mtwebster commented 2 years ago

Thanks a lot! https://github.com/linuxmint/warpinator/commit/cd0b33a0618b431642ef7abd806cadb9cb8fe935