mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 13:07:09 +01:00
Fix #2089: correct permissions configuration
This reverts the change in 44380db6e8, where we
lost the ability to "reinterpret" decimals in the YAML configuration file as
octal permissions values.
This commit is contained in:
parent
84bfbe95b9
commit
890b9e81e3
3 changed files with 22 additions and 10 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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/
|
||||
|
||||
|
|
|
|||
|
|
@ -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__)
|
||||
|
|
|
|||
Loading…
Reference in a new issue