Example #1
0
    def __init__(self, home_source, home_dest):
        Fuse.__init__(self, dash_s_do="setsingle")
        self.home_source = home_source
        self.home_dest = os.path.normpath(home_dest)

        if os.path.exists(self.home_source) == False:
            raise OSError("No such file or directory %s" % self.home_source)

        if os.path.exists(self.home_dest) == False:
            raise OSError("No such file or directory %s" % self.home_dest)

        self.demand_mounter = DemandMounter()
Example #2
0
class FcombineFS(Fuse):

    ################################
    ########### BIG FAT TODO:
    ################################
    # Do we need to update the activity counter for file reads/writes?
    # Perhaps we should just check to see if there's any open
    # files on the filesystem when the unmount is ready to occur?
    ###############################

    def __init__(self, home_source, home_dest):
        Fuse.__init__(self, dash_s_do="setsingle")
        self.home_source = home_source
        self.home_dest = os.path.normpath(home_dest)

        if os.path.exists(self.home_source) == False:
            raise OSError("No such file or directory %s" % self.home_source)

        if os.path.exists(self.home_dest) == False:
            raise OSError("No such file or directory %s" % self.home_dest)

        self.demand_mounter = DemandMounter()


    def update_activity(self, path):
        pass

    def getattr(self, path):
        log(7, "getattr")
        self.update_activity(path)
        return os.lstat("." + path)

    def readlink(self, path):
        log(7, "readlink")
        self.update_activity(path)
        return os.readlink("." + path)

    def readdir(self, path, offset):
        log(7, "readdir")
        self.demand_mounter.check_path(path)

        for e in os.listdir("." + path):
            yield fuse.Direntry(e)

    def unlink(self, path):
        log(7, "unlink")
        self.update_activity(path)
        os.unlink("." + path)

    def rmdir(self, path):
        log(7, "rmdir")
        self.update_activity(path)
        os.rmdir("." + path)

    def symlink(self, path, path1):
        log(7, "symlink")
        self.update_activity(path)
        os.symlink(path, "." + path1)

    def rename(self, path, path1):
        log(7, "rename")
        self.update_activity(path)
        os.rename("." + path, "." + path1)

    def link(self, path, path1):
        log(7, "link")
        self.update_activity(path)
        os.link("." + path, "." + path1)

    def chmod(self, path, mode):
        log(7, "chmod")
        self.update_activity(path)
        os.chmod("." + path, mode)

    def chown(self, path, user, group):
        log(7, "chown")
        self.update_activity(path)
        os.chown("." + path, user, group)

    def truncate(self, path, len):
        log(7, "truncate")
        self.update_activity(path)
        f = open("." + path, "a")
        f.truncate(len)
        f.close()

    def mknod(self, path, mode, dev):
        log(7, "mknod")
        self.update_activity(path)
        os.mknod("." + path, mode, dev)

    def mkdir(self, path, mode):
        log(7, "mkdir")
        self.update_activity(path)
        os.mkdir("." + path, mode)

    def utime(self, path, times):
        log(7, "utime")
        self.update_activity(path)
        os.utime("." + path, times)

    def access(self, path, mode):
        log(7, "access")
        if not os.access("." + path, mode):
            return -EACCES

    def statfs(self):
        log(7, "statfs")
        """
        Should return an object with statvfs attributes (f_bsize, f_frsize...).
        Eg., the return value of os.statvfs() is such a thing (since py 2.2).
        If you are not reusing an existing statvfs object, start with
        fuse.StatVFS(), and define the attributes.

        To provide usable information (ie., you want sensible df(1)
        output, you are suggested to specify the following attributes:

            - f_bsize - preferred size of file blocks, in bytes
            - f_frsize - fundamental size of file blcoks, in bytes
                [if you have no idea, use the same as blocksize]
            - f_blocks - total number of blocks in the filesystem
            - f_bfree - number of free blocks
            - f_files - total number of file inodes
            - f_ffree - nunber of free file inodes
        """

        return os.statvfs(".")

    def fsinit(self):
        log(7, "fsinit")
        os.chdir(self.home_source)

    def fsdestroy(self):
        log(7, "fsdestroy")
        self.demand_mounter.fsdestroy()

    def main(self):
        self.file_class = FcombineFSFile
        return Fuse.main(self, args=[sys.argv[0], '-ononempty', self.home_dest])