This file is indexed.

/usr/share/pyshared/DiskManager/Fstab/EventHandler.py is in disk-manager 1.1.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# -*- coding: UTF-8 -*-
#
#  EventHandler.py : Execute actions on events detection
#  Copyright (C) 2007 Mertens Florent <flomertens@gmail.com>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

import os
import time
import logging
import threading

from Fstabconfig import *
from Fstab import *
from FstabError import *

class EventHandler :

    def __init__(self, disk, enable_watch) :

        self.disk = disk
        self.enable_watch = enable_watch
        self.filename = self.disk.filename
        self.inhibit =  False
        self.start_watch()
        
    def start_watch(self) :

        if not self.enable_watch :
            return
        logging.debug("Starting Watch...")
        self.th_watch = threading.Thread(target=self.start_watch_thread, name="WatchThread")
        self.th_watch.setDaemon(True)
        self.th_watch.start()
                
    def start_watch_thread(self) :
    
        self.alive = True
        self.mtime_mtab = os.stat(MTAB).st_mtime
        self.mtime_fstab = os.stat(self.filename).st_mtime
        self.size = [ str(k.get_free_size())[:4] for k in self.disk ]
        while self.alive :
            time.sleep(0.5)
            if not self.inhibit and not self.mtime_fstab == os.stat(self.filename).st_mtime :
                logging.debug("FSTAB update detected")
                self.emit("external_fstab_changed")
            if not self.inhibit and not self.mtime_mtab == os.stat(MTAB).st_mtime :
                logging.debug("MTAB update detected")
                self.emit("external_mtab_changed")  
            if not self.inhibit and not self.size == [ str(k.get_free_size())[:4] for k in self.disk ] :
                logging.debug("Size update detected")
                self.emit("size_changed")
                
    def stop_watch(self) :

        if hasattr(self, "th_watch") and self.th_watch.isAlive() :
            self.alive = False
            logging.debug("Stopping Watch...")
            self.th_watch.join()

    def shutdown(self) :
        
        t = time.time()
        self.stop_watch()
        logging.debug("EventHandler shutdown in %s s", time.time() -t)
        
    def emit(self, event) :
    
        if not hasattr(self, "on_%s" % event) :
            raise UnknowEvent(self, event)
        t = time.time()
        logging.debug("Emitting '%s' event" % event)
        if getattr(self, "on_%s" % event)() :
            if hasattr(self, "%s_fct" % event) :
                fct = getattr(self, "%s_fct" % event)
                if callable(fct[0]) :
                    logging.debug("-> Call %s%s for event '%s'" % (fct[0].__name__, fct[1], event))
                    fct[0](*fct[1])
            else :
                logging.debug("-> No function define for event '%s'" % event)
        logging.debug("Event '%s' managed in %s s", event, time.time() -t)

    def on_external_fstab_changed(self) :
    
        fstab = MntFile(self.filename)
        if self.disk.fstab[:] == fstab[:] :
            self.mtime_fstab = os.stat(self.filename).st_mtime
            logging.debug("In fact, no real changes.")
            return False
        self.disk._rebuild_object(fstab)
        self.disk._current = self.disk.copy()
        self.disk._current.fstab = self.disk.fstab.copy()
        self.emit("external_changed")
        self.mtime_fstab = os.stat(self.filename).st_mtime
        
    def on_external_mtab_changed(self) :
    
        mtab = MntFile(MTAB, minimal = True)
        self.disk._build_object(self.disk.fstab)
        self.disk._current = self.disk.copy()
        self.disk._current.fstab = self.disk.fstab.copy()
        self.emit("external_changed")
        self.mtime_mtab = os.stat(MTAB).st_mtime
        self.size = [ str(k.get_free_size())[:4] for k in self.disk ]
        
    def on_internal_changed_prepare(self) :

        logging.debug("Inhibit watch for internal change...")
        self.inhibit = True
        
    def on_internal_changed_cancel(self) :

        logging.debug("Restart watch...")
        self.inhibit = False
        
    def on_internal_changed(self) :
    
        self.emit("configuration_changed")
        self.mtime_mtab = os.stat(MTAB).st_mtime
        self.mtime_fstab = os.stat(self.filename).st_mtime
        self.size = [ str(k.get_free_size())[:4] for k in self.disk ]
        logging.debug("Restart watch...")
        self.inhibit = False
        
    def on_external_changed(self) :
    
        self.emit("configuration_changed")
        
    def on_configuration_changed(self) :
    
        self.emit("any_changed")
    
    def on_size_changed(self) :
        
        self.emit("any_changed")
        self.size = [ str(k.get_free_size())[:4] for k in self.disk ]
            
    def on_any_changed(self) :
    
        return True