-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboarmount
executable file
·146 lines (126 loc) · 4.91 KB
/
boarmount
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2010 Mats Ekberg
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os, stat, errno, sys
import fuse
from fuse import Fuse
from blobrepo import repository
from front import Front
from common import *
if not hasattr(fuse, '__version__'):
raise RuntimeError, \
"your fuse-py doesn't know of fuse.__version__, probably it's too old."
fuse.fuse_python_api = (0, 2)
class MyStat(fuse.Stat):
def __init__(self):
self.st_mode = 0
self.st_ino = 0
self.st_dev = 0
self.st_nlink = 0
self.st_uid = 0
self.st_gid = 0
self.st_size = 0
self.st_atime = 0
self.st_mtime = 0
self.st_ctime = 0
class BoarFS(Fuse):
def __init__(self, front, revision, *args, **kwargs):
Fuse.__init__(self, *args, **kwargs)
self.front = front
self.revision = revision
bloblist = front.get_session_bloblist(revision)
self.files = {}
for i in bloblist:
i['type'] = "file"
i['dir'] = "/" + os.path.dirname(i['filename'])
assert i['filename'] not in self.files, "Dupes in bloblist - repository corruption?"
self.files[i['filename']] = i
dirname = os.path.dirname(i['filename'])
if dirname and dirname not in self.files: # Don't add an empty top dir name
self.files[dirname] = { 'filename': dirname, 'type': 'directory', 'size': 0, 'dir': "/" + os.path.dirname(dirname) }
def getattr(self, path):
path = unicode(path, locale.getpreferredencoding())
st = MyStat()
st.st_uid = os.geteuid()
st.st_gid = os.getegid()
fn = path[1:]
if path == '/':
st.st_mode = stat.S_IFDIR | 0755
st.st_nlink = 2
elif fn in self.files.keys():
info = self.files[fn]
if info['type'] == 'file':
st.st_mode = stat.S_IFREG | 0444
st.st_nlink = 1
st.st_size = self.files[fn]['size']
st.st_mtime = self.files[fn]['mtime']
st.st_ctime = self.files[fn]['ctime']
elif info['type'] == 'directory':
st.st_mode = stat.S_IFDIR | 0755
st.st_nlink = 2
else:
return -errno.ENOENT
return st
def readdir(self, path, offset):
for r in '.', '..':
yield fuse.Direntry(r)
for i in self.files.values():
fn = i['filename']
if i['dir'] == path:
yield fuse.Direntry(os.path.basename(fn).encode(locale.getpreferredencoding()))
def open(self, path, flags):
path = unicode(path, locale.getpreferredencoding())
fn = path[1:]
if fn not in self.files:
return -errno.ENOENT
accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
if (flags & accmode) != os.O_RDONLY:
return -errno.EACCES
def read(self, path, size, offset):
path = unicode(path, locale.getpreferredencoding())
fn = path[1:]
if fn not in self.files:
return -errno.ENOENT
repo = self.front.repo
fileinfo=self.files[fn]
assert repo.has_blob(fileinfo['md5sum']), "Blob does not exist in the repository. Corrupt repo?"
blob_size = repo.get_blob_size(fileinfo['md5sum'])
read_size = min(size, blob_size - offset)
reader = repo.get_blob_reader(fileinfo['md5sum'], offset=offset, size=read_size)
buf = reader.read()
return buf
def main():
usage="""Usage: boarmount <repository> <session name> <mount point>"""
if len(sys.argv) != 4:
print usage
exit()
repopath, sessionName = map(tounicode, sys.argv[1:3])
repopath = os.path.abspath(repopath)
front = Front(repository.Repo(repopath))
revision = front.find_last_revision(sessionName)
assert revision != None, "No such session found: " + sessionName
print "Connecting to revision", revision, "on session", sessionName
server = BoarFS(front=front,
revision = revision,
version="%prog " + fuse.__version__,
usage=usage,
dash_s_do='setsingle')
server.parse(errex=1)
server.main()
if __name__ == '__main__':
#log_stream = StreamEncoder(open("/tmp/boarmount.log", "w"))
#sys.stdout = log_stream
#sys.stderr = log_stream
main()