beetbox / beets

music library manager and MusicBrainz tagger
http://beets.io/
MIT License
12.84k stars 1.82k forks source link

Unicode error in new atomic move #4168

Closed LeoSebal closed 2 years ago

LeoSebal commented 2 years ago

Problem

I’ve stumbled upon a bug when importing any file, seemingly related to the use of the os.replace function and the import: move option. using the copy option instead fixes the bug. According to adrian, it would be related to Introduce atomic move and write of file

Traceback (most recent call last):
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\util\__init__.py", line 496, in move
    os.replace(path, dest)
OSError: [WinError 17] The system cannot move the file to a different disk drive: '\\\\?\\C:\\Users\\hydro\\AppData\\Local\\Temp\\tmp02lvwxx1.flac' -> '\\\\?\\M:\\Musique lossless\\Ancient Methods\\2021 - The Jericho Remixes\\01 Swordplay (Hypnoskull vocal remix).flac'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\hydro\anaconda3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\hydro\anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\hydro\anaconda3\Scripts\beet.exe\__main__.py", line 7, in <module>
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\ui\__init__.py", line 1285, in main
    _raw_main(args)
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\ui\__init__.py", line 1272, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\ui\commands.py", line 973, in import_func
    import_files(lib, paths, query)
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\ui\commands.py", line 943, in import_files
    session.run()
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\importer.py", line 340, in run
    pl.run_parallel(QUEUE_SIZE)
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\util\pipeline.py", line 446, in run_parallel
    raise exc_info[1].with_traceback(exc_info[2])
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\util\pipeline.py", line 358, in run
    self.coro.send(msg)
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\util\pipeline.py", line 170, in coro
    task = func(*(args + (task,)))
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\importer.py", line 1566, in manipulate_files
    task.manipulate_files(
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\importer.py", line 757, in manipulate_files
    item.move(operation)
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\library.py", line 922, in move
    self.move_file(dest, operation)
  File "C:\Users\hydro\anaconda3\lib\site-packages\beets\library.py", line 821, in move_file

Setup

The relevant bit of my configuration (output of beet config) is:

# Import options
import:
  write: yes
  # copy: yes
  move: yes
  resume: no
  autotag: yes
sampsyo commented 2 years ago

Thank you for filing! Is there any chance that traceback got cut off at the end? It doesn't seem to end in the line that's the origin of the second exception.

aibradford commented 2 years ago

Same issue here:

The error im getting is always the same except for the name of the file that causes the error:

Traceback (most recent call last):

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\util\__init__.py", line 496, in move

os.replace(path, dest)

OSError: [WinError 17] The system cannot move the file to a different disk drive: '\\\\?\\C:\\Users\\Nuc8\\AppData\\Local\\Temp\\tmp_fkqq4ch.jpg' -> '\\\\?\\D:\\_Sorted\\#artists\\Animal Collective\\2007 - Strawberry Jam [Domino WIGCD199] [24 96kHz FLAC]\\cover.jpg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\Nuc8\AppData\Local\Programs\Python\Python37\Scripts\beet-script.py", line 11, in <module>

load_entry_point('beets==1.6.0', 'console_scripts', 'beet')()

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\ui\__init__.py", line 1285, in main

_raw_main(args)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\ui\__init__.py", line 1272, in _raw_main

subcommand.func(lib, suboptions, subargs)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\ui\commands.py", line 973, in import_func

import_files(lib, paths, query)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\ui\commands.py", line 943, in import_files

session.run()

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\importer.py", line 340, in run

pl.run_parallel(QUEUE_SIZE)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\util\pipeline.py", line 446, in run_parallel

raise exc_info[1].with_traceback(exc_info[2])

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\util\pipeline.py", line 358, in run

self.coro.send(msg)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\util\pipeline.py", line 170, in coro

task = func(*(args + (task,)))

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\importer.py", line 1569, in manipulate_files

session=session,

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\importer.py", line 766, in manipulate_files

plugins.send('import_task_files', session=session, task=self)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\plugins.py", line 488, in send

result = handler(**arguments)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\plugins.py", line 145, in wrapper

return func(*args, **kwargs)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beetsplug\fetchart.py", line 1063, in assign_art

self._set_art(task.album, candidate, not self.src_removed)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beetsplug\fetchart.py", line 1048, in _set_art

album.set_art(candidate.path, delete)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\library.py", line 1317, in set_art

util.move(path, artdest)

File "c:\users\nuc8\appdata\local\programs\python\python37\lib\site-packages\beets\util\__init__.py", line 499, in move

prefix=py3_path(b'.' + os.path.basename(dest)),

TypeError: can't concat str to bytes"

Here is my congif.yaml:

https://pastebin.com/9M03TXdU

I don't have enough knowledge of python to be able to figure this out on my own, any help is truly appreciated.

thanks in advance to anyone who can help.

sampsyo commented 2 years ago

Thanks for the complete traceback; this definitely looks like a bug!

@catap, this bug was introduced in your PR #4060. The concatenation here assumes incorrectly that os.path.basename will produce a bytes object: https://github.com/beetbox/beets/pull/4060/files#diff-8c8be7ee9289c87f5f470e1b6edda131dbfa07272a9afaaa92ba42e7d766702eR499

Can you please take a look?

krpradeep commented 1 year ago

Hi, Sorry to comment on this old thread but I am getthing same error while trying to run beet fetchart command. my version of beet is

beets version 1.6.0 Python version 3.9.2 plugins: fetchart

Below stacktrace is after i tried windows mklink thinking it might bypass it, but still giving same error. "The system cannot move the file to a different disk drive"

Traceback (most recent call last):
  File "d:\music\beets\beets_virtualenv\lib\site-packages\beets\util\__init__.py", line 496, in move
    os.replace(path, dest)
OSError: [WinError 17] The system cannot move the file to a different disk drive: '\\\\?\\C:\\Users\\MainUser\\AppData\\Local\\Temp\\tmpsjgvem6d.jpg' -> '\\\\?\\C:\\Users\\MainUser\\AppData\\Roaming\\beets\\MusicLink\\1920 (2008)\\folder.jpg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Music\beets\beets_virtualenv\Scripts\beet-script.py", line 33, in <module>
    sys.exit(load_entry_point('beets==1.6.0', 'console_scripts', 'beet')())
  File "d:\music\beets\beets_virtualenv\lib\site-packages\beets\ui\__init__.py", line 1285, in main
    _raw_main(args)
  File "d:\music\beets\beets_virtualenv\lib\site-packages\beets\ui\__init__.py", line 1272, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "d:\music\beets\beets_virtualenv\lib\site-packages\beetsplug\fetchart.py", line 1083, in func
    self.batch_fetch_art(lib, lib.albums(ui.decargs(args)), opts.force,
  File "d:\music\beets\beets_virtualenv\lib\site-packages\beetsplug\fetchart.py", line 1145, in batch_fetch_art
    self._set_art(album, candidate)
  File "d:\music\beets\beets_virtualenv\lib\site-packages\beetsplug\fetchart.py", line 1048, in _set_art
    album.set_art(candidate.path, delete)
  File "d:\music\beets\beets_virtualenv\lib\site-packages\beets\library.py", line 1317, in set_art
    util.move(path, artdest)
  File "d:\music\beets\beets_virtualenv\lib\site-packages\beets\util\__init__.py", line 499, in move
    prefix=py3_path(b'.' + os.path.basename(dest)),
TypeError: can't concat str to bytes
catap commented 1 year ago

@krpradeep unfortunately but the fix isn’t released at any version yet.

Hopefully the next release will be soon, see: https://github.com/beetbox/beets/discussions/4501

krpradeep commented 1 year ago

@catap Thanks for reply. I able to work it out by manually merging change into local

Commit link