From 12173d30a8077d588821952ca670c4457bf01a97 Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:04:24 +0100 Subject: [PATCH] permissions: Move syspath conversion to the actual API boundary --- beetsplug/permissions.py | 27 ++++++++++++--------------- test/rsrc/unicode’d.mp3 | Bin 25287 -> 75297 bytes 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/beetsplug/permissions.py b/beetsplug/permissions.py index a55feb6ca..6fe3aabe5 100644 --- a/beetsplug/permissions.py +++ b/beetsplug/permissions.py @@ -7,9 +7,9 @@ like the following in your config.yaml to configure: """ import os import stat -from beets import config, util +from beets import config from beets.plugins import BeetsPlugin -from beets.util import ancestry +from beets.util import ancestry, displayable_path, syspath def convert_perm(perm): @@ -26,7 +26,7 @@ def check_permissions(path, permission): """Check whether the file's permissions equal the given vector. Return a boolean. """ - return oct(stat.S_IMODE(os.stat(path).st_mode)) == oct(permission) + return oct(stat.S_IMODE(os.stat(syspath(path)).st_mode)) == oct(permission) def assert_permissions(path, permission, log): @@ -34,15 +34,12 @@ def assert_permissions(path, permission, log): log a warning message. Return a boolean indicating the match, like `check_permissions`. """ - if not check_permissions(util.syspath(path), permission): - log.warning( - 'could not set permissions on {}', - util.displayable_path(path), - ) + if not check_permissions(path, permission): + log.warning('could not set permissions on {}', displayable_path(path)) log.debug( 'set permissions to {}, but permissions are now {}', permission, - os.stat(util.syspath(path)).st_mode & 0o777, + os.stat(syspath(path)).st_mode & 0o777, ) @@ -102,10 +99,10 @@ class Permissions(BeetsPlugin): # Changing permissions on the destination file. self._log.debug( 'setting file permissions on {}', - util.displayable_path(path), + displayable_path(path), ) - if not check_permissions(util.syspath(path), file_perm): - os.chmod(util.syspath(path), file_perm) + if not check_permissions(path, file_perm): + os.chmod(syspath(path), file_perm) # Checks if the destination path has the permissions configured. assert_permissions(path, file_perm, self._log) @@ -115,10 +112,10 @@ class Permissions(BeetsPlugin): # Changing permissions on the destination directory. self._log.debug( 'setting directory permissions on {}', - util.displayable_path(path), + displayable_path(path), ) - if not check_permissions(util.syspath(path), dir_perm): - os.chmod(util.syspath(path), dir_perm) + if not check_permissions(path, dir_perm): + os.chmod(syspath(path), dir_perm) # Checks if the destination path has the permissions configured. assert_permissions(path, dir_perm, self._log) diff --git a/test/rsrc/unicode’d.mp3 b/test/rsrc/unicode’d.mp3 index 7a145f01e4b3d17c26abd4ad25101d50af8c9229..f7e8b6285ac6eb3d606a6f7fcaee76a4f8f9e735 100644 GIT binary patch delta 344 zcmX?plyTu17A{X0V-^Mm2IdOKja<)}nVBB%2VxHf;ZxTXmJ{|u3< delta 60 zcmZ2@hUNHCMlMemV-^M=C`{kT^_-cRAu(t37v_0#n-921v28x^^$X+X1zOt}VcbTx K&E9{mX#xP5#u%pn