From 26f5281eed8f7f8999e1c3ce0a7185d44672c9fd Mon Sep 17 00:00:00 2001 From: "jonathan.ehret" <ehret@vr.rwth-aachen.de> Date: Sat, 8 Jul 2023 22:31:03 +0200 Subject: [PATCH] minor readbility refactoring and not requiring file modification time to be send (for backward compatibility) --- LaunchScript/VirtualAcousticsStarterServer.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/LaunchScript/VirtualAcousticsStarterServer.py b/LaunchScript/VirtualAcousticsStarterServer.py index 7f46794..d5f6817 100644 --- a/LaunchScript/VirtualAcousticsStarterServer.py +++ b/LaunchScript/VirtualAcousticsStarterServer.py @@ -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 -- GitLab