From fa373a683ea95da76b05a6244cffd4fc270518ff Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Fri, 4 May 2012 13:37:43 -0400 Subject: [PATCH] CC-3749: Media Monitor should not load files pypo cannot read -fixed --- .../airtimefilemonitor/airtimenotifier.py | 12 +++---- .../airtimefilemonitor/airtimeprocessevent.py | 6 ++-- .../airtimefilemonitor/mediamonitorcommon.py | 33 +++---------------- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py index 42f22b0ba..cbb404712 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py @@ -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) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index 0d6a6e602..947b16282 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -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: diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index 89800c5c5..b6ed45a80 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -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