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.
This commit is contained in:
parent
103b4abdeb
commit
5b47402ed0
|
@ -141,8 +141,10 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
self.mmc.set_needed_file_permissions(pathname, dir)
|
self.mmc.set_needed_file_permissions(pathname, dir)
|
||||||
|
|
||||||
def process_IN_MODIFY(self, event):
|
def process_IN_MODIFY(self, event):
|
||||||
self.logger.info("process_IN_MODIFY: %s", event)
|
# if IN_MODIFY is followed by IN_CREATE, it's not true modify event
|
||||||
self.handle_modified_file(event.dir, event.pathname, event.name)
|
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):
|
def handle_modified_file(self, dir, pathname, name):
|
||||||
# update timestamp on create_dict for the entry with pathname as the key
|
# update timestamp on create_dict for the entry with pathname as the key
|
||||||
|
|
|
@ -2,6 +2,7 @@ import os
|
||||||
import grp
|
import grp
|
||||||
import pwd
|
import pwd
|
||||||
import logging
|
import logging
|
||||||
|
import stat
|
||||||
|
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
from airtimemetadata import AirtimeMetadata
|
from airtimemetadata import AirtimeMetadata
|
||||||
|
@ -74,17 +75,23 @@ class MediaMonitorCommon:
|
||||||
def set_needed_file_permissions(self, item, is_dir):
|
def set_needed_file_permissions(self, item, is_dir):
|
||||||
try:
|
try:
|
||||||
omask = os.umask(0)
|
omask = os.umask(0)
|
||||||
|
|
||||||
if not self.has_correct_permissions(item, 'www-data', 'www-data'):
|
if not self.has_correct_permissions(item, 'www-data', 'www-data'):
|
||||||
uid = pwd.getpwnam('www-data')[2]
|
# stats.st_mode is the original permission
|
||||||
gid = grp.getgrnam('www-data')[2]
|
# stat.S_IROTH - readable by all permission
|
||||||
|
# stat.S_IXOTH - excutable by all permission
|
||||||
os.chown(item, uid, gid)
|
# 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:
|
if is_dir is True:
|
||||||
os.chmod(item, 02777)
|
os.chmod(item, 02777)
|
||||||
else:
|
else:
|
||||||
os.chmod(item, 0666)
|
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:
|
except Exception, e:
|
||||||
self.logger.error("Failed to change file's owner/group/permissions. %s", e)
|
self.logger.error("Failed to change file's owner/group/permissions. %s", e)
|
||||||
|
|
Loading…
Reference in New Issue