We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
importadded: ValueError on trying to import a large library
After migrating my music to a new drive, I'm trying to update the beets library. I've first run `beet update` so beets flushes out the old files, and I'm now running `beet import -AC .` to import the new files. Along the way, I've seen this error show up a couple times, though it is inconsistent in when it shows:

```
Traceback (most recent call last):
  File "/usr/local/bin/beet", line 9, in <module>
    load_entry_point('beets==1.3.17', 'console_scripts', 'beet')()
  File "/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py", line 1236, in main
    _raw_main(args)
  File "/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py", line 1226, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/local/lib/python2.7/dist-packages/beets/ui/commands.py", line 966, in import_func
    import_files(lib, paths, query)
  File "/usr/local/lib/python2.7/dist-packages/beets/ui/commands.py", line 943, in import_files
    session.run()
  File "/usr/local/lib/python2.7/dist-packages/beets/importer.py", line 321, in run
    pl.run_parallel(QUEUE_SIZE)
  File "/usr/local/lib/python2.7/dist-packages/beets/util/pipeline.py", line 348, in run
    self.coro.send(msg)
  File "/usr/local/lib/python2.7/dist-packages/beets/util/pipeline.py", line 161, in coro
    task = func(*(args + (task,)))
  File "/usr/local/lib/python2.7/dist-packages/beets/importer.py", line 1401, in manipulate_files
    task.finalize(session)
  File "/usr/local/lib/python2.7/dist-packages/beets/importer.py", line 544, in finalize
    self._emit_imported(session.lib)
  File "/usr/local/lib/python2.7/dist-packages/beets/importer.py", line 570, in _emit_imported
    plugins.send('album_imported', lib=lib, album=self.album)
  File "/usr/local/lib/python2.7/dist-packages/beets/plugins.py", line 459, in send
    result = handler(**arguments)
  File "/usr/local/lib/python2.7/dist-packages/beets/plugins.py", line 124, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/beetsplug/importadded.py", line 106, in update_album_times
    album.added = min(album_mtimes)
ValueError: min() arg is an empty sequence
```

I'm currently running beets 1.3.17, and my configuration is listed below:

```
importfeeds:
    dir: /media/Backup/Music
    relative_to:
    formats: m3u m3u_multi
    absolute_path: no
    m3u_name: imported.m3u
web:
    host: 0.0.0.0
    cors: '*'
convert:
    max_bitrate: 192
    command: ffmpeg -i $source -map_metadata 0 $dest
    extension: mp3
    never_convert_lossy_files: no
    format: mp3
    dest:
    auto: no
    threads: 4
    copy_album_art: no
    tmpdir:

    paths: {}
    pretend: no
    quiet: no
    formats:
        alac:
            command: ffmpeg -i $source -y -vn -acodec alac $dest
            extension: m4a
        aac:
            command: ffmpeg -i $source -y -vn -acodec libfaac -aq 100 $dest
            extension: m4a
        opus: ffmpeg -i $source -y -vn -acodec libopus -ab 96k $dest
        mp3: ffmpeg -i $source -y -vn -aq 2 $dest
        flac: ffmpeg -i $source -y -vn -acodec flac $dest
        ogg: ffmpeg -i $source -y -vn -acodec libvorbis -aq 2 $dest
        wma: ffmpeg -i $source -y -vn -acodec wmav2 -vn $dest
    embed: yes
per_disc_numbering: yes
fetchart:
    auto: no
    minwidth: 0
    sources:
    - coverart
    - itunes
    - amazon
    - albumart
    cautious: no
    google_engine: 001442825323518660753:hrh5ch1gjzm
    maxwidth: 0
    google_key: REDACTED
    cover_names:
    - cover
    - front
    - art
    - album
    - folder
    remote_priority: no
    enforce_ratio: no
embedart:
    auto: no
    compare_threshold: 0
    ifempty: no
    remove_art_file: no
    maxwidth: 0
replaygain:
    backend: gstreamer
    targetlevel: 89
    auto: yes
    overwrite: no
library: ~/.config/beets/library.db

plugins: duplicates importfeeds importadded replaygain embedart fetchart convert edit
directory: /media/Backup/Music
edit:
    itemfields: track title artist album
    albumfields: album albumartist
    ignore_fields: id path
importadded:
    preserve_mtimes: no
duplicates:
    count: no
    full: no
    format: ''
    keys: []
    move: ''
    tag: ''
    path: no
    copy: ''
    tiebreak: {}
    album: no
    strict: no
    checksum: ''
    merge: no
    delete: no
```

