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

        if not check_deny_file(filename):
            if not os.path.exists(filename):
                return
            node = content.get_file_info(filename)
            if not node:
                return

            # Modify existing record
            ret = content.exist(node['uid'], node['size'], node['date'])
            if ret == 'MODIFIED':
                clog.debug('[WRITE] MODIFIED: %s' % filename)
                content.modify_file(filename)
                self.update_event_dir_list(filename)
                self.up_to_date = False
            # Insert New Record
            elif ret == 'NEW_FILE':
                clog.debug('[WRITE] CREATED: %s' % filename)
                content.add_file(filename, True, node)
                self.update_event_dir_list(filename)
                self.up_to_date = False
            # Already in the DB.(For Samba event)
            elif ret == 'SAME_FILE':
                pass
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 = ''