Holzhaus / beets-extrafiles

A plugin for beets that copies additional files and directories during the import process.
MIT License
46 stars 10 forks source link

Using '*.*' glob pattern breaks import #3

Closed hamfactorial closed 5 years ago

hamfactorial commented 5 years ago

Importing an album using the following configuration breaks the plugin:

extrafiles:
    patterns:
        all: '*.*'
    paths:
        all: $albumpath/$filename

Here is the resulting output using -vvv verbosity:

user configuration: /config/config.yaml
data directory: /config
plugin paths: 
Sending event: pluginload
library database: /config/musiclibrary.blb
library directory: /music
Sending event: library_opened
Sending event: import_begin
Sending event: import_task_created
Sending event: import_task_start
Looking up: /tmp/Feels
Tagging Animal Collective - Feels
Searching for discovered album ID: 1ddb09aa-e6e7-3c50-9204-406bd0fadf4d
Requesting MusicBrainz release 1ddb09aa-e6e7-3c50-9204-406bd0fadf4d
primary MB release type: album
Sending event: albuminfo_received
Candidate: Animal Collective - Feels (1ddb09aa-e6e7-3c50-9204-406bd0fadf4d)
Computing track assignment...
...done.
Success. Distance: 0.00
Album ID match recommendation is Recommendation.strong
ID match.

/tmp/Feels (9 items)
Sending event: before_choose_candidate
Tagging:
    Animal Collective - Feels
URL:
    https://musicbrainz.org/release/1ddb09aa-e6e7-3c50-9204-406bd0fadf4d
(Similarity: 100.0%) (CD, 2006, RU, FatCat Records)
Sending event: import_task_choice
Sending event: import_task_apply
0 of 9 items replaced
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Sending event: after_write
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Sending event: after_write
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Sending event: after_write
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Sending event: after_write
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Sending event: after_write
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Sending event: after_write
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Sending event: after_write
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Sending event: after_write
Sending event: before_item_moved
Sending event: item_moved
Sending event: database_change
Sending event: database_change
Sending event: write
Sending event: after_write
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: database_change
Sending event: import_task_files
scrub: auto-scrubbing /music/Animal Collective/Feels/01 - Did You See the Words.flac
scrub: writing new tags after scrub
Sending event: write
Sending event: after_write
scrub: restoring art
scrub: auto-scrubbing /music/Animal Collective/Feels/02 - Grass.flac
scrub: writing new tags after scrub
Sending event: write
Sending event: after_write
scrub: restoring art
scrub: auto-scrubbing /music/Animal Collective/Feels/03 - Flesh Canoe.flac
scrub: writing new tags after scrub
Sending event: write
Sending event: after_write
scrub: restoring art
scrub: auto-scrubbing /music/Animal Collective/Feels/04 - The Purple Bottle.flac
scrub: writing new tags after scrub
Sending event: write
Sending event: after_write
scrub: restoring art
scrub: auto-scrubbing /music/Animal Collective/Feels/05 - Bees.flac
scrub: writing new tags after scrub
Sending event: write
Sending event: after_write
scrub: restoring art
scrub: auto-scrubbing /music/Animal Collective/Feels/06 - Banshee Beat.flac
scrub: writing new tags after scrub
Sending event: write
Sending event: after_write
scrub: restoring art
scrub: auto-scrubbing /music/Animal Collective/Feels/07 - Daffy Duck.flac
scrub: writing new tags after scrub
Sending event: write
Sending event: after_write
scrub: restoring art
scrub: auto-scrubbing /music/Animal Collective/Feels/08 - Loch Raven.flac
scrub: writing new tags after scrub
Sending event: write
Sending event: after_write
scrub: restoring art
scrub: auto-scrubbing /music/Animal Collective/Feels/09 - Turn Into Something.flac
scrub: writing new tags after scrub
Sending event: write
Sending event: after_write
scrub: restoring art
Sending event: album_imported
Sending event: import
Sending event: cli_exit
extrafiles: Moving extra file: /tmp/Feels/Animal Collective - Feels.log -> /music/Animal Collective/Feels/Animal Collective - Feels.log
extrafiles: Moving extra file: /tmp/Feels/cover.jpg -> /music/Animal Collective/Feels/cover.jpg
extrafiles: Moving extra file: /tmp/Feels/. -> /music/Animal Collective/Feels/_
Traceback (most recent call last):
  File "/usr/lib/python3.6/shutil.py", line 544, in move
    os.rename(src, real_dst)
OSError: [Errno 18] Cross-device link: b'/tmp/Feels/.' -> b'/music/Animal Collective/Feels/_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/beet", line 11, in <module>
    load_entry_point('beets==1.4.7', 'console_scripts', 'beet')()
  File "/usr/lib/python3.6/site-packages/beets/ui/__init__.py", line 1256, in main
    _raw_main(args)
  File "/usr/lib/python3.6/site-packages/beets/ui/__init__.py", line 1245, in _raw_main
    plugins.send('cli_exit', lib=lib)
  File "/usr/lib/python3.6/site-packages/beets/plugins.py", line 476, in send
    result = handler(**arguments)
  File "/usr/lib/python3.6/site-packages/beets/plugins.py", line 140, in wrapper
    return func(*args, **kwargs)
  File "/music/.local/lib/python3.6/site-packages/beets_extrafiles-0.0.2-py3.6.egg/beetsplug/extrafiles.py", line 98, in on_cli_exit
  File "/music/.local/lib/python3.6/site-packages/beets_extrafiles-0.0.2-py3.6.egg/beetsplug/extrafiles.py", line 147, in process_items
  File "/music/.local/lib/python3.6/site-packages/beets_extrafiles-0.0.2-py3.6.egg/beetsplug/extrafiles.py", line 123, in _move_file
  File "/usr/lib/python3.6/shutil.py", line 551, in move
    if _destinsrc(src, dst):
  File "/usr/lib/python3.6/shutil.py", line 565, in _destinsrc
    if not src.endswith(os.path.sep):
TypeError: endswith first arg must be bytes or a tuple of bytes, not str

The relevant command seems to be this one:

extrafiles: Moving extra file: /tmp/Feels/. -> /music/Animal Collective/Feels/_

It seems that the iglob() function is returning a "." which should probably be ignored.

Holzhaus commented 5 years ago

This shouldn't happen because glob.iglob (which is used internally) treats files beginning with a dot as special cases. However, I added a fix in 12ec5c7f9ce3391d533d3d9100c87f6a05d9a57d, which should prevent this behaviour in any case.

Also, I noticed that you were using an old version, because I forgot to bump the version in setup.py so that the new version was not pushed to PyPI. This is also fixed now.