summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Woods <wwoods@redhat.com>2009-02-03 14:32:43 -0500
committerWill Woods <wwoods@redhat.com>2009-02-03 14:32:43 -0500
commitc886a23f260cde6c9f43f5209a8aa1e4ca594717 (patch)
treeffaaceb5560f02dd19e9e42630c9ef1380c22449
parent3880f99261bf66a25c7422af13a920f987fd7723 (diff)
downloaddebuginfofs-c886a23f260cde6c9f43f5209a8aa1e4ca594717.tar.gz
debuginfofs-c886a23f260cde6c9f43f5209a8aa1e4ca594717.tar.xz
debuginfofs-c886a23f260cde6c9f43f5209a8aa1e4ca594717.zip
move and update repofs
-rwxr-xr-xrepofs.py (renamed from proof-of-concept/repofs.py)50
1 files changed, 43 insertions, 7 deletions
diff --git a/proof-of-concept/repofs.py b/repofs.py
index d3ad279..1656ab2 100755
--- a/proof-of-concept/repofs.py
+++ b/repofs.py
@@ -1,4 +1,9 @@
#!/usr/bin/python
+# repofs.py - Export the contents of a package repo as a readonly filesystem.
+#
+# Copyright 2009 Red Hat, Inc. GPLv2+ BOILERPLATE GOES HERE.
+#
+# Author: Will Woods <wwoods@redhat.com>
import os
import glob
@@ -103,7 +108,7 @@ class SimpleYumRepo(object):
inf = open(rpm)
# Find RPM header and read compression algorithm
# Skip forward to gzipped CPIO archive
- # FIXME: Awful. Just awful.
+ # FIXME: Awful. Just awful. At least use rpm2cpio.
header = inf.read(409600)
offset = header.index("\x1f\x8b")
del header
@@ -121,25 +126,55 @@ class SimpleYumRepo(object):
cpio.stdin.close()
cpio.wait()
-class Repofs(Fuse):
+class FuseRO(Fuse):
+ '''A Fuse subclass for implementing readonly filesystems.'''
+ # chmod chown create link mkdir mknod rename rmdir setxattr(?) symlink
+ # truncate unlink write
+ def __rofs(self, *args):
+ '''Raises OSError(EROFS,"Read-only filesystem")'''
+ raise OSError(errno.EROFS, "Read-only filesystem")
+ chmod = __rofs
+ chown = __rofs
+ link = __rofs
+ mkdir = __rofs
+ rename = __rofs
+ rmdir = __rofs
+ setxattr = __rofs # You might override this so you can store xattrs
+ symlink = __rofs
+ truncate = __rofs
+ unlink = __rofs
+ def write(self, *args):
+ '''write() function that raises IOError(EBADF)
+ You can't open files for writing; this is a readonly filesystem!'''
+ raise IOError(errno.EBADF, "write() on readonly filesystem")
+ def _check_open(self, flags):
+ '''checks the open() flags, and returns False if write access
+ was requested. Returns True otherwise.'''
+ accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
+ return (flags & accmode) == os.O_RDONLY
+
+class Repofs(FuseRO):
def __init__(self, *args, **kw):
Fuse.__init__(self, *args, **kw)
+ # FIXME: this logging is terrible
+ def log(self,message):
+ self.logfile.write("%s %s\n" % (time.asctime(), message))
+
def fsinit(self):
if not os.path.isdir(self.cachedir):
os.makedirs(self.cachedir)
+ # FIXME this logging is awful
self.logfile = open(os.path.join(self.cachedir,".log"),"a",0)
self.log("fsinit(path=%s). Hang on.." % self.repopath)
- # TODO: figure out the repo type (Yum, etc) and use the right class
+ # TODO: figure out the repo type (Yum, etc) and use the right class.
+ # That way we can support other distros. Yay!
self.repos = []
for rp in self.repopath.split(":"):
r = SimpleYumRepo(path=rp, cachedir=self.cachedir)
self.repos.append(r)
self.log(" cachedir=%s, repopath=%s" % (r.cachedir, r.path))
- def log(self,message):
- self.logfile.write("%s %s\n" % (time.asctime(), message))
-
def _package_for_file(self, path):
for repo in self.repos:
packages = repo.packages_for_file(path)
@@ -198,6 +233,8 @@ class Repofs(Fuse):
return local_s
# XXX explicitly declare other functions that return proper error codes?
+
+ # FIXME: use file objects instead?
def open(self, path, flags):
self.log("open(%s,%s)" % (path,flags))
@@ -219,7 +256,6 @@ class Repofs(Fuse):
def main(self, *a, **kw):
return Fuse.main(self, *a, **kw)
- # FIXME need some kind of destroy() that removes the per-instance cache
def main():
usage = 'Repofs: mount a package repo and export all the files in the packages.\n\n' + Fuse.fusage