CC-3749: Media Monitor should not load files pypo cannot read

-fixed
This commit is contained in:
Martin Konecny 2012-05-04 13:37:43 -04:00
parent 08217d59fc
commit fa373a683e
3 changed files with 14 additions and 37 deletions

View file

@ -103,9 +103,9 @@ class AirtimeNotifier(Notifier):
self.mmc.ensure_is_dir(self.config.imported_directory)
self.mmc.ensure_is_dir(self.config.organize_directory)
self.mmc.set_needed_file_permissions(self.config.storage_directory, True)
self.mmc.set_needed_file_permissions(self.config.imported_directory, True)
self.mmc.set_needed_file_permissions(self.config.organize_directory, True)
self.mmc.is_readable(self.config.storage_directory, True)
self.mmc.is_readable(self.config.imported_directory, True)
self.mmc.is_readable(self.config.organize_directory, True)
self.watch_directory(new_storage_directory)
elif m['event_type'] == "file_delete":
@ -192,17 +192,17 @@ class AirtimeNotifier(Notifier):
mm = self.proc_fun()
self.mmc.set_needed_file_permissions(directory, True)
self.mmc.is_readable(directory, True)
for (path, dirs, files) in os.walk(directory):
for d in dirs:
self.mmc.set_needed_file_permissions(os.path.join(path, d), True)
self.mmc.is_readable(os.path.join(path, d), True)
for filename in files:
full_filepath = os.path.join(path, filename)
if self.mmc.is_audio_file(full_filepath):
if self.mmc.set_needed_file_permissions(full_filepath, False):
if self.mmc.is_readable(full_filepath, False):
self.logger.info("importing %s", full_filepath)
event = {'filepath': full_filepath, 'mode': self.config.MODE_CREATE, 'is_recorded_show': False}
mm.multi_queue.put(event)

View file

@ -151,14 +151,14 @@ class AirtimeProcessEvent(ProcessEvent):
self.logger.error('Exception: %s', e)
self.logger.error("traceback: %s", traceback.format_exc())
self.mmc.set_needed_file_permissions(pathname, dir)
self.mmc.is_readable(pathname, dir)
is_recorded = self.mmc.is_parent_directory(pathname, self.config.recorded_directory)
self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': pathname, 'is_recorded_show': is_recorded})
else:
#event is because of a created directory
if self.mmc.is_parent_directory(pathname, self.config.storage_directory):
self.mmc.set_needed_file_permissions(pathname, dir)
self.mmc.is_readable(pathname, dir)
def process_IN_MODIFY(self, event):
# if IN_MODIFY is followed by IN_CREATE, it's not true modify event
@ -237,7 +237,7 @@ class AirtimeProcessEvent(ProcessEvent):
if event.pathname in filename:
self.handle_mount_change()
#if stuff dropped in stor via a UI move must change file permissions.
self.mmc.set_needed_file_permissions(event.pathname, event.dir)
self.mmc.is_readable(event.pathname, event.dir)
if not event.dir:
if self.mmc.is_audio_file(event.name):
if event.cookie in self.temp_files:

View file

@ -49,7 +49,7 @@ class MediaMonitorCommon:
return False
#check if file is readable by "nobody"
def has_correct_permissions(self, filepath, euid='nobody', egid='nogroup'):
def is_user_readable(self, filepath, euid='nobody', egid='nogroup'):
try:
uid = pwd.getpwnam(euid)[2]
@ -76,40 +76,17 @@ class MediaMonitorCommon:
return readable
# the function only changes the permission if its not readable by www-data
def set_needed_file_permissions(self, item, is_dir):
def is_readable(self, item, is_dir):
try:
omask = os.umask(0)
if not self.has_correct_permissions(item, 'www-data', 'www-data') \
or not self.has_correct_permissions(item, 'pypo', 'pypo'):
if not self.is_user_readable(item, 'www-data', 'www-data') \
or not self.is_user_readable(item, 'pypo', 'pypo'):
# stats.st_mode is the original permission
# stat.S_IROTH - readable by all permission
# stat.S_IXOTH - excutable by all permission
# try to set permission
self.logger.warn("%s has incorrect permissions for reading. Skipping import.", item)
"""
if self.is_parent_directory(item, self.config.storage_directory) \
or self.is_parent_directory(item, self.config.imported_directory) \
or self.is_parent_directory(item, self.config.organize_directory):
if is_dir is True:
os.chmod(item, 02777)
else:
os.chmod(item, 0666)
else:
# add world readable permission
stats = os.stat(item)
if is_dir is True:
bitor = stats.st_mode | stat.S_IROTH | stat.S_IXOTH
else:
bitor = stats.st_mode | stat.S_IROTH
os.chmod(item, bitor)
"""
return False
except Exception, e:
self.logger.warn("Failed to change owner/group/permissions for %s", item)
return False
finally:
os.umask(omask)
return True