CC-3770: Make sure files in /srv/airtime/stor have world-readable permissions.
-fixed
This commit is contained in:
parent
c466b946a0
commit
91d1dfbbfa
2 changed files with 92 additions and 55 deletions
|
@ -134,8 +134,9 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
#file is being overwritten/replaced in GUI.
|
#file is being overwritten/replaced in GUI.
|
||||||
elif "goutputstream" in pathname:
|
elif "goutputstream" in pathname:
|
||||||
self.temp_files[pathname] = None
|
self.temp_files[pathname] = None
|
||||||
elif self.mmc.is_audio_file(pathname) and self.mmc.is_readable(pathname, False):
|
elif self.mmc.is_audio_file(pathname):
|
||||||
if self.mmc.is_parent_directory(pathname, self.config.organize_directory):
|
if self.mmc.is_parent_directory(pathname, self.config.organize_directory):
|
||||||
|
|
||||||
#file was created in /srv/airtime/stor/organize. Need to process and move
|
#file was created in /srv/airtime/stor/organize. Need to process and move
|
||||||
#to /srv/airtime/stor/imported
|
#to /srv/airtime/stor/imported
|
||||||
oldPath = pathname
|
oldPath = pathname
|
||||||
|
@ -144,21 +145,18 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
#delete files from organize if they can not be read properly.
|
#delete files from organize if they can not be read properly.
|
||||||
if pathname is None:
|
if pathname is None:
|
||||||
try:
|
try:
|
||||||
self.logger.info("Deleting file because it cannot be read properly: %s", oldPath)
|
self.logger.warn("Deleting file because it cannot be read properly: %s", oldPath)
|
||||||
os.remove(oldPath)
|
os.remove(oldPath)
|
||||||
return
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error('Exception: %s', e)
|
self.logger.error('Exception: %s', e)
|
||||||
self.logger.error("traceback: %s", traceback.format_exc())
|
self.logger.error("traceback: %s", traceback.format_exc())
|
||||||
|
else:
|
||||||
self.mmc.is_readable(pathname, dir)
|
#ensure file is world readable (Liquidsoap and Web UI preview)
|
||||||
|
if self.mmc.make_readable(pathname):
|
||||||
is_recorded = self.mmc.is_parent_directory(pathname, self.config.recorded_directory)
|
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})
|
self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': pathname, 'is_recorded_show': is_recorded})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
#event is because of a created directory
|
self.logger.warn("Couldn't add %s because failed to change file permissions", pathname)
|
||||||
if self.mmc.is_parent_directory(pathname, self.config.storage_directory):
|
|
||||||
self.mmc.is_readable(pathname, dir)
|
|
||||||
|
|
||||||
def process_IN_MODIFY(self, event):
|
def process_IN_MODIFY(self, event):
|
||||||
# if IN_MODIFY is followed by IN_CREATE, it's not true modify event
|
# if IN_MODIFY is followed by IN_CREATE, it's not true modify event
|
||||||
|
@ -175,7 +173,7 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
self.create_dict[pathname] = time.time()
|
self.create_dict[pathname] = time.time()
|
||||||
if not dir and not self.mmc.is_parent_directory(pathname, self.config.organize_directory):
|
if not dir and not self.mmc.is_parent_directory(pathname, self.config.organize_directory):
|
||||||
self.logger.info("Modified: %s", pathname)
|
self.logger.info("Modified: %s", pathname)
|
||||||
if self.mmc.is_audio_file(name):
|
if self.mmc.is_audio_file(name) and self.mmc.make_readable(pathname):
|
||||||
self.file_events.append({'filepath': pathname, 'mode': self.config.MODE_MODIFY})
|
self.file_events.append({'filepath': pathname, 'mode': self.config.MODE_MODIFY})
|
||||||
|
|
||||||
# if change is detected on /etc/mtab, we check what mount(file system) was added/removed
|
# if change is detected on /etc/mtab, we check what mount(file system) was added/removed
|
||||||
|
@ -238,7 +236,8 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
self.handle_mount_change()
|
self.handle_mount_change()
|
||||||
|
|
||||||
if not event.dir:
|
if not event.dir:
|
||||||
if self.mmc.is_audio_file(event.name) and self.mmc.is_readable(event.pathname, False):
|
if self.mmc.is_audio_file(event.name):
|
||||||
|
if self.mmc.make_readable(event.pathname):
|
||||||
if event.cookie in self.temp_files:
|
if event.cookie in self.temp_files:
|
||||||
self.file_events.append({'filepath': event.pathname, 'mode': self.config.MODE_MODIFY})
|
self.file_events.append({'filepath': event.pathname, 'mode': self.config.MODE_MODIFY})
|
||||||
del self.temp_files[event.cookie]
|
del self.temp_files[event.cookie]
|
||||||
|
|
|
@ -84,6 +84,44 @@ class MediaMonitorCommon:
|
||||||
self.logger.warn("Failed to check owner/group/permissions for %s", item)
|
self.logger.warn("Failed to check owner/group/permissions for %s", item)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def make_file_readable(self, pathname, is_dir):
|
||||||
|
if is_dir:
|
||||||
|
#set to 755
|
||||||
|
os.chmod(pathname, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR | stat.S_IRGRP|stat.S_IXGRP | stat.S_IROTH|stat.S_IXOTH)
|
||||||
|
else:
|
||||||
|
#set to 644
|
||||||
|
os.chmod(pathname, stat.S_IRUSR|stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
|
||||||
|
|
||||||
|
def make_readable(self, pathname):
|
||||||
|
"""
|
||||||
|
Should only call this function if is_readable() returns False. This function
|
||||||
|
will attempt to make the file world readable by modifying the file's permission's
|
||||||
|
as well as the file's parent directory permissions. We should only call this function
|
||||||
|
on files in Airtime's stor directory, not watched directories!
|
||||||
|
|
||||||
|
Returns True if we were able to make the file world readable. False otherwise.
|
||||||
|
"""
|
||||||
|
original_file = pathname
|
||||||
|
is_dir = False
|
||||||
|
try:
|
||||||
|
while not is_readable(original_file, is_dir):
|
||||||
|
#Not readable. Make appropriate permission changes.
|
||||||
|
|
||||||
|
self.make_file_readable(pathname, is_dir)
|
||||||
|
|
||||||
|
dirname = os.path.dirname(pathname)
|
||||||
|
if dirname == pathname:
|
||||||
|
#most likey reason for this is that we've hit '/'. Avoid infinite loop by terminating loop
|
||||||
|
raise Exception()
|
||||||
|
else:
|
||||||
|
pathname = dirname
|
||||||
|
is_dir = True
|
||||||
|
except Exception, e:
|
||||||
|
#something went wrong while we were trying to make world readable.
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
#checks if path is a directory, and if it doesnt exist, then creates it.
|
#checks if path is a directory, and if it doesnt exist, then creates it.
|
||||||
#Otherwise prints error to log file.
|
#Otherwise prints error to log file.
|
||||||
def ensure_is_dir(self, directory):
|
def ensure_is_dir(self, directory):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue