From d1542b0d896ad1235d0cea103658097a1cebdd1e Mon Sep 17 00:00:00 2001 From: James Date: Wed, 28 Sep 2011 13:45:21 -0400 Subject: [PATCH] CC-2882: Airtime cannot delete watched folder when is been renamed - done --- .../application/controllers/ApiController.php | 1 + airtime_mvc/application/models/MusicDir.php | 4 -- .../airtimefilemonitor/airtimeprocessevent.py | 53 +++++++++---------- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 6576a9051..878b1f909 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -542,6 +542,7 @@ class ApiController extends Zend_Controller_Action foreach($files as $file){ $file->delete(); } + return; } $this->view->id = $file->getId(); } diff --git a/airtime_mvc/application/models/MusicDir.php b/airtime_mvc/application/models/MusicDir.php index e3d537ee9..028923a3e 100644 --- a/airtime_mvc/application/models/MusicDir.php +++ b/airtime_mvc/application/models/MusicDir.php @@ -284,10 +284,6 @@ class Application_Model_MusicDir { $real_path = realpath($p_dir)."/"; if($real_path != "/"){ $p_dir = $real_path; - }else{ - // this is the case where user removes watched directory on - // the file system directly. - $p_dir .= "/"; } $dir = Application_Model_MusicDir::getDirByPath($p_dir); if($dir == NULL){ diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index 6d891ad80..c8670bb64 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -42,44 +42,41 @@ class AirtimeProcessEvent(ProcessEvent): def process_IN_MOVE_SELF(self, event): self.logger.info("event: %s", event) + path = event.path if event.dir: - path = event.path - wd = self.wm.get_wd(path) - self.logger.info("Removing watch on: %s wd %s", path, wd) - self.wm.rm_watch(wd, rec=True) if "-unknown-path" in path: + unkown_path = path pos = path.find("-unknown-path") - path = path[0:pos] + path = path[0:pos]+"/" - list = self.api_client.list_all_watched_dirs() - # case where the dir that is being watched is moved to somewhere - if path in list: - self.logger.info("Requesting the airtime server to remove '%s'", path) - res = self.api_client.remove_watched_dir(path) - if(res is None): - self.logger.info("Unable to connect to the Airtime server.") - # sucess - if(res['msg']['code'] == 0): - self.logger.info("%s removed from watch folder list successfully.", path) + list = self.api_client.list_all_watched_dirs() + # case where the dir that is being watched is moved to somewhere + if path in list[u'dirs'].values(): + self.logger.info("Requesting the airtime server to remove '%s'", path) + res = self.api_client.remove_watched_dir(path) + if(res is None): + self.logger.info("Unable to connect to the Airtime server.") + # sucess + if(res['msg']['code'] == 0): + self.logger.info("%s removed from watch folder list successfully.", path) + else: + self.logger.info("Removing the watch folder failed: %s", res['msg']['error']) else: - self.logger.info("Removing the watch folder failed: %s", res['msg']['error']) - else: - self.file_events.append({'mode': self.config.MODE_DELETE_DIR, 'filepath': path}) + # subdir being moved + # in this case, it has to remove watch manualy and also have to manually delete all records + # on cc_files table + wd = self.wm.get_wd(unkown_path) + self.logger.info("Removing watch on: %s wd %s", unkown_path, wd) + self.wm.rm_watch(wd, rec=True) + self.file_events.append({'mode': self.config.MODE_DELETE_DIR, 'filepath': path}) def process_IN_DELETE_SELF(self, event): self.logger.info("event: %s", event) + path = event.path + '/' if event.dir: - path = event.path - wd = self.wm.get_wd(path) - self.logger.info("Removing watch on: %s wd %s", path, wd) - self.wm.rm_watch(wd, rec=True) - if "-unknown-path" in path: - pos = path.find("-unknown-path") - path = path[0:pos] - list = self.api_client.list_all_watched_dirs() - if path in list: + if path in list[u'dirs'].values(): self.logger.info("Requesting the airtime server to remove '%s'", path) res = self.api_client.remove_watched_dir(path) if(res is None): @@ -89,8 +86,6 @@ class AirtimeProcessEvent(ProcessEvent): self.logger.info("%s removed from watch folder list successfully.", path) else: self.logger.info("Removing the watch folder failed: %s", res['msg']['error']) - else: - self.file_events.append({'mode': self.config.MODE_DELETE_DIR, 'filepath': path}) #event.dir: True if the event was raised against a directory. #event.name: filename