def __commit(self):
        """Commit the transaction while handling tile files."""

        # Move tile files to their final location just before
        # the commit, to avoid commiting tile records without files.
        # Tile files without records are possible if the commit fails
        # at the last moment.

        for tile_contents in self.tile_create_list:
            tile_contents.make_permanent()

        self.db.commit()

        # Remove tile files just after the commit, to avoid removing
        # tile files when the deletion of a tile record has been rolled
        # back. Again, tile files without records are possible if there
        # is an exception or crash just after the commit.
        #
        # The tile remove list is filtered against the tile create list
        # to avoid removing a file that has just been re-created. It is
        # a bad idea to overwrite a tile file in this way (in a single
        # transaction), because it will be overwritten just before the
        # commit (above) and the wrong file will be in place if the
        # transaction is rolled back.

        tile_create_set = {t.get_output_path()
                           for t in self.tile_create_list}
        for tile_pathname in self.tile_remove_list:
            if tile_pathname not in tile_create_set:
                if os.path.isfile(tile_pathname):
                    os.remove(tile_pathname)
dataset/ETHPy150Open GeoscienceAustralia/agdc/src/abstract_ingester/collection.py/Transaction.__commit/original