strip URL when comparing difference between URLs and local files to avoid false positive

This commit is contained in:
Etoh 2015-07-19 13:49:32 +01:00
parent 0245f86588
commit 9cbfcd99b2

View File

@ -9,6 +9,7 @@ import itertools
import hashlib import hashlib
import random import random
import string import string
import urllib
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None): def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
"""Retry calling the decorated function using an exponential backoff. """Retry calling the decorated function using an exponential backoff.
@ -158,8 +159,11 @@ def blackholeStdoutForFrozenWindow():
# Relate to file hashing / difference checking: # Relate to file hashing / difference checking:
def stripfilename(filename): def stripfilename(filename, stripURL):
if filename: if filename:
if stripURL:
filename = urllib.unquote(filename)
filename = filename.split(u"/")[-1]
return re.sub(constants.FILENAME_STRIP_REGEX, "", filename) return re.sub(constants.FILENAME_STRIP_REGEX, "", filename)
else: else:
return "" return ""
@ -173,8 +177,8 @@ def stripRoomName(RoomName):
else: else:
return "" return ""
def hashFilename(filename): def hashFilename(filename, stripURL = False):
return hashlib.sha256(stripfilename(filename).encode('utf-8')).hexdigest()[:12] return hashlib.sha256(stripfilename(filename, stripURL).encode('utf-8')).hexdigest()[:12]
def hashFilesize(size): def hashFilesize(size):
return hashlib.sha256(str(size)).hexdigest()[:12] return hashlib.sha256(str(size)).hexdigest()[:12]
@ -190,9 +194,10 @@ def sameHashed(string1raw, string1hashed, string2raw, string2hashed):
return True return True
def sameFilename (filename1, filename2): def sameFilename (filename1, filename2):
stripURL = True if isURL(filename1) ^ isURL(filename2) else False
if filename1 == constants.PRIVACY_HIDDENFILENAME or filename2 == constants.PRIVACY_HIDDENFILENAME: if filename1 == constants.PRIVACY_HIDDENFILENAME or filename2 == constants.PRIVACY_HIDDENFILENAME:
return True return True
elif sameHashed(stripfilename(filename1), hashFilename(filename1), stripfilename(filename2), hashFilename(filename2)): elif sameHashed(stripfilename(filename1, stripURL), hashFilename(filename1, stripURL), stripfilename(filename2, stripURL), hashFilename(filename2, stripURL)):
return True return True
else: else:
return False return False
@ -221,9 +226,10 @@ def meetsMinVersion(version, minVersion):
def isURL(path): def isURL(path):
if path is None: if path is None:
return False return False
elif "://" in path:
if "://" in path:
return True return True
else:
return False
def getPlayerArgumentsByPathAsArray(arguments, path): def getPlayerArgumentsByPathAsArray(arguments, path):
if arguments and not isinstance(arguments, (str, unicode)) and arguments.has_key(path): if arguments and not isinstance(arguments, (str, unicode)) and arguments.has_key(path):