From 5b47402ed040f7894c87c1bb0c853ec96cddc189 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 8 Feb 2012 15:14:58 -0500 Subject: [PATCH] CC-3299: Media monitor should not change the owner of watched files - it sets dir permission 02777 and file permission to 0666 if the path is under "stor" dir, else it tries add world readable bit. --- .../airtimefilemonitor/airtimeprocessevent.py | 6 +++-- .../airtimefilemonitor/mediamonitorcommon.py | 27 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index 4fbc210cd..0cb19b201 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -141,8 +141,10 @@ class AirtimeProcessEvent(ProcessEvent): self.mmc.set_needed_file_permissions(pathname, dir) def process_IN_MODIFY(self, event): - self.logger.info("process_IN_MODIFY: %s", event) - self.handle_modified_file(event.dir, event.pathname, event.name) + # if IN_MODIFY is followed by IN_CREATE, it's not true modify event + if not event.pathname in self.create_dict: + self.logger.info("process_IN_MODIFY: %s", event) + self.handle_modified_file(event.dir, event.pathname, event.name) def handle_modified_file(self, dir, pathname, name): # update timestamp on create_dict for the entry with pathname as the key diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index c9c3e2daf..2c8c66a7e 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -2,6 +2,7 @@ import os import grp import pwd import logging +import stat from subprocess import Popen, PIPE from airtimemetadata import AirtimeMetadata @@ -74,17 +75,23 @@ class MediaMonitorCommon: def set_needed_file_permissions(self, item, is_dir): try: omask = os.umask(0) - if not self.has_correct_permissions(item, 'www-data', 'www-data'): - uid = pwd.getpwnam('www-data')[2] - gid = grp.getgrnam('www-data')[2] - - os.chown(item, uid, gid) - - if is_dir is True: - os.chmod(item, 02777) - else: - os.chmod(item, 0666) + # 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 + if self.is_parent_directory(item, self.config.storage_directory) or self.is_parent_directory(item, self.config.imported_directory) or (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: + os.chmod(item, stats.st_mode | stat.S_IROTH | stat.S_IXOTH) + else: + os.chmod(item, stats.st_mode | stat.S_IROTH) except Exception, e: self.logger.error("Failed to change file's owner/group/permissions. %s", e)