Repository: beetbox/beets

Issue:
Import error with reflink enabled and importadded plugin
<!--
Describe your problem, feature request, or discussion topic here.

Please fill out this and the "Setup" section below and remember to include
enough detail so that other people can reproduce the problem.
-->

### Problem
First of all, many thanks for adding reflink option! Very promising feature. But in some cases it causes an error. E.g. with ImportAdded plugin enabled.

Running this command in verbose (`-vv`) mode:

```sh
$ beet -vv import [absolutely any music catalogue]
```

Led to this problem:

```
[probably non-related output is redacted]

Sending event: album_imported
Traceback (most recent call last):
  File "/usr/bin/beet", line 33, in <module>
    sys.exit(load_entry_point('beets==1.6.0', 'console_scripts', 'beet')())
  File "/usr/lib/python3.10/site-packages/beets/ui/__init__.py", line 1285, in main
    _raw_main(args)
  File "/usr/lib/python3.10/site-packages/beets/ui/__init__.py", line 1272, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python3.10/site-packages/beets/ui/commands.py", line 973, in import_func
    import_files(lib, paths, query)
  File "/usr/lib/python3.10/site-packages/beets/ui/commands.py", line 943, in import_files
    session.run()
  File "/usr/lib/python3.10/site-packages/beets/importer.py", line 340, in run
    pl.run_parallel(QUEUE_SIZE)
  File "/usr/lib/python3.10/site-packages/beets/util/pipeline.py", line 446, in run_parallel
    raise exc_info[1].with_traceback(exc_info[2])
  File "/usr/lib/python3.10/site-packages/beets/util/pipeline.py", line 358, in run
    self.coro.send(msg)
  File "/usr/lib/python3.10/site-packages/beets/util/pipeline.py", line 170, in coro
    task = func(*(args + (task,)))
  File "/usr/lib/python3.10/site-packages/beets/importer.py", line 1573, in manipulate_files
    task.finalize(session)
  File "/usr/lib/python3.10/site-packages/beets/importer.py", line 612, in finalize
    self._emit_imported(session.lib)
  File "/usr/lib/python3.10/site-packages/beets/importer.py", line 638, in _emit_imported
    plugins.send('album_imported', lib=lib, album=self.album)
  File "/usr/lib/python3.10/site-packages/beets/plugins.py", line 488, in send
    result = handler(**arguments)
  File "/usr/lib/python3.10/site-packages/beets/plugins.py", line 145, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/beetsplug/importadded.py", line 105, in update_album_times
    album.added = min(album_mtimes)
ValueError: min() arg is an empty sequence

```

### Setup

* OS: ArchLinux
* Python version: 3.10.5
* beets version: 1.6.0
* Turning off plugins made problem go away (yes/no): yes, importadded plugin

<!--
You can turn off plugins temporarily by passing --plugins= on the command line:

$ beet --plugins= version
-->

My configuration (output of `beet config`) is:

```yaml
directory: /storage/music/show-reflink-bug
library: ~/.datasets/metadata/beets/show-reflink-bug.db.db

plugins: [importadded]

import:
    reflink: yes
    write: yes
importadded:
    preserve_mtimes: no
    preserve_write_mtimes: no
```



Discussion:

Resolving patch:
diff --git a/beetsplug/importadded.py b/beetsplug/importadded.py
--- a/beetsplug/importadded.py
+++ b/beetsplug/importadded.py
@@ -34,6 +34,7 @@ def __init__(self):
         register('item_copied', self.record_import_mtime)
         register('item_linked', self.record_import_mtime)
         register('item_hardlinked', self.record_import_mtime)
+        register('item_reflinked', self.record_import_mtime)
         register('album_imported', self.update_album_times)
         register('item_imported', self.update_item_times)
         register('after_write', self.update_after_write_time)
@@ -49,7 +50,8 @@ def reimported_album(self, album):
 
     def record_if_inplace(self, task, session):
         if not (session.config['copy'] or session.config['move'] or
-                session.config['link'] or session.config['hardlink']):
+                session.config['link'] or session.config['hardlink'] or
+                session.config['reflink']):
             self._log.debug("In place import detected, recording mtimes from "
                             "source paths")
             items = [task.item] \


Test patch: