diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 57bff257d..a1a96df8b 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -521,8 +521,9 @@ class ApiController extends Zend_Controller_Action print 'You are not allowed to access this resource.'; exit; } + $dir_id = $request->getParam('dir_id'); - $this->view->files = StoredFile::listAllFiles(); + $this->view->files = StoredFile::listAllFiles($dir_id); } public function listAllWatchedDirsAction() { @@ -542,10 +543,10 @@ class ApiController extends Zend_Controller_Action $arrWatchedDirs = MusicDir::getWatchedDirs(); $storDir = MusicDir::getStorDir(); - $result[] = $storDir->getDirectory(); + $result[$storDir->getId()] = $storDir->getDirectory(); foreach ($arrWatchedDirs as $watchedDir){ - $result[] = $watchedDir->getDirectory(); + $result[$watchedDir->getId()] = $watchedDir->getDirectory(); } $this->view->dirs = $result; diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index bd7c77628..1401e366a 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -819,14 +819,15 @@ class StoredFile { } - public static function listAllFiles(){ + public static function listAllFiles($dir_id){ global $CC_CONFIG, $CC_DBC; $sql = "SELECT m.directory || '/' || f.filepath as fp" ." FROM CC_MUSIC_DIRS m" ." LEFT JOIN CC_FILES f" ." ON m.id = f.directory" - ." WHERE m.id = f.directory"; + ." WHERE m.id = f.directory" + ." AND directory = $dir_id"; $rows = $CC_DBC->getAll($sql); $results = array(); diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 7ed9acdd3..eb828d2df 100644 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -105,7 +105,7 @@ class ApiClientInterface: def update_media_metadata(self, md): pass - def list_all_db_files(self): + def list_all_db_files(self, dir_id): pass def list_all_watched_dirs(self): @@ -409,12 +409,13 @@ class AirTimeApiClient(ApiClientInterface): return response - def list_all_db_files(self): + def list_all_db_files(self, dir_id): logger = logging.getLogger() try: url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["list_all_db_files"]) url = url.replace("%%api_key%%", self.config["api_key"]) + url = url.replace("%%dir_id%%", dir_id) req = urllib2.Request(url) response = urllib2.urlopen(req).read() diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py b/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py index 9e3a07fd6..e8c4b7367 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py @@ -26,17 +26,17 @@ class AirtimeMediaMonitorBootstrap(): self.logger.info("watched directories found: %s", directories) - for dir in directories: - self.check_for_diff(dir) + for id, dir in directories: + self.check_for_diff(id, dir) - def list_db_files(self): - return self.api_client.list_all_db_files() + def list_db_files(self, dir_id): + return self.api_client.list_all_db_files(dir_id) def get_list_of_watched_dirs(self): json = self.api_client.list_all_watched_dirs() return json["dirs"] - def check_for_diff(self, dir): + def check_for_diff(self, dir_id, dir): #set to hold new and/or modified files. We use a set to make it ok if files are added #twice. This is become some of the tests for new files return result sets that are not #mutually exclusive from each other. @@ -45,7 +45,7 @@ class AirtimeMediaMonitorBootstrap(): db_known_files_set = set() - files = self.list_db_files() + files = self.list_db_files(dir_id) for file in files['files']: db_known_files_set.add(file) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py index fd29a5e5a..361e8248d 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py @@ -64,11 +64,14 @@ class AirtimeNotifier(Notifier): self.md_manager.save_md_to_file(m) elif m['event_type'] == "new_watch": - self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory']) - self.walk_newly_watched_directory(m['directory']) - mm = self.proc_fun() - mm.watch_directory(m['directory']) + if mm.has_correct_permissions(m['directory']): + self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory']) + self.walk_newly_watched_directory(m['directory']) + + mm.watch_directory(m['directory']) + else: + self.logger.warn("filepath '%s' has does not have sufficient read permissions. Ignoring.", full_filepath) elif m['event_type'] == "remove_watch": watched_directory = m['directory'].encode('utf-8') @@ -170,7 +173,10 @@ class AirtimeNotifier(Notifier): full_filepath = path+"/"+filename if mm.is_audio_file(full_filepath): - 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) + if mm.has_correct_permissions(full_filepath): + 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) + else: + self.logger.warn("file '%s' has does not have sufficient read permissions. Ignoring.", full_filepath) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index c3a3a9ab1..6ed9f1272 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -61,6 +61,13 @@ class AirtimeProcessEvent(ProcessEvent): return True else: return False + + #file needs to be readable by all users, and directories + #up to this file needs to be readable AND executable by all + #users. + def has_correct_permissions(self, filepath): + st = os.stat(filepath) + return bool(st.st_mode & stat.S_IROTH) def set_needed_file_permissions(self, item, is_dir): @@ -100,7 +107,7 @@ class AirtimeProcessEvent(ProcessEvent): omask = os.umask(0) os.rename(source, dest) except Exception, e: - self.logger.error("failed to move file.") + self.logger.error("failed to move file. %s", e) finally: os.umask(omask) diff --git a/python_apps/media-monitor/media-monitor.cfg b/python_apps/media-monitor/media-monitor.cfg index 79354e67f..f9c86d616 100644 --- a/python_apps/media-monitor/media-monitor.cfg +++ b/python_apps/media-monitor/media-monitor.cfg @@ -32,7 +32,7 @@ update_media_url = 'reload-metadata/format/json/api_key/%%api_key%%/mode/%%mode% list_all_db_files = 'list-all-files/format/json/api_key/%%api_key%%' # URL to tell Airtime we want a listing of all dirs its watching (including the stor dir) -list_all_watched_dirs = 'list-all-watched-dirs/format/json/api_key/%%api_key%%' +list_all_watched_dirs = 'list-all-watched-dirs/format/json/api_key/%%api_key%%/dir_id/%%dir_id%%' ############################################ # RabbitMQ settings #