def has_same_content_as(self, other):
logger.debug('File.has_same_content: %s %s', self, other)
if os.path.isdir(self.path) or os.path.isdir(other.path):
return False
# try comparing small files directly first
try:
my_size = os.path.getsize(self.path)
other_size = os.path.getsize(other.path)
except OSError:
# files not readable (e.g. broken symlinks) or something else,
# just assume they are different
return False
if my_size == other_size and my_size <= SMALL_FILE_THRESHOLD:
try:
with profile('command', 'cmp (internal)'):
with open(self.path, 'rb') as file1, open(other.path, 'rb') as file2:
return file1.read() == file2.read()
except OSError:
# one or both files could not be opened for some reason,
# assume they are different
return False
return self.cmp_external(other)
评论列表
文章目录