I've since disabled the `importadded` plugin so I can just import all my files, but is there a way to fix this in the future? This is running off of an NTFS filesystem, so I don't know if a `stat` command or similar isn't coming back correctly, but I haven't had issues with this in the past.

Let me know if there's any way I can assist.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `beetsplug/importadded.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 """Populate an item's `added` and `mtime` fields by using the file
4 modification time (mtime) of the item's source file before import.
5 
6 Reimported albums and items are skipped.
7 """
8 from __future__ import division, absolute_import, print_function
9 
10 import os
11 
12 from beets import util
13 from beets import importer
14 from beets.plugins import BeetsPlugin
15 
16 
17 class ImportAddedPlugin(BeetsPlugin):
18     def __init__(self):
19         super(ImportAddedPlugin, self).__init__()
20         self.config.add({
21             'preserve_mtimes': False,
22             'preserve_write_mtimes': False,
23         })
24 
25         # item.id for new items that were reimported
26         self.reimported_item_ids = None
27         # album.path for old albums that were replaced by a reimported album
28         self.replaced_album_paths = None
29         # item path in the library to the mtime of the source file
30         self.item_mtime = dict()
31 
32         register = self.register_listener
33         register('import_task_start', self.check_config)
34         register('import_task_start', self.record_if_inplace)
35         register('import_task_files', self.record_reimported)
36         register('before_item_moved', self.record_import_mtime)
37         register('item_copied', self.record_import_mtime)
38         register('item_linked', self.record_import_mtime)
39         register('item_hardlinked', self.record_import_mtime)
40         register('album_imported', self.update_album_times)
41         register('item_imported', self.update_item_times)
42         register('after_write', self.update_after_write_time)
43 
44     def check_config(self, task, session):
45         self.config['preserve_mtimes'].get(bool)
46 
47     def reimported_item(self, item):
48         return item.id in self.reimported_item_ids
49 
50     def reimported_album(self, album):
51         return album.path in self.replaced_album_paths
52 
53     def record_if_inplace(self, task, session):
54         if not (session.config['copy'] or session.config['move'] or
55                 session.config['link'] or session.config['hardlink']):
56             self._log.debug(u"In place import detected, recording mtimes from "
57                             u"source paths")
58             items = [task.item] \
59                 if isinstance(task, importer.SingletonImportTask) \
60                 else task.items
61             for item in items:
62                 self.record_import_mtime(item, item.path, item.path)
63 
64     def record_reimported(self, task, session):
65         self.reimported_item_ids = set(item.id for item, replaced_items
66                                        in task.replaced_items.items()
67                                        if replaced_items)
68         self.replaced_album_paths = set(task.replaced_albums.keys())
69 
70     def write_file_mtime(self, path, mtime):
71         """Write the given mtime to the destination path.
72         """
73         stat = os.stat(util.syspath(path))
74         os.utime(util.syspath(path), (stat.st_atime, mtime))
75 
76     def write_item_mtime(self, item, mtime):
77         """Write the given mtime to an item's `mtime` field and to the mtime
78         of the item's file.
79         """
80         # The file's mtime on disk must be in sync with the item's mtime
81         self.write_file_mtime(util.syspath(item.path), mtime)
82         item.mtime = mtime
83 
84     def record_import_mtime(self, item, source, destination):
85         """Record the file mtime of an item's path before its import.
86         """
87         mtime = os.stat(util.syspath(source)).st_mtime
88         self.item_mtime[destination] = mtime
89         self._log.debug(u"Recorded mtime {0} for item '{1}' imported from "
90                         u"'{2}'", mtime, util.displayable_path(destination),
91                         util.displayable_path(source))
92 
93     def update_album_times(self, lib, album):
94         if self.reimported_album(album):
95             self._log.debug(u"Album '{0}' is reimported, skipping import of "
96                             u"added dates for the album and its items.",
97                             util.displayable_path(album.path))
98             return
99 
100         album_mtimes = []
101         for item in album.items():
102             mtime = self.item_mtime.pop(item.path, None)
103             if mtime:
104                 album_mtimes.append(mtime)
105                 if self.config['preserve_mtimes'].get(bool):
106                     self.write_item_mtime(item, mtime)
107                     item.store()
108         album.added = min(album_mtimes)
109         self._log.debug(u"Import of album '{0}', selected album.added={1} "
110                         u"from item file mtimes.", album.album, album.added)
111         album.store()
112 
113     def update_item_times(self, lib, item):
114         if self.reimported_item(item):
115             self._log.debug(u"Item '{0}' is reimported, skipping import of "
116                             u"added date.", util.displayable_path(item.path))
117             return
118         mtime = self.item_mtime.pop(item.path, None)
119         if mtime:
120             item.added = mtime
121             if self.config['preserve_mtimes'].get(bool):
122                 self.write_item_mtime(item, mtime)
123             self._log.debug(u"Import of item '{0}', selected item.added={1}",
124                             util.displayable_path(item.path), item.added)
125             item.store()
126 
127     def update_after_write_time(self, item):
128         """Update the mtime of the item's file with the item.added value
129         after each write of the item if `preserve_write_mtimes` is enabled.
130         """
131         if item.added:
132             if self.config['preserve_write_mtimes'].get(bool):
133                 self.write_item_mtime(item, item.added)
134             self._log.debug(u"Write of item '{0}', selected item.added={1}",
135                             util.displayable_path(item.path), item.added)
136
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/beetsplug/importadded.py b/beetsplug/importadded.py
--- a/beetsplug/importadded.py
+++ b/beetsplug/importadded.py
@@ -30,8 +30,8 @@
         self.item_mtime = dict()
 
         register = self.register_listener
-        register('import_task_start', self.check_config)
-        register('import_task_start', self.record_if_inplace)
+        register('import_task_created', self.check_config)
+        register('import_task_created', self.record_if_inplace)
         register('import_task_files', self.record_reimported)
         register('before_item_moved', self.record_import_mtime)
         register('item_copied', self.record_import_mtime)

{"golden_diff": "diff --git a/beetsplug/importadded.py b/beetsplug/importadded.py\n--- a/beetsplug/importadded.py\n+++ b/beetsplug/importadded.py\n@@ -30,8 +30,8 @@\n         self.item_mtime = dict()\n \n         register = self.register_listener\n-        register('import_task_start', self.check_config)\n-        register('import_task_start', self.record_if_inplace)\n+        register('import_task_created', self.check_config)\n+        register('import_task_created', self.record_if_inplace)\n         register('import_task_files', self.record_reimported)\n         register('before_item_moved', self.record_import_mtime)\n         register('item_copied', self.record_import_mtime)\n", "issue": "importadded: ValueError on trying to import a large library\nAfter migrating my music to a new drive, I'm trying to update the beets library. I've first run `beet update` so beets flushes out the old files, and I'm now running `beet import -AC .` to import the new files. Along the way, I've seen this error show up a couple times, though it is inconsistent in when it shows:\n\n```\nTraceback (most recent call last):\n  File \"/usr/local/bin/beet\", line 9, in <module>\n    load_entry_point('beets==1.3.17', 'console_scripts', 'beet')()\n  File \"/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py\", line 1236, in main\n    _raw_main(args)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py\", line 1226, in _raw_main\n    subcommand.func(lib, suboptions, subargs)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/ui/commands.py\", line 966, in import_func\n    import_files(lib, paths, query)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/ui/commands.py\", line 943, in import_files\n    session.run()\n  File \"/usr/local/lib/python2.7/dist-packages/beets/importer.py\", line 321, in run\n    pl.run_parallel(QUEUE_SIZE)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/util/pipeline.py\", line 348, in run\n    self.coro.send(msg)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/util/pipeline.py\", line 161, in coro\n    task = func(*(args + (task,)))\n  File \"/usr/local/lib/python2.7/dist-packages/beets/importer.py\", line 1401, in manipulate_files\n    task.finalize(session)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/importer.py\", line 544, in finalize\n    self._emit_imported(session.lib)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/importer.py\", line 570, in _emit_imported\n    plugins.send('album_imported', lib=lib, album=self.album)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/plugins.py\", line 459, in send\n    result = handler(**arguments)\n  File \"/usr/local/lib/python2.7/dist-packages/beets/plugins.py\", line 124, in wrapper\n    return func(*args, **kwargs)\n  File \"/usr/local/lib/python2.7/dist-packages/beetsplug/importadded.py\", line 106, in update_album_times\n    album.added = min(album_mtimes)\nValueError: min() arg is an empty sequence\n```\n\nI'm currently running beets 1.3.17, and my configuration is listed below:\n\n```\nimportfeeds:\n    dir: /media/Backup/Music\n    relative_to:\n    formats: m3u m3u_multi\n    absolute_path: no\n    m3u_name: imported.m3u\nweb:\n    host: 0.0.0.0\n    cors: '*'\nconvert:\n    max_bitrate: 192\n    command: ffmpeg -i $source -map_metadata 0 $dest\n    extension: mp3\n    never_convert_lossy_files: no\n    format: mp3\n    dest:\n    auto: no\n    threads: 4\n    copy_album_art: no\n    tmpdir:\n\n    paths: {}\n    pretend: no\n    quiet: no\n    formats:\n        alac:\n            command: ffmpeg -i $source -y -vn -acodec alac $dest\n            extension: m4a\n        aac:\n            command: ffmpeg -i $source -y -vn -acodec libfaac -aq 100 $dest\n            extension: m4a\n        opus: ffmpeg -i $source -y -vn -acodec libopus -ab 96k $dest\n        mp3: ffmpeg -i $source -y -vn -aq 2 $dest\n        flac: ffmpeg -i $source -y -vn -acodec flac $dest\n        ogg: ffmpeg -i $source -y -vn -acodec libvorbis -aq 2 $dest\n        wma: ffmpeg -i $source -y -vn -acodec wmav2 -vn $dest\n    embed: yes\nper_disc_numbering: yes\nfetchart:\n    auto: no\n    minwidth: 0\n    sources:\n    - coverart\n    - itunes\n    - amazon\n    - albumart\n    cautious: no\n    google_engine: 001442825323518660753:hrh5ch1gjzm\n    maxwidth: 0\n    google_key: REDACTED\n    cover_names:\n    - cover\n    - front\n    - art\n    - album\n    - folder\n    remote_priority: no\n    enforce_ratio: no\nembedart:\n    auto: no\n    compare_threshold: 0\n    ifempty: no\n    remove_art_file: no\n    maxwidth: 0\nreplaygain:\n    backend: gstreamer\n    targetlevel: 89\n    auto: yes\n    overwrite: no\nlibrary: ~/.config/beets/library.db\n\nplugins: duplicates importfeeds importadded replaygain embedart fetchart convert edit\ndirectory: /media/Backup/Music\nedit:\n    itemfields: track title artist album\n    albumfields: album albumartist\n    ignore_fields: id path\nimportadded:\n    preserve_mtimes: no\nduplicates:\n    count: no\n    full: no\n    format: ''\n    keys: []\n    move: ''\n    tag: ''\n    path: no\n    copy: ''\n    tiebreak: {}\n    album: no\n    strict: no\n    checksum: ''\n    merge: no\n    delete: no\n```\n\nI've since disabled the `importadded` plugin so I can just import all my files, but is there a way to fix this in the future? This is running off of an NTFS filesystem, so I don't know if a `stat` command or similar isn't coming back correctly, but I haven't had issues with this in the past.\n\nLet me know if there's any way I can assist.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"Populate an item's `added` and `mtime` fields by using the file\nmodification time (mtime) of the item's source file before import.\n\nReimported albums and items are skipped.\n\"\"\"\nfrom __future__ import division, absolute_import, print_function\n\nimport os\n\nfrom beets import util\nfrom beets import importer\nfrom beets.plugins import BeetsPlugin\n\n\nclass ImportAddedPlugin(BeetsPlugin):\n    def __init__(self):\n        super(ImportAddedPlugin, self).__init__()\n        self.config.add({\n            'preserve_mtimes': False,\n            'preserve_write_mtimes': False,\n        })\n\n        # item.id for new items that were reimported\n        self.reimported_item_ids = None\n        # album.path for old albums that were replaced by a reimported album\n        self.replaced_album_paths = None\n        # item path in the library to the mtime of the source file\n        self.item_mtime = dict()\n\n        register = self.register_listener\n        register('import_task_start', self.check_config)\n        register('import_task_start', self.record_if_inplace)\n        register('import_task_files', self.record_reimported)\n        register('before_item_moved', self.record_import_mtime)\n        register('item_copied', self.record_import_mtime)\n        register('item_linked', self.record_import_mtime)\n        register('item_hardlinked', self.record_import_mtime)\n        register('album_imported', self.update_album_times)\n        register('item_imported', self.update_item_times)\n        register('after_write', self.update_after_write_time)\n\n    def check_config(self, task, session):\n        self.config['preserve_mtimes'].get(bool)\n\n    def reimported_item(self, item):\n        return item.id in self.reimported_item_ids\n\n    def reimported_album(self, album):\n        return album.path in self.replaced_album_paths\n\n    def record_if_inplace(self, task, session):\n        if not (session.config['copy'] or session.config['move'] or\n                session.config['link'] or session.config['hardlink']):\n            self._log.debug(u\"In place import detected, recording mtimes from \"\n                            u\"source paths\")\n            items = [task.item] \\\n                if isinstance(task, importer.SingletonImportTask) \\\n                else task.items\n            for item in items:\n                self.record_import_mtime(item, item.path, item.path)\n\n    def record_reimported(self, task, session):\n        self.reimported_item_ids = set(item.id for item, replaced_items\n                                       in task.replaced_items.items()\n                                       if replaced_items)\n        self.replaced_album_paths = set(task.replaced_albums.keys())\n\n    def write_file_mtime(self, path, mtime):\n        \"\"\"Write the given mtime to the destination path.\n        \"\"\"\n        stat = os.stat(util.syspath(path))\n        os.utime(util.syspath(path), (stat.st_atime, mtime))\n\n    def write_item_mtime(self, item, mtime):\n        \"\"\"Write the given mtime to an item's `mtime` field and to the mtime\n        of the item's file.\n        \"\"\"\n        # The file's mtime on disk must be in sync with the item's mtime\n        self.write_file_mtime(util.syspath(item.path), mtime)\n        item.mtime = mtime\n\n    def record_import_mtime(self, item, source, destination):\n        \"\"\"Record the file mtime of an item's path before its import.\n        \"\"\"\n        mtime = os.stat(util.syspath(source)).st_mtime\n        self.item_mtime[destination] = mtime\n        self._log.debug(u\"Recorded mtime {0} for item '{1}' imported from \"\n                        u\"'{2}'\", mtime, util.displayable_path(destination),\n                        util.displayable_path(source))\n\n    def update_album_times(self, lib, album):\n        if self.reimported_album(album):\n            self._log.debug(u\"Album '{0}' is reimported, skipping import of \"\n                            u\"added dates for the album and its items.\",\n                            util.displayable_path(album.path))\n            return\n\n        album_mtimes = []\n        for item in album.items():\n            mtime = self.item_mtime.pop(item.path, None)\n            if mtime:\n                album_mtimes.append(mtime)\n                if self.config['preserve_mtimes'].get(bool):\n                    self.write_item_mtime(item, mtime)\n                    item.store()\n        album.added = min(album_mtimes)\n        self._log.debug(u\"Import of album '{0}', selected album.added={1} \"\n                        u\"from item file mtimes.\", album.album, album.added)\n        album.store()\n\n    def update_item_times(self, lib, item):\n        if self.reimported_item(item):\n            self._log.debug(u\"Item '{0}' is reimported, skipping import of \"\n                            u\"added date.\", util.displayable_path(item.path))\n            return\n        mtime = self.item_mtime.pop(item.path, None)\n        if mtime:\n            item.added = mtime\n            if self.config['preserve_mtimes'].get(bool):\n                self.write_item_mtime(item, mtime)\n            self._log.debug(u\"Import of item '{0}', selected item.added={1}\",\n                            util.displayable_path(item.path), item.added)\n            item.store()\n\n    def update_after_write_time(self, item):\n        \"\"\"Update the mtime of the item's file with the item.added value\n        after each write of the item if `preserve_write_mtimes` is enabled.\n        \"\"\"\n        if item.added:\n            if self.config['preserve_write_mtimes'].get(bool):\n                self.write_item_mtime(item, item.added)\n            self._log.debug(u\"Write of item '{0}', selected item.added={1}\",\n                            util.displayable_path(item.path), item.added)\n", "path": "beetsplug/importadded.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"Populate an item's `added` and `mtime` fields by using the file\nmodification time (mtime) of the item's source file before import.\n\nReimported albums and items are skipped.\n\"\"\"\nfrom __future__ import division, absolute_import, print_function\n\nimport os\n\nfrom beets import util\nfrom beets import importer\nfrom beets.plugins import BeetsPlugin\n\n\nclass ImportAddedPlugin(BeetsPlugin):\n    def __init__(self):\n        super(ImportAddedPlugin, self).__init__()\n        self.config.add({\n            'preserve_mtimes': False,\n            'preserve_write_mtimes': False,\n        })\n\n        # item.id for new items that were reimported\n        self.reimported_item_ids = None\n        # album.path for old albums that were replaced by a reimported album\n        self.replaced_album_paths = None\n        # item path in the library to the mtime of the source file\n        self.item_mtime = dict()\n\n        register = self.register_listener\n        register('import_task_created', self.check_config)\n        register('import_task_created', self.record_if_inplace)\n        register('import_task_files', self.record_reimported)\n        register('before_item_moved', self.record_import_mtime)\n        register('item_copied', self.record_import_mtime)\n        register('item_linked', self.record_import_mtime)\n        register('item_hardlinked', self.record_import_mtime)\n        register('album_imported', self.update_album_times)\n        register('item_imported', self.update_item_times)\n        register('after_write', self.update_after_write_time)\n\n    def check_config(self, task, session):\n        self.config['preserve_mtimes'].get(bool)\n\n    def reimported_item(self, item):\n        return item.id in self.reimported_item_ids\n\n    def reimported_album(self, album):\n        return album.path in self.replaced_album_paths\n\n    def record_if_inplace(self, task, session):\n        if not (session.config['copy'] or session.config['move'] or\n                session.config['link'] or session.config['hardlink']):\n            self._log.debug(u\"In place import detected, recording mtimes from \"\n                            u\"source paths\")\n            items = [task.item] \\\n                if isinstance(task, importer.SingletonImportTask) \\\n                else task.items\n            for item in items:\n                self.record_import_mtime(item, item.path, item.path)\n\n    def record_reimported(self, task, session):\n        self.reimported_item_ids = set(item.id for item, replaced_items\n                                       in task.replaced_items.items()\n                                       if replaced_items)\n        self.replaced_album_paths = set(task.replaced_albums.keys())\n\n    def write_file_mtime(self, path, mtime):\n        \"\"\"Write the given mtime to the destination path.\n        \"\"\"\n        stat = os.stat(util.syspath(path))\n        os.utime(util.syspath(path), (stat.st_atime, mtime))\n\n    def write_item_mtime(self, item, mtime):\n        \"\"\"Write the given mtime to an item's `mtime` field and to the mtime\n        of the item's file.\n        \"\"\"\n        # The file's mtime on disk must be in sync with the item's mtime\n        self.write_file_mtime(util.syspath(item.path), mtime)\n        item.mtime = mtime\n\n    def record_import_mtime(self, item, source, destination):\n        \"\"\"Record the file mtime of an item's path before its import.\n        \"\"\"\n        mtime = os.stat(util.syspath(source)).st_mtime\n        self.item_mtime[destination] = mtime\n        self._log.debug(u\"Recorded mtime {0} for item '{1}' imported from \"\n                        u\"'{2}'\", mtime, util.displayable_path(destination),\n                        util.displayable_path(source))\n\n    def update_album_times(self, lib, album):\n        if self.reimported_album(album):\n            self._log.debug(u\"Album '{0}' is reimported, skipping import of \"\n                            u\"added dates for the album and its items.\",\n                            util.displayable_path(album.path))\n            return\n\n        album_mtimes = []\n        for item in album.items():\n            mtime = self.item_mtime.pop(item.path, None)\n            if mtime:\n                album_mtimes.append(mtime)\n                if self.config['preserve_mtimes'].get(bool):\n                    self.write_item_mtime(item, mtime)\n                    item.store()\n        album.added = min(album_mtimes)\n        self._log.debug(u\"Import of album '{0}', selected album.added={1} \"\n                        u\"from item file mtimes.\", album.album, album.added)\n        album.store()\n\n    def update_item_times(self, lib, item):\n        if self.reimported_item(item):\n            self._log.debug(u\"Item '{0}' is reimported, skipping import of \"\n                            u\"added date.\", util.displayable_path(item.path))\n            return\n        mtime = self.item_mtime.pop(item.path, None)\n        if mtime:\n            item.added = mtime\n            if self.config['preserve_mtimes'].get(bool):\n                self.write_item_mtime(item, mtime)\n            self._log.debug(u\"Import of item '{0}', selected item.added={1}\",\n                            util.displayable_path(item.path), item.added)\n            item.store()\n\n    def update_after_write_time(self, item):\n        \"\"\"Update the mtime of the item's file with the item.added value\n        after each write of the item if `preserve_write_mtimes` is enabled.\n        \"\"\"\n        if item.added:\n            if self.config['preserve_write_mtimes'].get(bool):\n                self.write_item_mtime(item, item.added)\n            self._log.debug(u\"Write of item '{0}', selected item.added={1}\",\n                            util.displayable_path(item.path), item.added)\n", "path": "beetsplug/importadded.py"}]}