Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode error in new atomic move #4168

Closed
LeoSebal opened this issue Nov 28, 2021 · 6 comments · Fixed by #4209
Closed

Unicode error in new atomic move #4168

LeoSebal opened this issue Nov 28, 2021 · 6 comments · Fixed by #4209
Labels
bug bugs that are confirmed and actionable

Comments

@LeoSebal
Copy link

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

  • OS: Windows 10
  • Python version: 3.9.7
  • beets version: 1.6.0
  • Turning off plugins made problem go away (yes/no): irrelevant

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 sampsyo added the needinfo We need more details or follow-up from the filer before this can be tagged "bug" or "feature." label Nov 29, 2021
@sampsyo
Copy link
Member

sampsyo commented Nov 29, 2021

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
Copy link

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 sampsyo added bug bugs that are confirmed and actionable and removed needinfo We need more details or follow-up from the filer before this can be tagged "bug" or "feature." labels Dec 3, 2021
@sampsyo sampsyo changed the title “The system cannot move the file to a different disk drive” Unicode error in new atomic move Dec 3, 2021
@sampsyo
Copy link
Member

sampsyo commented Dec 3, 2021

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?

catap added a commit to catap/beets that referenced this issue Dec 8, 2021
`os.path.basename` returns the same type that was used.

So, I have no guarantee that I needed here: `b'.''` or `'.'`.

Let use something universal ;)

Closes beetbox#4168
sampsyo added a commit that referenced this issue Dec 27, 2021
Fixes #4168. Also closes #4192, which it supersedes.

The original problem is that this implementation used bytestrings
incorrectly to invoke `mktemp`. However, `mktemp` is deprecated, so this
PR just avoids it altogether. Fortunately, the non-deprecated APIs in
`tempfile` support all-bytes arguments.
sampsyo added a commit that referenced this issue Dec 27, 2021
@krpradeep
Copy link

krpradeep commented Jun 21, 2023

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
Copy link
Contributor

catap commented Jun 21, 2023

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

Hopefully the next release will be soon, see: #4501

@krpradeep
Copy link

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

Commit link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs that are confirmed and actionable
Projects
None yet
5 participants