Example #1
0
    def process_IN_MOVED_FROM(self, event):
        self.check_delete_file(event)
        filename = event.pathname

        clog.debug('UID existence check..')
        if not content.uid(filename):
            return

        if self._moved_from_cookie_prev == 0:
            self._moved_from_cookie_prev = event.cookie
            self._moved_from_file = event.pathname

        clog.debug('[MV_FROM] filename: %s' % event.pathname)
        self.update_event_dir_list(filename)
        self.up_to_date = False
Example #2
0
    def process_IN_MOVED_TO(self, event):
        dst_path = event.pathname
        node = content.get_file_info(dst_path)

        # New Contents came in.
        if event.src_exist == False:
            if not check_deny_file(dst_path):
                clog.debug('[MOVED_TO] Created: %s' % dst_path)
                content.add_file(dst_path, True, node)
                self.update_event_dir_list(dst_path)
                self.up_to_date = False
        else:
            clog.debug('UID existence check..')
            uid = content.uid(event.src_pathname)
            # New contents came in.(This should be a dir creation on Samba.)
            if not uid:
                log.debug('UID doesn\'t exists in DB. Adding file...')
                if not check_deny_file(dst_path):
                    clog.debug('[MOVED_TO] Created: %s' % dst_path)
                    content.add_file(dst_path, True, node)
                    self.update_event_dir_list(dst_path)
                    self.up_to_date = False
            # Moved inside the content directory
            else:
                clog.debug('========= Before updating watches=========')
                for w in event.wm.watches.values():
                    clog.debug('wd: %d, path: %s' % (w.wd, w.path))
                clog.debug('==========================================')

                # Update Watch
                if (event.mask & pyinotify.IN_ISDIR) :
                    src_path = event.src_pathname

                    for w in event.wm.watches.values():
                        if w.path == src_path:
                            w.path = dst_path

                    clog.debug('========== After updating watches =============')
                    for w in event.wm.watches.values():
                        clog.debug('wd: %d, path: %s' % (w.wd, w.path))
                    clog.debug('===============================================')

                    src_path_len = len(src_path)
                    sep_len = len(os.path.sep)

                    for w in event.wm.watches.values():
                        if w.path.startswith(src_path):
                            # Note that dest_path is a normalized path.
                            w.path = os.path.join(dst_path, w.path[src_path_len + sep_len:])
                            #log.debug('[MOVED_TO] updated watch path: %s' % w.path)

                    clog.debug('======== After updating watch dependencies ==========')
                    for w in event.wm.watches.values():
                        clog.debug('wd: %d, path: %s' % (w.wd, w.path))
                    clog.debug('=====================================================')

                clog.debug('[MOVED_TO] Moved: %s' % dst_path)
                content.move_file(event.src_pathname, dst_path)
                self.update_event_dir_list(dst_path)
                self.up_to_date = False

                self._moved_from_cookie_prev = 0
                self._moved_from_file = ''