From 0b5d33ba3b0664f298b175cb0a2efd99ed54c942 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Mon, 28 Feb 2022 20:11:36 +0100 Subject: extras: Decode paths before handing them to shutil.move Even though the python 3.9 documentation for shutil.move [1] states that "[..] a path-like object for both src and dst" is accepted, it does not in fact support bytes as arguments. This is because shutil.move calls _dstinsrc [2] which tries to compare bytes with str via str.endswith. Python seems to be aware of this [3], but has not yet fixed any of these problems. For now just decode both bytes objects so shutil.move works. [1] https://docs.python.org/3.9/library/shutil.html?highlight=shutil%20move#shutil.move [2] https://github.com/python/cpython/blob/a58ebcc701dd6c43630df941481475ff0f615a81/Lib/shutil.py#L829-L836 [3] https://bugs.python.org/issue46727 --- beetsplug/extras.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'beetsplug/extras.py') diff --git a/beetsplug/extras.py b/beetsplug/extras.py index e731b6e..8227064 100644 --- a/beetsplug/extras.py +++ b/beetsplug/extras.py @@ -11,7 +11,9 @@ class ExtrasPlugin(beets.plugins.BeetsPlugin): def on_item_moved(self, item, source, destination): for (sourcepath, destpath) in self.gather(source, destination): - shutil.move(sourcepath, destpath) + # need to decode to str here as shutil.move (still) breaks on bytes + # arguments because of _destinsrc using str.endswith + shutil.move(sourcepath.decode(), destpath.decode()) def on_item_copied(self, item, source, destination): for (sourcepath, destpath) in self.gather(source, destination): -- cgit v1.2.3-2-gb3c3