Incremental number handling on duplicate file names

After a couple of hours searching the WP core I’ve lost hope finding this myself (for once).

Could someone guide me perhaps to where WordPress handles the incremental number when having duplicate file names during uploading?

As a side question. When handling questions like this, where and how would you start searching? AFAIK I’ve searched through every file containing file and upload.

Solutions Collecting From Web of "Incremental number handling on duplicate file names"

The number is added in wp_unique_filename() in wp-includes/functions.php. You can prevent it by hooking into 'sanitize_file_name' and setting another file name.

You can find such functions and filters by following the code with your IDE. Most IDEs make functions clickable so you can go from their call to their declaration.

Here is an example from Eclipse PDT:

enter image description here