diff --git a/beetsplug/permissions.py b/beetsplug/permissions.py index 3d389911d..3caec40e0 100644 --- a/beetsplug/permissions.py +++ b/beetsplug/permissions.py @@ -35,9 +35,9 @@ class Permissions(BeetsPlugin): }) -@Permissions.listen('item_moved') -@Permissions.listen('item_copied') -def permissions(item, source, destination): +@Permissions.listen('item_imported') +@Permissions.listen('album_imported') +def permissions(lib, item=None, album=None): """Running the permission fixer. """ # Getting the config. @@ -46,11 +46,21 @@ def permissions(item, source, destination): # Converts file permissions to oct. file_perm = convert_perm(file_perm) - # Changing permissions on the destination path. - os.chmod(util.bytestring_path(destination), file_perm) + # Create chmod_queue. + chmod_queue = [] + if item: + chmod_queue.append(item.path) + elif album: + for album_item in album.items(): + chmod_queue.append(album_item.path) - # Checks if the destination path has the permissions configured. - if not check_permissions(util.bytestring_path(destination), file_perm): - message = 'There was a problem setting permission on {}'.format( - destination) - print(message) + # Setting permissions for every path in the queue. + for path in chmod_queue: + # Changing permissions on the destination path. + os.chmod(util.bytestring_path(path), file_perm) + + # Checks if the destination path has the permissions configured. + if not check_permissions(util.bytestring_path(path), file_perm): + message = 'There was a problem setting permission on {}'.format( + path) + print(message) diff --git a/test/test_permissions.py b/test/test_permissions.py index cad7a47da..9f3ae858c 100644 --- a/test/test_permissions.py +++ b/test/test_permissions.py @@ -15,9 +15,8 @@ class PermissionsPluginTest(unittest.TestCase, TestHelper): def tearDown(self): self.teardown_beets() - self.unload_plugins() - def test_perm(self): + def test_permissions_on_album_imported(self): self.importer = self.create_importer() self.importer.run() item = self.lib.items().get() @@ -25,6 +24,18 @@ class PermissionsPluginTest(unittest.TestCase, TestHelper): config_perm = convert_perm(config_perm) self.assertTrue(check_permissions(item.path, config_perm)) + self.assertFalse(check_permissions(item.path, convert_perm(644))) + + def test_permissions_on_item_imported(self): + self.config['import']['singletons'] = True + self.importer = self.create_importer() + self.importer.run() + item = self.lib.items().get() + config_perm = self.config['permissions']['file'].get() + config_perm = convert_perm(config_perm) + + self.assertTrue(check_permissions(item.path, config_perm)) + self.assertFalse(check_permissions(item.path, convert_perm(644))) def suite():