8 – Why does the programmed file object save the file?


I am working on a module that needs a web service and creates corresponding products. The image files of the products are already in the file system. According to this answer, I first need to create a file object to get its id to paste into my product's image box. I adopted a similar code, but I've found that I have a lot of watchdog entries trying to delete my files when I do the product creation function. What's happening?

My code:

                                                $ default = File :: create ()[
              'uri' => "public://urun/hazirlaniyor.png"
            ]);
$ query =  Drupal :: database () -> select ("mitacan_excel", "m") -> fields ("m", ["gorsel","logo","grupkodu","grupadi","grupindex"]) -> condition ("stokkodu", str_replace ("İ", "& # 304;", $ r-> StokKodu)) -> execute () -> fetchAll ();
$ imagename = & public; // urun / & # 39; . $ Query[0]-> gorsel;
$ images =  Drupal :: entityTypeManager ()
-> getStorage (& # 39; file & # 39;)
-> loadByProperties (['uri' => $imagename]);
$ image = reset ($ images);
if (! $ image) {
$ image = File :: create ()[
                    'uri' => $imagename,
                ]);
$ image-> save ();
}
$ product-> field_urun_foto[] = [
                'target_id' => (!file_exists($imagename))?$default->id():$image->id(),
                'alt' => explode(".",explode("/",$imagename)[3])[0],
& # 39; title & # 39; => explode (".", explode ("/", $ imagename)[3])[0],
];