@@ -70,10 +70,29 @@ def __init__(self):
70
70
71
71
self .register_listener ('item_imported' , self .fix )
72
72
self .register_listener ('album_imported' , self .fix )
73
+ self .register_listener ('art_set' , self .fix_art )
73
74
74
75
def fix (self , lib , item = None , album = None ):
75
76
"""Fix the permissions for an imported Item or Album.
76
77
"""
78
+ files = []
79
+ dirs = set ()
80
+ if item :
81
+ files .append (item .path )
82
+ dirs .update (dirs_in_library (lib .directory , item .path ))
83
+ elif album :
84
+ for album_item in album .items ():
85
+ files .append (album_item .path )
86
+ dirs .update (dirs_in_library (lib .directory , album_item .path ))
87
+ self .set_permissions (files = files , dirs = dirs )
88
+
89
+ def fix_art (self , album ):
90
+ """Fix the permission for Album art file.
91
+ """
92
+ if album .artpath :
93
+ self .set_permissions (files = [album .artpath ])
94
+
95
+ def set_permissions (self , files = [], dirs = []):
77
96
# Get the configured permissions. The user can specify this either a
78
97
# string (in YAML quotes) or, for convenience, as an integer so the
79
98
# quotes can be omitted. In the latter case, we need to reinterpret the
@@ -83,18 +102,7 @@ def fix(self, lib, item=None, album=None):
83
102
file_perm = convert_perm (file_perm )
84
103
dir_perm = convert_perm (dir_perm )
85
104
86
- # Create chmod_queue.
87
- file_chmod_queue = []
88
- if item :
89
- file_chmod_queue .append (item .path )
90
- elif album :
91
- for album_item in album .items ():
92
- file_chmod_queue .append (album_item .path )
93
-
94
- # A set of directories to change permissions for.
95
- dir_chmod_queue = set ()
96
-
97
- for path in file_chmod_queue :
105
+ for path in files :
98
106
# Changing permissions on the destination file.
99
107
self ._log .debug (
100
108
u'setting file permissions on {}' ,
@@ -105,13 +113,8 @@ def fix(self, lib, item=None, album=None):
105
113
# Checks if the destination path has the permissions configured.
106
114
assert_permissions (path , file_perm , self ._log )
107
115
108
- # Adding directories to the directory chmod queue.
109
- dir_chmod_queue .update (
110
- dirs_in_library (lib .directory ,
111
- path ))
112
-
113
116
# Change permissions for the directories.
114
- for path in dir_chmod_queue :
117
+ for path in dirs :
115
118
# Chaning permissions on the destination directory.
116
119
self ._log .debug (
117
120
u'setting directory permissions on {}' ,
0 commit comments