Handle potential OSError when unlinking temporary files in ArtResizer (#5615)

## Description

was getting permission error because after png is converted to jpg beets
want to delete the png but somehow it is still being used causing the
import to fail. this temporarily fixes the import but still needs a
proper way to know what is using the file and how to delete it.

```
  File "C:\Users\DELL\projects\_myForks\beets\beetsplug\fetchart.py", line 1321, in fetch_art
    candidate = self.art_for_album(task.album, task.paths, local)
  File "C:\Users\DELL\projects\_myForks\beets\beetsplug\fetchart.py", line 1413, in art_for_album
    out.resize(self)
    ~~~~~~~~~~^^^^^^
  File "C:\Users\DELL\projects\_myForks\beets\beetsplug\fetchart.py", line 218, in resize
    self._resize(plugin, current_check)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DELL\projects\_myForks\beets\beetsplug\fetchart.py", line 246, in _resize
    self.path = ArtResizer.shared.reformat(
                ~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self.path,
        ^^^^^^^^^^
        plugin.cover_format,
        ^^^^^^^^^^^^^^^^^^^^
        deinterlaced=plugin.deinterlace,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\DELL\projects\_myForks\beets\beets\util\artresizer.py", line 658, in reformat
    os.unlink(path_in)
    ~~~~~~~~~^^^^^^^^^
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: b'C:\\Users\\DELL\\AppData\\Local\\Temp\\beets\\beetsplug_fetchart\\4kqx2um2.png'
```
when importing
https://musicbrainz.org/release/5744ddb7-e9b6-4b46-a55c-38e75aa95460

beet config

```yaml
fetchart:
    minwidth: 500
    maxwidth: 3000
    max_filesize: 3500000
    sources:
    -   coverart: release
    -   coverart: releasegroup
    - itunes
    - amazon
    - filesystem
    - albumart
    - '*'
    cautious: yes
    cover_names: cover front art artwork folder album
    store_source: yes
    cover_format: JPEG
    auto: yes
    quality: 0
    enforce_ratio: no
    high_resolution: no
    deinterlace: no
```
This commit is contained in:
Šarūnas Nejus 2026-01-17 14:35:44 +00:00 committed by GitHub
commit ef59cfa522
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View file

@ -24,6 +24,7 @@ import platform
import re
import subprocess
from abc import ABC, abstractmethod
from contextlib import suppress
from enum import Enum
from itertools import chain
from typing import TYPE_CHECKING, Any, ClassVar
@ -846,7 +847,8 @@ class ArtResizer:
)
finally:
if result_path != path_in:
os.unlink(path_in)
with suppress(OSError):
os.unlink(path_in)
return result_path
@property

View file

@ -48,6 +48,8 @@ New features:
Bug fixes:
- Handle potential OSError when unlinking temporary files in ArtResizer.
:bug:`5615`
- :doc:`/plugins/spotify`: Updated Spotify API credentials. :bug:`6270`
- :doc:`/plugins/smartplaylist`: Fixed an issue where multiple queries in a
playlist configuration were not preserving their order, causing items to