Switch to unified view

a/fuse/accessfs.py b/fuse/accessfs.py
...
...
48
class check_and_translate(check_access):
48
class check_and_translate(check_access):
49
49
50
    def check(self, inst, path, mode):
50
    def check(self, inst, path, mode):
51
        super(check_and_translate, self).check(inst, path, mode)
51
        super(check_and_translate, self).check(inst, path, mode)
52
        return inst._to_global(path)
52
        return inst._to_global(path)
53
54
class LoopbackFS(fuse.Fuse):
55
    '''Loopback filesystem with hooks for permission management'''
56
57
    def __init__(self, root, *args, **kwargs):
58
        super(LoopbackFS, self).__init__(*args, **kwargs)
59
        self._root = root
60
61
    @check_and_translate(os.R_OK)
62
    def getattr(self, path): return os.lstat(path)
63
64
    @check_and_translate(os.R_OK)
65
    def readlink(self, path): return os.readlink(path)
66
67
    @check_and_translate(os.W_OK)
68
    def mknod(self, path, mode, dev): os.mknod(path, mode, dev)
69
70
    @check_and_translate(os.W_OK)
71
    def mkdir(self, path, mode): os.mkdir(path, mode)
72
73
    @check_and_translate(os.W_OK)
74
    def unlink(self, path): os.unlink(path)
75
76
    @check_and_translate(None, os.W_OK)
77
    def symlink(self, target, name): os.symlink(target, name)
78
79
    @check_and_translate(os.R_OK|os.W_OK, os.R_OK|os.W_OK)
80
    def rename(self, old, new): os.rename(old, new)
81
82
    @check_and_translate(os.R_OK, os.W_OK)
83
    def link(self, src, dst): os.link(src, dst)
84
85
    @check_and_translate(None)
86
    def access(self, path, mode): return os.access(path, mode)
87
88
    def fsinit(self): pass
89
90
    def _to_global(self, path):
91
        return os.path.join(self._root, path)
92
93
    # @check_access(os.R_OK)
94
    # def readdir(self, path, offset):
95
    #     for e in os.listdir(self._to_global(path)):
96
    #         yield fuse.Direntry(e)
97
98
    # def rmdir(self, path):
99
    #     self._assert_access(path, os.W_OK)
100
    #     os.rmdir(self._to_global(path))
101
102
    # def chmod(self, path, mode):
103
    #     self._assert_access(path, os.W_OK)
104
    #     os.chmod(self._to_global(path), mode)
105
106
    # def chown(self, path, user, group):
107
    #     self._assert_access(path, os.W_OK)
108
    #     os.chown(self._to_global(path), user, group)
109
110
    # def truncate(self, path, len):
111
    #     self._assert_access(path, os.W_OK)
112
    #     f = open(self._to_global(path), "a")
113
    #     f.truncate(len)
114
    #     f.close()
115
116
    # def utime(self, path, times):
117
    #     os.utime(self._to_global(path), times)
118
119
    # def statfs(self):
120
    #     """
121
    #     Should return an object with statvfs attributes (f_bsize, f_frsize...).
122
    #     Eg., the return value of os.statvfs() is such a thing (since py 2.2).
123
    #     If you are not reusing an existing statvfs object, start with
124
    #     fuse.StatVFS(), and define the attributes.
125
126
    #     To provide usable information (ie., you want sensible df(1)
127
    #     output, you are suggested to specify the following attributes:
128
129
    #         - f_bsize - preferred size of file blocks, in bytes
130
    #         - f_frsize - fundamental size of file blcoks, in bytes
131
    #             [if you have no idea, use the same as blocksize]
132
    #         - f_blocks - total number of blocks in the filesystem
133
    #         - f_bfree - number of free blocks
134
    #         - f_files - total number of file inodes
135
    #         - f_ffree - nunber of free file inodes
136
    #     """
137
138
    #     return os.statvfs(".")
139
140
    # def make_file_class(self):
141
    #     class FSAccessFile(AccessFile):
142
    #         filesystem=self
143
    #     return FSAccessFile
144
145
class OverlayFS(fuse.Fuse):
146
    '''Filesystem that overlays a read-only GridFS on an existing filesystem'''
147
148
    def __init__(self, root, gfs, *args, **kwargs):
149
        super(OverlayFS, self).__init__(*args, **kwargs)
150
        self._root = root
151
        self._gfs = gfs
152
153
53
154
def flag2mode(flags):
54
def flag2mode(flags):
155
    md = {os.O_RDONLY: 'r', os.O_WRONLY: 'w', os.O_RDWR: 'w+'}
55
    md = {os.O_RDONLY: 'r', os.O_WRONLY: 'w', os.O_RDWR: 'w+'}
156
    m = md[flags & (os.O_RDONLY | os.O_WRONLY | os.O_RDWR)]
56
    m = md[flags & (os.O_RDONLY | os.O_WRONLY | os.O_RDWR)]
157
    if flags | os.O_APPEND:
57
    if flags | os.O_APPEND: