The Python Oracle

What exactly does a non-shallow filecmp.cmp do?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Music Box Puzzles

--

Chapters
00:00 What Exactly Does A Non-Shallow Filecmp.Cmp Do?
00:48 Accepted Answer Score 14
01:29 Thank you

--

Full question
https://stackoverflow.com/questions/3421...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #filecompare

#avk47



ACCEPTED ANSWER

Score 14


Consulting the source filecmp.py reveals that if shallow=False, filecmp.cmp first checks a few select properties of os.stat(), regardless of whether shallow is True or False. If the stat properties that are examined are the same, it returns True. Else, it checks its internal cache to see if the files have already been compared earlier. If it has, it returns True. Else, it reads BUFSIZE = 8*1024 chunks of data from both files and does an exact contents comparison until it reaches the end of the file. It returns True if the two files have exactly the same contents.