Problems importing one specific album

I’m ripping and importing a bunch of CDs and one CD just refuses to import.

I’m on Fedora Linux 38. The album is Spritis of the Western Sky by Justin Hayward.

I ripped the CD to /home/andy/rips/Justin Hayward/Spirits Of The Western Sky

My music library is on a Synology NAS and shared out vis SMB.

The line in my fstab to mount my music is:

//172.25.100.3/music-library /mnt/music-library cifs username=fedora-server,password=strong_password,uid=1000,gid=1000,iocharset=utf8 0 0

When I run the command beet import ~/rips/Justin\ Hayward and let it import the album, I get the following errors

Traceback (most recent call last):
  File "/home/andy/.local/lib/python3.11/site-packages/beets/util/__init__.py", line 496, in move
    os.replace(path, dest)
OSError: [Errno 18] Invalid cross-device link: b'/home/andy/rips/Justin Hayward/Spirits Of The Western Sky/02 One Day, Someday.flac' -> b'/mnt/music-library/FLAC/Justin Hayward/Spirits of the Western Sky/02 One Day, Someday.flac'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/andy/.local/lib/python3.11/site-packages/beets/util/__init__.py", line 504, in move
    os.replace(tmp, dest)
OSError: [Errno 16] Device or resource busy: '/mnt/music-library/FLAC/Justin Hayward/Spirits of the Western Sky/.02 One Day, Someday.flac_bitjsr0.beets' -> b'/mnt/music-library/FLAC/Justin Hayward/Spirits of the Western Sky/02 One Day, Someday.flac'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/andy/.local/lib/python3.11/site-packages/beets/util/__init__.py", line 508, in move
    raise FilesystemError(exc, 'move', (path, dest),
beets.util.FilesystemError: Device or resource busy while moving /home/andy/rips/Justin Hayward/Spirits Of The Western Sky/02 One Day, Someday.flac to /mnt/music-library/FLAC/Justin Hayward/Spirits of the Western Sky/02 One Day, Someday.flac

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/andy/.local/bin/beet", line 33, in <module>
    sys.exit(load_entry_point('beets==1.6.0', 'console_scripts', 'beet')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andy/.local/lib/python3.11/site-packages/beets/ui/__init__.py", line 1285, in main
    _raw_main(args)
  File "/home/andy/.local/lib/python3.11/site-packages/beets/ui/__init__.py", line 1272, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/home/andy/.local/lib/python3.11/site-packages/beets/ui/commands.py", line 973, in import_func
    import_files(lib, paths, query)
  File "/home/andy/.local/lib/python3.11/site-packages/beets/ui/commands.py", line 943, in import_files
    session.run()
  File "/home/andy/.local/lib/python3.11/site-packages/beets/importer.py", line 340, in run
    pl.run_parallel(QUEUE_SIZE)
  File "/home/andy/.local/lib/python3.11/site-packages/beets/util/pipeline.py", line 446, in run_parallel
    raise exc_info[1].with_traceback(exc_info[2])
  File "/home/andy/.local/lib/python3.11/site-packages/beets/util/pipeline.py", line 358, in run
    self.coro.send(msg)
  File "/home/andy/.local/lib/python3.11/site-packages/beets/util/pipeline.py", line 170, in coro
    task = func(*(args + (task,)))
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andy/.local/lib/python3.11/site-packages/beets/importer.py", line 1566, in manipulate_files
    task.manipulate_files(
  File "/home/andy/.local/lib/python3.11/site-packages/beets/importer.py", line 757, in manipulate_files
    item.move(operation)
  File "/home/andy/.local/lib/python3.11/site-packages/beets/library.py", line 922, in move
    self.move_file(dest, operation)
  File "/home/andy/.local/lib/python3.11/site-packages/beets/library.py", line 821, in move_file
    util.move(self.path, dest)
  File "/home/andy/.local/lib/python3.11/site-packages/beets/util/__init__.py", line 512, in move
    os.remove(tmp)
OSError: [Errno 16] Device or resource busy: '/mnt/music-library/FLAC/Justin Hayward/Spirits of the Western Sky/.02 One Day, Someday.flac_bitjsr0.beets'

I’ve imported 3 other albums today without issue.

Ok, I just tried to import another album, and it’s doing the same thing.

Could you please post the output of beet config?

plugins: fetchart lyrics lastgenre embedart replaygain info acousticbrainz chroma inline

directory: /mnt/music-library
library: ~/.config/beets/musiclibrary.db

import:
  move: yes
  quiet: no
  timid: yes
paths:
  default: $format/$albumartist/$album %if{%aunique{},($year - $label)}/%if{$multidisc,$disc-}$track $title
  comp: $format/$albumartist/$album %if{%aunique{},($year - $label)}/%if{$multidisc,$disc-}$track $title
  singleton: $format/$albumartist/$album %if{%aunique{},($year - $label)}/%if{$multidisc,$disc-}$track $title

item_fields:
  multidisc: 1 if disctotal > 1 else 0

fetchart:
  auto: yes
  sources:
    - filesystem
    - coverart
    - itunes
    - amazon
    - albumart
  high_resolution: yes
  cover_format: jpg

lyrics:
  auto: yes

replaygain:
  auto: yes
  backend: gstreamer

lastgenre:
  auto: yes

embedart:
  auto: yes

acousticbrainz:
  auto: yes

chroma:
  auto: yes

This is definitely file system related. If I copy the files to /mnt/music-library and import from there, they import without issue.

I need to clarify the config a little.

/home/andy/rips is also a mount point for an SMB share off my NAS.

My workflow is:

  1. Rip CDs on my Mac to my NAS
  2. Import them them into beets on my Linux server from one NAS SMB mount point to another NAS SMB mount point.
  3. Done

Last night, I imported 2 albums without issue. And the third one failed with that error. Now they’re all failing. I’m going to set move to no and see what happens.

Something else different about these albums is I am trying to overwrite a previous import. I don’t know if that makes any difference. I’ll need to experiment some more.

The Invalid cross-device link error is to be expected when moving across filesystems as beets initially tries to do an os.replace, but that is not supported across filesystems.

The weird bit is the Device or resource busy error. If beets detects it can’t use os.replace, it instead copies the file to the destination under a temporary name (.02 One Day, Someday.flac_bitjsr0.beets in the above snippet) and renames it to the final name with os.replace. It then deletes the source file from the original filesystem.

I wonder if the temporary file created hasn’t finished being written by the time os.replace is called (due to it being over the network), causing the Device or resource busy error. You could try adding a short time.sleep call in between closing the file and moving it to prove this: https://github.com/beetbox/beets/blob/a4e61e8bc7983df412f9bccec930c7b0818a4a08/beets/util/__init__.py#L522

I’m not sure if there’s a way to “wait” for the write to finish - close already supposedly flushes the file to disk.

We’ve had a few issues raised in the past with network shares, it’s certainly worth trying to use copy instead.

1 Like

Would setting move to no help the issue at all?

Disabling move and enabling copy is certainly worth a shot, as that doesn’t have to do the temporary file dance when copying across filesystems - it should just copy directly to the destination.