From 890b9e81e3dec898e365a4f3478df749dc27a1c8 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 28 Jun 2016 10:51:13 -0700 Subject: [PATCH] Fix #2089: correct permissions configuration This reverts the change in 44380db6e8dc6ed5e656b00444b6171accd90562, where we lost the ability to "reinterpret" decimals in the YAML configuration file as octal permissions values. --- beetsplug/permissions.py | 21 ++++++++++++--------- docs/changelog.rst | 8 +++++++- test/test_permissions.py | 3 +++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/beetsplug/permissions.py b/beetsplug/permissions.py index 1d2c45f0f..aaf923fe8 100644 --- a/beetsplug/permissions.py +++ b/beetsplug/permissions.py @@ -13,15 +13,17 @@ import os from beets import config, util from beets.plugins import BeetsPlugin from beets.util import ancestry +import six def convert_perm(perm): - """If the perm is a int then just return it, otherwise convert it to oct. + """Convert a string to an integer, interpreting the text as octal. + Or, if `perm` is an integer, reinterpret it as an octal number that + has been "misinterpreted" as decimal. """ - if isinstance(perm, int): - return perm - else: - return int(perm, 8) + if isinstance(perm, six.integer_types): + perm = six.text_type(perm) + return int(perm, 8) def check_permissions(path, permission): @@ -63,7 +65,7 @@ class Permissions(BeetsPlugin): # Adding defaults. self.config.add({ u'file': '644', - u'dir': '755' + u'dir': '755', }) self.register_listener('item_imported', self.fix) @@ -72,11 +74,12 @@ class Permissions(BeetsPlugin): def fix(self, lib, item=None, album=None): """Fix the permissions for an imported Item or Album. """ - # Getting the config. + # Get the configured permissions. The user can specify this either a + # string (in YAML quotes) or, for convenience, as an integer so the + # quotes can be omitted. In the latter case, we need to reinterpret the + # integer as octal, not decimal. file_perm = config['permissions']['file'].get() dir_perm = config['permissions']['dir'].get() - - # Converts permissions to oct. file_perm = convert_perm(file_perm) dir_perm = convert_perm(dir_perm) diff --git a/docs/changelog.rst b/docs/changelog.rst index 8e780b9a6..ef91a11da 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,9 +13,15 @@ New features: 'path' tag to the json outpu of a file which shows the relative path to the file. :bug:`2050` -Other fixes: +Fixes: * :doc:`/plugins/web`: Normalized the json output +* :doc:`/plugins/permissions`: Fix a regression in the previous release where + the plugin would always fail to set permissions (and log a warning). + :bug:`2089` + +The last release, 1.3.19, also erroneously reported its version as "1.3.18" +when you typed ``beet version``. This has been corrected. .. _six: https://pythonhosted.org/six/ diff --git a/test/test_permissions.py b/test/test_permissions.py index c6b1837b4..7234ec30d 100644 --- a/test/test_permissions.py +++ b/test/test_permissions.py @@ -74,6 +74,9 @@ class PermissionsPluginTest(unittest.TestCase, TestHelper): def test_convert_perm_from_string(self): self.assertEqual(convert_perm('10'), 8) + def test_convert_perm_from_int(self): + self.assertEqual(convert_perm(10), 8) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)