Skip to content

Commit

Permalink
plugin now listens for item_copied instead of after_write. now the te…
Browse files Browse the repository at this point in the history
…st works
  • Loading branch information
xsteadfastx committed Nov 20, 2014
1 parent a01e73d commit 8784e8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 8 additions & 7 deletions beetsplug/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def __init__(self):
})


@Permissions.listen('after_write')
def permissions(path):
@Permissions.listen('item_copied')
def permissions(item, source, destination):
"""Running the permission fixer.
"""
# Getting the config.
Expand All @@ -45,10 +45,11 @@ def permissions(path):
# Converts file permissions to oct.
file_perm = convert_perm(file_perm)

# Changing permissions on the path.
os.chmod(util.bytestring_path(path), file_perm)
# Changing permissions on the destination path.
os.chmod(util.bytestring_path(destination), file_perm)

# Checks if the 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)
# 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)
4 changes: 3 additions & 1 deletion test/test_permissions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Tests for the 'permissions' plugin.
"""
from _common import unittest
from helper import TestHelper
from beetsplug.permissions import check_permissions, convert_perm
Expand All @@ -22,7 +24,7 @@ def test_perm(self):
config_perm = self.config['permissions']['file'].get()
config_perm = convert_perm(config_perm)

assert check_permissions(item.path, config_perm)
self.assertTrue(check_permissions(item.path, config_perm))


def suite():
Expand Down

0 comments on commit 8784e8d

Please sign in to comment.