Skip to content
Snippets Groups Projects
Commit 26f5281e authored by Jonathan Ehret's avatar Jonathan Ehret
Browse files

minor readbility refactoring and not requiring file modification time to be...

minor readbility refactoring and not requiring file modification time to be send (for backward compatibility)
parent 4101b672
No related branches found
No related tags found
No related merge requests found
......@@ -408,24 +408,31 @@ class VirtualAcousticsLauncher:
# Receives a file from a client, copies it to a tmp folder and returns the respective fullpath
# Input is a string message starting with "file:"
# it has the content file:[RelativePathToFile]:[FileLengthInBytes]:[ModificationTimeInSecondsSinceEPOCH]
# it has the content file:[RelativePathToFile]:[FileLengthInBytes]:[ProjectName]:[ModificationTimeInSecondsSinceEPOCH]
def receive_file(self, sMessage):
aMessageParts = sMessage.split(":")
Path, Filename = os.path.split(aMessageParts[1])
iBytesToReceive = int(aMessageParts[2])
ProjectName = aMessageParts[3]
iLastModificationTime = int(aMessageParts[4])
Fullpath = os.path.join(self.sCurrentScriptsDirectory, "..", "tmp", ProjectName, Path, "")
print("Should receive file: "+Filename+" in path "+Fullpath+ " with "+str(iBytesToReceive)+" bytes")
iLocalFileLastModification = iLastModificationTime # default set it to the remote file time (in case it does not exist yet)
if os.path.isfile(Fullpath+Filename):
iLocalFileLastModification = os.path.getmtime(Fullpath+Filename)
bNewerFileExists = False
#only do this check if the modification time was transmitted (for backward compatibility)
if len(aMessageParts)>=5:
iLastModificationTime = int(aMessageParts[4])
iLocalFileLastModification = iLastModificationTime # default set it to the remote file time (in case it does not exist yet)
if os.path.isfile(Fullpath+Filename):
iLocalFileLastModification = os.path.getmtime(Fullpath+Filename)
if iLocalFileLastModification<iLastModificationTime:
bNewerFileExists = True
#check whether the file with this exact size (which is not older than the file to send) already exists
if os.path.isfile(Fullpath+Filename) and os.stat(Fullpath+Filename).st_size==iBytesToReceive and iLocalFileLastModification>iLastModificationTime:
iLocalFileSize = os.stat(Fullpath+Filename).st_size
if os.path.isfile(Fullpath+Filename) and iLocalFileSize == iBytesToReceive and not bNewerFileExists :
self.oLauncherConnection.send( b'exists' )
print("File already exists with this size, so no need for resending")
print("File already exists (same size, and more recent modification time), so no need for resending")
else: #file needs to be received
#create dir if it does not exist
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment