From 317c7d03b2ca8775ccf86e15510eb2471acc75db Mon Sep 17 00:00:00 2001 From: danny <> Date: Mon, 11 Apr 2022 14:38:09 +0300 Subject: [PATCH 1/2] add reflink support --- beetsplug/extrafiles.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/beetsplug/extrafiles.py b/beetsplug/extrafiles.py index 7e92983..92b557c 100644 --- a/beetsplug/extrafiles.py +++ b/beetsplug/extrafiles.py @@ -78,11 +78,13 @@ def __init__(self, *args, **kwargs): self._moved_items = set() self._copied_items = set() + self._reflinked_items = set() self._scanned_paths = set() self.path_formats = beets.ui.get_path_formats(self.config['paths']) self.register_listener('item_moved', self.on_item_moved) self.register_listener('item_copied', self.on_item_copied) + self.register_listener('item_reflinked', self.on_item_reflinked) self.register_listener('cli_exit', self.on_cli_exit) def on_item_moved(self, item, source, destination): @@ -93,11 +95,18 @@ def on_item_copied(self, item, source, destination): """Run this listener function on item_copied events.""" self._copied_items.add((item, source, destination)) + def on_item_reflinked(self, item, source, destination): + """Run this listener function on item_reflinked events.""" + self._reflinked_items.add((item, source, destination)) + def on_cli_exit(self, lib): """Run this listener function when the CLI exits.""" files = self.gather_files(self._copied_items) self.process_items(files, action=self._copy_file) + files = self.gather_files(self._reflinked_items) + self.process_items(files, action=self._reflink_file) + files = self.gather_files(self._moved_items) self.process_items(files, action=self._move_file) @@ -123,6 +132,29 @@ def _copy_file(self, path, dest): else: beets.util.copy(path, dest) + def _reflink_file(self, path, dest): + """Reflink path to dest.""" + self._log.info('Reflinking extra file: {0} -> {1}', path, dest) + if os.path.isdir(path): + if os.path.exists(dest): + raise beets.util.FilesystemError( + 'file exists', 'link', + (path, dest), + ) + + sourcepath = beets.util.displayable_path(path) + destpath = beets.util.displayable_path(dest) + try: + shutil.copytree(sourcepath, destpath, + copy_function=beets.util.reflink) + except (OSError, IOError) as exc: + raise beets.util.FilesystemError( + exc, 'link', (path, dest), + traceback.format_exc(), + ) + else: + beets.util.reflink(path, dest) + def _move_file(self, path, dest): """Move path to dest.""" self._log.info('Moving extra file: {0} -> {1}', path, dest) From e31c7ee5a70ebb194c3835e87f85cdd8d93c7b8d Mon Sep 17 00:00:00 2001 From: Daniel <23189912+danyisill@users.noreply.github.com> Date: Mon, 11 Apr 2022 15:57:57 +0300 Subject: [PATCH 2/2] it keeps complaining for some reason on aur --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cc1bb53..9487dd8 100755 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ test_suite='tests', install_requires=[ 'beets>=1.4.7', - 'mediafile~=0.6.0', + 'mediafile>=0.9.0', ], classifiers=[ 'Topic :: Multimedia :: Sound/Audio',