Skip to content

Commit

Permalink
Fix #2089: correct permissions configuration
Browse files Browse the repository at this point in the history
This reverts the change in 44380db, where we
lost the ability to "reinterpret" decimals in the YAML configuration file as
octal permissions values.
  • Loading branch information
sampsyo committed Jun 28, 2016
1 parent 84bfbe9 commit 890b9e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
21 changes: 12 additions & 9 deletions beetsplug/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
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):
Expand Down Expand Up @@ -63,7 +65,7 @@ def __init__(self):
# Adding defaults.
self.config.add({
u'file': '644',
u'dir': '755'
u'dir': '755',
})

self.register_listener('item_imported', self.fix)
Expand All @@ -72,11 +74,12 @@ def __init__(self):
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)

Expand Down
8 changes: 7 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
3 changes: 3 additions & 0 deletions test/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def assertPerms(self, path, typ, expect_success): # noqa
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__)
Expand Down

0 comments on commit 890b9e8

Please sign in to comment.